27.02.2013 Views

Rails%203%20In%20Action

Rails%203%20In%20Action

Rails%203%20In%20Action

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

198 CHAPTER 8 More authorization<br />

<br />

:delete,<br />

:confirm => "Are you sure you want to delete this ticket?" %><br />

<br />

When you run bin/cucumber features/hidden_links.feature, all 15 scenarios pass:<br />

16 scenarios (16 passed)<br />

124 steps (124 passed)<br />

Fantastic! Now you’ve stopped displaying links to the users who shouldn’t see them<br />

and switched to displaying them only to people who should be able to see them.<br />

What a whirlwind adventure! First you learned to check for permissions for all the<br />

actions in the TicketsController, and then you learned to hide links from users in<br />

the views. Let’s make sure everything is working by running rake cucumber:ok spec:<br />

40 scenarios (40 passed)<br />

376 steps (376 passed)<br />

# and<br />

17 examples, 0 failures, 3 pending<br />

Great! Now let’s commit:<br />

git add .<br />

git commit -m "Restrict actions in TicketsController<br />

➥based on permissions and hide links"<br />

git push<br />

With all that done, you now have the scaffold for setting up permissions but no interface<br />

to it! There’s currently no way in the system for a user (in particular, an admin) to<br />

set up the permissions on other users. We now implement that.<br />

8.8 Assigning permissions<br />

In chapter 6, you added an admin field to the users table and then triggered it<br />

through the admin backend by checking or unchecking a check box. You’re going to<br />

do the same thing with the permissions for the projects. When you’re done, you’ll see<br />

a permissions screen that allows you to pick and choose the permissions for the users<br />

and projects.<br />

You implement this screen one check box at a time because you must confirm that<br />

the permissions you assign through this interface work just as well as when you use the<br />

step definitions in Cucumber. Let’s get started with the permission to view projects.<br />

8.8.1 Viewing projects<br />

In this section, you implement the foundations for assigning the permissions through<br />

the admin backend, starting with the permission to view projects. Create a new feature<br />

called features/assigning_permissions.feature, and start it out with the code from the<br />

following listing.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!