Commit d1f72816e963a4810014dbdd0ce8d4037245c3b9

Authored by Rodrigo Souto
1 parent 6b78cf93

invite-controller: simplify permission check

app/controllers/public/invite_controller.rb
@@ -85,10 +85,6 @@ class InviteController < PublicController @@ -85,10 +85,6 @@ class InviteController < PublicController
85 protected 85 protected
86 86
87 def check_permissions_to_invite 87 def check_permissions_to_invite
88 - if profile.person? and !user.has_permission?(:manage_friends, profile) or  
89 - profile.community? and !user.has_permission?(:invite_members, profile)  
90 - render_access_denied  
91 - end 88 + render_access_denied if !profile.allow_invitation_from?(user)
92 end 89 end
93 -  
94 end 90 end
app/models/organization.rb
@@ -177,4 +177,8 @@ class Organization < Profile @@ -177,4 +177,8 @@ class Organization < Profile
177 self.visible = false 177 self.visible = false
178 save! 178 save!
179 end 179 end
  180 +
  181 + def allow_invitation_from?(person)
  182 + (followed_by?(person) && self.allow_members_to_invite) || person.has_permission?('invite-members', self)
  183 + end
180 end 184 end
app/models/person.rb
@@ -514,6 +514,10 @@ class Person < Profile @@ -514,6 +514,10 @@ class Person < Profile
514 suggestion.disable if suggestion 514 suggestion.disable if suggestion
515 end 515 end
516 516
  517 + def allow_invitation_from?(person)
  518 + person.has_permission?(:manage_friends, self)
  519 + end
  520 +
517 protected 521 protected
518 522
519 def followed_by?(profile) 523 def followed_by?(profile)
app/models/profile.rb
@@ -992,4 +992,8 @@ private :generate_url, :url_options @@ -992,4 +992,8 @@ private :generate_url, :url_options
992 suggestion.disable if suggestion 992 suggestion.disable if suggestion
993 end 993 end
994 994
  995 + def allow_invitation_from(person)
  996 + false
  997 + end
  998 +
995 end 999 end