Commit b3cf98f7d72d304ef3114a87a0a260b5f8a1f25d
1 parent
d6f15e02
Exists in
staging
and in
42 other branches
ActionItem378: define permissions to tasks
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1884 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
10 changed files
with
43 additions
and
1 deletions
Show diff stats
app/controllers/my_profile/profile_editor_controller.rb
| ... | ... | @@ -3,7 +3,7 @@ class ProfileEditorController < MyProfileController |
| 3 | 3 | protect 'edit_profile', :profile, :only => [:index, :edit] |
| 4 | 4 | |
| 5 | 5 | def index |
| 6 | - @pending_tasks = profile.tasks.pending | |
| 6 | + @pending_tasks = profile.tasks.pending.select{|i| user.has_permission?(i.permission, profile)} | |
| 7 | 7 | end |
| 8 | 8 | |
| 9 | 9 | helper :profile | ... | ... |
app/models/add_friend.rb
app/models/add_member.rb
app/models/create_enterprise.rb
app/models/task.rb
| ... | ... | @@ -116,6 +116,11 @@ class Task < ActiveRecord::Base |
| 116 | 116 | nil |
| 117 | 117 | end |
| 118 | 118 | |
| 119 | + # What permission is required to perform task? | |
| 120 | + def permission | |
| 121 | + :perform_task | |
| 122 | + end | |
| 123 | + | |
| 119 | 124 | protected |
| 120 | 125 | |
| 121 | 126 | # This method must be overrided in subclasses, and its implementation must do | ... | ... |
test/unit/add_friend_test.rb
| ... | ... | @@ -82,4 +82,9 @@ class AddFriendTest < ActiveSupport::TestCase |
| 82 | 82 | assert_equal 'testuser1 wants to be your friend', task.description |
| 83 | 83 | end |
| 84 | 84 | |
| 85 | + should 'has permission to manage friends' do | |
| 86 | + t = AddFriend.new | |
| 87 | + assert_equal :manage_friends, t.permission | |
| 88 | + end | |
| 89 | + | |
| 85 | 90 | end | ... | ... |
test/unit/add_member_test.rb
test/unit/change_password_test.rb
test/unit/create_enterprise_test.rb
| ... | ... | @@ -186,4 +186,9 @@ class CreateEnterpriseTest < Test::Unit::TestCase |
| 186 | 186 | assert request.errors.invalid?(:identifier) |
| 187 | 187 | end |
| 188 | 188 | |
| 189 | + should 'has permission to validate enterprise' do | |
| 190 | + t = CreateEnterprise.new | |
| 191 | + assert_equal :validate_enterprise, t.permission | |
| 192 | + end | |
| 193 | + | |
| 189 | 194 | end | ... | ... |
test/unit/task_test.rb
| ... | ... | @@ -169,6 +169,11 @@ class TaskTest < Test::Unit::TestCase |
| 169 | 169 | assert_equal [t2], Task.finished |
| 170 | 170 | end |
| 171 | 171 | |
| 172 | + should 'has perform task permission' do | |
| 173 | + t = Task.new | |
| 174 | + assert_equal :perform_task, t.permission | |
| 175 | + end | |
| 176 | + | |
| 172 | 177 | protected |
| 173 | 178 | |
| 174 | 179 | def sample_user | ... | ... |