2014-02-14 00:42:35 +08:00
|
|
|
# mixin for all Guardian methods dealing with user permissions
|
|
|
|
module UserGuardian
|
|
|
|
|
|
|
|
def can_edit_user?(user)
|
|
|
|
is_me?(user) || is_staff?
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_edit_username?(user)
|
2014-03-08 14:16:49 +08:00
|
|
|
return false if (SiteSetting.sso_overrides_username? && SiteSetting.enable_sso?)
|
2014-02-14 00:42:35 +08:00
|
|
|
return true if is_staff?
|
|
|
|
return false if SiteSetting.username_change_period <= 0
|
|
|
|
is_me?(user) && (user.post_count == 0 || user.created_at > SiteSetting.username_change_period.days.ago)
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_edit_email?(user)
|
2014-03-08 14:16:49 +08:00
|
|
|
return false if (SiteSetting.sso_overrides_email? && SiteSetting.enable_sso?)
|
2014-02-14 00:42:35 +08:00
|
|
|
return false unless SiteSetting.email_editable?
|
2014-08-15 10:41:01 +08:00
|
|
|
return true if is_staff?
|
2014-02-14 00:42:35 +08:00
|
|
|
can_edit?(user)
|
|
|
|
end
|
|
|
|
|
2014-03-14 04:26:40 +08:00
|
|
|
def can_edit_name?(user)
|
|
|
|
return false if not(SiteSetting.enable_names?)
|
|
|
|
return false if (SiteSetting.sso_overrides_name? && SiteSetting.enable_sso?)
|
|
|
|
return true if is_staff?
|
|
|
|
can_edit?(user)
|
|
|
|
end
|
|
|
|
|
2014-09-03 09:32:27 +08:00
|
|
|
def can_see_notifications?(user)
|
|
|
|
is_me?(user) || is_admin?
|
|
|
|
end
|
|
|
|
|
2014-02-14 00:42:35 +08:00
|
|
|
def can_block_user?(user)
|
|
|
|
user && is_staff? && not(user.staff?)
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_unblock_user?(user)
|
|
|
|
user && is_staff?
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_delete_user?(user)
|
2014-07-29 01:17:37 +08:00
|
|
|
return false if user.nil? || user.admin?
|
2014-02-14 00:42:35 +08:00
|
|
|
if is_me?(user)
|
|
|
|
user.post_count <= 1
|
|
|
|
else
|
2014-07-29 01:17:37 +08:00
|
|
|
is_staff? && (user.first_post_created_at.nil? || user.first_post_created_at > SiteSetting.delete_user_max_post_age.to_i.days.ago)
|
2014-02-14 00:42:35 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-09-30 04:31:05 +08:00
|
|
|
def can_check_emails?(user)
|
|
|
|
is_admin? || (is_staff? && SiteSetting.show_email_on_profile)
|
|
|
|
end
|
|
|
|
|
2014-03-14 04:26:40 +08:00
|
|
|
end
|