Commit b3cf98f7d72d304ef3114a87a0a260b5f8a1f25d

Authored by JoenioCosta
1 parent d6f15e02

ActionItem378: define permissions to tasks


git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1884 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/controllers/my_profile/profile_editor_controller.rb
@@ -3,7 +3,7 @@ class ProfileEditorController < MyProfileController @@ -3,7 +3,7 @@ class ProfileEditorController < MyProfileController
3 protect 'edit_profile', :profile, :only => [:index, :edit] 3 protect 'edit_profile', :profile, :only => [:index, :edit]
4 4
5 def index 5 def index
6 - @pending_tasks = profile.tasks.pending 6 + @pending_tasks = profile.tasks.pending.select{|i| user.has_permission?(i.permission, profile)}
7 end 7 end
8 8
9 helper :profile 9 helper :profile
app/models/add_friend.rb
@@ -25,4 +25,8 @@ class AddFriend < Task @@ -25,4 +25,8 @@ class AddFriend < Task
25 _('%s wants to be your friend') % requestor.name 25 _('%s wants to be your friend') % requestor.name
26 end 26 end
27 27
  28 + def permission
  29 + :manage_friends
  30 + end
  31 +
28 end 32 end
app/models/add_member.rb
@@ -25,4 +25,8 @@ class AddMember < Task @@ -25,4 +25,8 @@ class AddMember < Task
25 _('%s wants to be a member') % requestor.name 25 _('%s wants to be a member') % requestor.name
26 end 26 end
27 27
  28 + def permission
  29 + :manage_memberships
  30 + end
  31 +
28 end 32 end
app/models/create_enterprise.rb
@@ -164,4 +164,8 @@ class CreateEnterprise < Task @@ -164,4 +164,8 @@ class CreateEnterprise < Task
164 msg 164 msg
165 end 165 end
166 166
  167 + def permission
  168 + :validate_enterprise
  169 + end
  170 +
167 end 171 end
app/models/task.rb
@@ -116,6 +116,11 @@ class Task < ActiveRecord::Base @@ -116,6 +116,11 @@ class Task < ActiveRecord::Base
116 nil 116 nil
117 end 117 end
118 118
  119 + # What permission is required to perform task?
  120 + def permission
  121 + :perform_task
  122 + end
  123 +
119 protected 124 protected
120 125
121 # This method must be overrided in subclasses, and its implementation must do 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,4 +82,9 @@ class AddFriendTest < ActiveSupport::TestCase
82 assert_equal 'testuser1 wants to be your friend', task.description 82 assert_equal 'testuser1 wants to be your friend', task.description
83 end 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 end 90 end
test/unit/add_member_test.rb
@@ -66,4 +66,9 @@ class AddMemberTest < ActiveSupport::TestCase @@ -66,4 +66,9 @@ class AddMemberTest < ActiveSupport::TestCase
66 assert_same t.target, t.community 66 assert_same t.target, t.community
67 end 67 end
68 68
  69 + should 'has permission to manage members' do
  70 + t = AddMember.new
  71 + assert_equal :manage_memberships, t.permission
  72 + end
  73 +
69 end 74 end
test/unit/change_password_test.rb
@@ -105,5 +105,10 @@ class ChangePasswordTest < Test::Unit::TestCase @@ -105,5 +105,10 @@ class ChangePasswordTest < Test::Unit::TestCase
105 end 105 end
106 end 106 end
107 107
  108 + should 'has default permission' do
  109 + t1 = Task.new
  110 + t2 = ChangePassword.new
  111 + assert_equal t1.permission, t2.permission
  112 + end
108 113
109 end 114 end
test/unit/create_enterprise_test.rb
@@ -186,4 +186,9 @@ class CreateEnterpriseTest < Test::Unit::TestCase @@ -186,4 +186,9 @@ class CreateEnterpriseTest < Test::Unit::TestCase
186 assert request.errors.invalid?(:identifier) 186 assert request.errors.invalid?(:identifier)
187 end 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 end 194 end
test/unit/task_test.rb
@@ -169,6 +169,11 @@ class TaskTest < Test::Unit::TestCase @@ -169,6 +169,11 @@ class TaskTest < Test::Unit::TestCase
169 assert_equal [t2], Task.finished 169 assert_equal [t2], Task.finished
170 end 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 protected 177 protected
173 178
174 def sample_user 179 def sample_user