forked from gdpelican/retort
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
62 additions
and
65 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,2 +1,3 @@ | ||
node_modules | ||
Gemfile.lock | ||
/.vscode |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# frozen_string_literal: true | ||
|
||
# mixin for all guardian methods dealing with retort permissions | ||
module DiscourseRetort::RetortGuardian | ||
def can_create_retort? | ||
return false if SiteSetting.retort_disabled_users.split("|").include?(@user.username) | ||
return false if @user.silenced? | ||
true | ||
end | ||
|
||
def can_create_retort_on_topic?(topic) | ||
return false if topic.archived? | ||
return false if SiteSetting.retort_disabled_categories.split("|").map(&:to_i).include?(topic.category_id) | ||
true | ||
end | ||
|
||
def can_create_retort_on_post?(post) | ||
# discourse already checked `can_see?` at app/lib/guardian.rb#L192 | ||
can_create_retort? && can_create_retort_on_topic?(post.topic) | ||
end | ||
|
||
def can_recover_retort?(retort) | ||
return false if retort.nil? | ||
return false unless is_my_own?(retort) | ||
return false unless can_create_retort_on_post?(retort.post) | ||
return false if @user.id != retort.deleted_by | ||
true | ||
end | ||
|
||
def can_delete_retort?(retort) | ||
return false if retort.nil? | ||
return false unless is_my_own?(retort) | ||
return false if retort.updated_at < SiteSetting.retort_withdraw_tolerance.second.ago | ||
true | ||
end | ||
|
||
def can_moderate_retort?(retort) | ||
return false if retort.nil? | ||
return true if is_staff? | ||
false | ||
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