Move the account deletion endpoint from /maintenance/users/deletion to either: * https://danbooru.donmai.us/users/deactivate * https://danbooru.donmai.us/users/:id/deactivate This incidentally allows the Owner-level user to deactivate accounts belonging to other users. This is meant for things like deactivating inactive accounts with invalid or abusive names. This is limited to accounts below Gold level for security.
90 lines
2.0 KiB
Ruby
90 lines
2.0 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class UserPolicy < ApplicationPolicy
|
|
def create?
|
|
true
|
|
end
|
|
|
|
def new?
|
|
true
|
|
end
|
|
|
|
def update?
|
|
record.id == user.id || user.is_admin?
|
|
end
|
|
|
|
def deactivate?
|
|
(record.id == user.id && !user.is_anonymous?) || user.is_owner?
|
|
end
|
|
|
|
def destroy?
|
|
deactivate?
|
|
end
|
|
|
|
def promote?
|
|
user.is_moderator?
|
|
end
|
|
|
|
def upgrade?
|
|
!user.is_anonymous?
|
|
end
|
|
|
|
def fix_counts?
|
|
!user.is_anonymous?
|
|
end
|
|
|
|
def can_see_last_logged_in_at?
|
|
user.is_moderator?
|
|
end
|
|
|
|
def can_see_favorites?
|
|
user.is_admin? || record.id == user.id || !record.enable_private_favorites?
|
|
end
|
|
|
|
def can_enable_private_favorites?
|
|
user.is_gold?
|
|
end
|
|
|
|
def permitted_attributes_for_create
|
|
[:name, :password, :password_confirmation, { email_address_attributes: [:address] }]
|
|
end
|
|
|
|
def permitted_attributes_for_update
|
|
%i[
|
|
comment_threshold default_image_size favorite_tags
|
|
blacklisted_tags time_zone per_page custom_style theme
|
|
receive_email_notifications
|
|
new_post_navigation_layout enable_private_favorites
|
|
show_deleted_posts show_deleted_children
|
|
disable_categorized_saved_searches disable_tagged_filenames
|
|
disable_mobile_gestures enable_safe_mode
|
|
enable_desktop_mode disable_post_tooltips
|
|
].compact
|
|
end
|
|
|
|
def api_attributes
|
|
attributes = %i[
|
|
id created_at name inviter_id level level_string
|
|
post_upload_count post_update_count note_update_count is_banned
|
|
]
|
|
|
|
if record.id == user.id
|
|
attributes += User::ACTIVE_BOOLEAN_ATTRIBUTES
|
|
attributes += %i[
|
|
updated_at last_logged_in_at last_forum_read_at
|
|
comment_threshold default_image_size
|
|
favorite_tags blacklisted_tags time_zone per_page
|
|
custom_style favorite_count statement_timeout favorite_group_limit
|
|
tag_query_limit max_saved_searches theme
|
|
]
|
|
end
|
|
|
|
attributes += [:last_ip_addr] if policy(:ip_address).show?
|
|
|
|
attributes
|
|
end
|
|
|
|
alias_method :profile?, :show?
|
|
alias_method :settings?, :edit?
|
|
end
|