-
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.
DEV: Update rubocop-discourse to latest version
- Loading branch information
Showing
20 changed files
with
191 additions
and
116 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
File renamed without changes.
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,13 @@ | ||
# frozen_string_literal: true | ||
|
||
module DiscourseStaffAlias | ||
module PostExtension | ||
extend ActiveSupport::Concern | ||
|
||
prepended do | ||
has_many :users_posts_links, | ||
class_name: "DiscourseStaffAlias::UsersPostsLink", | ||
dependent: :delete_all | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
module DiscourseStaffAlias | ||
module PostRevisionExtension | ||
extend ActiveSupport::Concern | ||
|
||
prepended do | ||
has_many :users_post_revisions_links, | ||
class_name: "DiscourseStaffAlias::UsersPostRevisionsLink", | ||
dependent: :delete_all | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# frozen_string_literal: true | ||
|
||
module DiscourseStaffAlias | ||
module PostsControllerExtension | ||
extend ActiveSupport::Concern | ||
|
||
prepended do | ||
include WithCurrentUser | ||
|
||
around_action do |controller, action| | ||
if DiscourseStaffAlias::CONTROLLER_ACTIONS.include?(action_name = controller.action_name) && | ||
(params = controller.params).dig( | ||
*DiscourseStaffAlias::CONTROLLER_PARAMS[action_name], | ||
) == "true" | ||
existing_user = controller.current_user | ||
|
||
if !DiscourseStaffAlias.user_allowed?(existing_user) || params[:whisper] | ||
raise Discourse::InvalidAccess | ||
end | ||
|
||
alias_user = DiscourseStaffAlias.alias_user | ||
alias_user.aliased_user = existing_user | ||
|
||
controller.with_current_user(alias_user) { action.call } | ||
else | ||
action.call | ||
end | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# frozen_string_literal: true | ||
|
||
module DiscourseStaffAlias | ||
module TopicsControllerExtension | ||
extend ActiveSupport::Concern | ||
|
||
prepended do | ||
include WithCurrentUser | ||
|
||
around_action do |controller, action| | ||
if (action_name = controller.action_name) == "update" && | ||
(params = controller.params)["as_staff_alias"] | ||
existing_user = controller.current_user | ||
|
||
raise Discourse::InvalidAccess if !DiscourseStaffAlias.user_allowed?(existing_user) | ||
|
||
alias_user = DiscourseStaffAlias.alias_user | ||
alias_user.aliased_user = existing_user | ||
|
||
controller.with_current_user(alias_user) { action.call } | ||
else | ||
action.call | ||
end | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
module DiscourseStaffAlias | ||
module UserExtension | ||
extend ActiveSupport::Concern | ||
|
||
prepended do | ||
attr_accessor :aliased_user | ||
|
||
has_many :users_posts_links, class_name: "DiscourseStaffAlias::UsersPostsLink" | ||
has_many :users_post_revisions_links, | ||
class_name: "DiscourseStaffAlias::UsersPostRevisionsLink" | ||
end | ||
|
||
def can_post_as_staff_alias | ||
@can_post_as_staff_alias ||= | ||
begin | ||
allowed_group_ids = SiteSetting.staff_alias_allowed_groups.split("|") | ||
GroupUser.exists?(user_id: self.id, group_id: allowed_group_ids) | ||
end | ||
end | ||
end | ||
end |
File renamed without changes.
File renamed without changes.
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,16 @@ | ||
# frozen_string_literal: true | ||
|
||
module DiscourseStaffAlias | ||
module WithCurrentUser | ||
def with_current_user(user) | ||
@current_user = user | ||
yield if block_given? | ||
ensure | ||
@current_user = nil | ||
end | ||
|
||
def current_user | ||
@current_user || current_user_provider.current_user | ||
end | ||
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
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
Oops, something went wrong.