-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DEV: Scope guardian methods to the plugin and some cleanup (#138)
Scope guardian methods to the plugin Move old method to add to serializer to the proper API method
- Loading branch information
Showing
4 changed files
with
65 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,13 @@ | ||
# frozen_string_literal: true | ||
module DiscourseTranslator::GuardianExtension | ||
def user_group_allowed? | ||
authorized_groups = SiteSetting.restrict_translation_by_group.split("|").map(&:to_i) | ||
|
||
authorized? current_user, authorized_groups | ||
def user_group_allow_translate? | ||
return false if !current_user | ||
current_user.in_any_groups?(SiteSetting.restrict_translation_by_group_map) | ||
end | ||
|
||
def post_group_allowed?(post) | ||
authorized_poster_groups = | ||
SiteSetting.restrict_translation_by_poster_group.split("|").map(&:to_i) | ||
return true if authorized_poster_groups.empty? | ||
|
||
poster = User.find post.user_id | ||
authorized? poster, authorized_poster_groups | ||
end | ||
|
||
def authorized?(user, authorized_groups) | ||
return false if !user | ||
|
||
user_groups = user.groups.pluck :id | ||
authorized = authorized_groups.intersection user_groups | ||
!authorized.empty? | ||
def poster_group_allow_translate?(post) | ||
return false if !current_user | ||
return true if SiteSetting.restrict_translation_by_poster_group_map.empty? | ||
post.user.in_any_groups?(SiteSetting.restrict_translation_by_poster_group_map) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters