Commit d1f72816e963a4810014dbdd0ce8d4037245c3b9
1 parent
6b78cf93
Exists in
master
and in
27 other branches
invite-controller: simplify permission check
Showing
4 changed files
with
13 additions
and
5 deletions
Show diff stats
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