mirror of
https://github.com/discourse/discourse.git
synced 2024-11-30 19:36:22 +08:00
5a2ad7e386
We shouldn't be checking if a user is allowed to do an action in the logger. We should be checking it just before we perform the action. In fact, guardians in the logger can make things even worse in case of a security bug. Let's say we forgot to check user's permissions before performing some action, but we still have a call to the guardian in the logger. In this case, a user would perform the action anyway, and this action wouldn't even be logged! I've checked all cases and I confirm that we're safe to delete this calls from the logger. I've added two calls to guardians in admin/user_controller. We didn't have security bugs there, because regular users can't access admin/... routes at all. But it's good to have calls to guardian in these methods anyway, neighboring methods have them.
40 lines
1.0 KiB
Ruby
40 lines
1.0 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
#mixin for all guardian methods dealing with group permissions
|
|
module GroupGuardian
|
|
|
|
# Creating Method
|
|
def can_create_group?
|
|
is_admin? ||
|
|
(
|
|
SiteSetting.moderators_manage_categories_and_groups &&
|
|
is_moderator?
|
|
)
|
|
end
|
|
|
|
# Edit authority for groups means membership changes only.
|
|
# Automatic groups are not represented in the GROUP_USERS
|
|
# table and thus do not allow membership changes.
|
|
def can_edit_group?(group)
|
|
!group.automatic &&
|
|
(can_admin_group?(group) || group.users.where('group_users.owner').include?(user))
|
|
end
|
|
|
|
def can_admin_group?(group)
|
|
is_admin? ||
|
|
(
|
|
SiteSetting.moderators_manage_categories_and_groups &&
|
|
is_moderator? &&
|
|
can_see?(group) &&
|
|
group.id != Group::AUTO_GROUPS[:admins]
|
|
)
|
|
end
|
|
|
|
def can_see_group_messages?(group)
|
|
return true if is_admin?
|
|
return true if is_moderator? && group.id == Group::AUTO_GROUPS[:moderators]
|
|
|
|
SiteSetting.enable_personal_messages? && group.users.include?(user)
|
|
end
|
|
end
|