diff options
author | multiple creatures <dev@multiple-creature.party> | 2020-02-18 02:02:54 -0600 |
---|---|---|
committer | multiple creatures <dev@multiple-creature.party> | 2020-02-18 02:18:09 -0600 |
commit | 0f3b01eaab82325baaf1c7a4c75a322d3c21a67f (patch) | |
tree | f3d19c99328336997919803ffc6850a96d5a6411 /app/models | |
parent | fc69e4a0bb4e3d2fdcb2ffef0f3211f8c347ed15 (diff) |
switch to irc-like oper behavior; require mods & admins to explicitly oper up using `fangs`/`op` bangtag or toggling defang setting in profile; auto-defang after 15 mins or with `defang`/`deop` bangtag
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/account.rb | 5 | ||||
-rw-r--r-- | app/models/concerns/user_roles.rb | 45 | ||||
-rw-r--r-- | app/models/form/admin_settings.rb | 2 | ||||
-rw-r--r-- | app/models/user.rb | 3 |
4 files changed, 49 insertions, 6 deletions
diff --git a/app/models/account.rb b/app/models/account.rb index b0b9e9191..6f5a11ce0 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -132,7 +132,12 @@ class Account < ApplicationRecord :pending?, :admin?, :moderator?, + :halfmod?, :staff?, + :can_moderate?, + :defanged?, + :defanged, + :defanged=, :locale, :default_language, diff --git a/app/models/concerns/user_roles.rb b/app/models/concerns/user_roles.rb index 58dffdc46..2da039efd 100644 --- a/app/models/concerns/user_roles.rb +++ b/app/models/concerns/user_roles.rb @@ -6,6 +6,7 @@ module UserRoles included do scope :admins, -> { where(admin: true) } scope :moderators, -> { where(moderator: true) } + scope :halfmods, -> { where(halfmod: true) } scope :staff, -> { admins.or(moderators) } end @@ -13,11 +14,17 @@ module UserRoles admin? || moderator? end + def can_moderate? + staff? || halfmod? + end + def role if admin? 'admin' elsif moderator? 'moderator' + elsif halfmod? + 'halfmod' else 'user' end @@ -27,6 +34,8 @@ module UserRoles case role when 'user' true + when 'halfmod' + halfmod? when 'moderator' staff? when 'admin' @@ -36,19 +45,45 @@ module UserRoles end end + def has_more_authority_than?(other_user) + if admin? + !other_user&.admin? + elsif moderator? + !other_user&.staff? + elsif halfmod? + !other_user&.can_moderate? + else + false + end + end + def promote! - if moderator? - update!(moderator: false, admin: true) + if halfmod? + update!(halfmod: false, moderator: true, admin: false) + elsif moderator? + update!(halfmod: false, moderator: false, admin: true) elsif !admin? - update!(moderator: true) + update!(halfmod: true, moderator: false, admin: false) end end def demote! if admin? - update!(admin: false, moderator: true) + update!(halfmod: false, moderator: true, admin: false) elsif moderator? - update!(moderator: false) + update!(halfmod: true, moderator: false, admin: false) + elsif halfmod? + update!(halfmod: false, moderator: false, admin: false) end end + + def fangs_out! + update!(defanged: false, last_fanged_at: Time.now.utc) + LogWorker.perform_async("\u23eb <#{self.account.username}> switched to fanged #{role} mode.") + end + + def defang! + update!(defanged: true, last_fanged_at: nil) + LogWorker.perform_async("\u23ec <#{self.account.username}> is no longer in fanged #{role} mode.") + end end diff --git a/app/models/form/admin_settings.rb b/app/models/form/admin_settings.rb index 00abb3906..c9cd3a87f 100644 --- a/app/models/form/admin_settings.rb +++ b/app/models/form/admin_settings.rb @@ -88,7 +88,7 @@ class Form::AdminSettings validates :site_short_description, :site_description, html: { wrap_with: :p } validates :site_extended_description, :site_terms, :closed_registrations_message, html: true validates :registrations_mode, inclusion: { in: %w(open approved none) } - validates :min_invite_role, inclusion: { in: %w(disabled user moderator admin) } + validates :min_invite_role, inclusion: { in: %w(disabled user halfmod moderator admin) } validates :site_contact_email, :site_contact_username, presence: true validates :site_contact_username, existing_username: true validates :bootstrap_timeline_accounts, existing_username: { multiple: true } diff --git a/app/models/user.rb b/app/models/user.rb index 267818eff..00e2af458 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -48,6 +48,9 @@ # filters_enabled :boolean default(FALSE), not null # monsterfork_api :integer default("full"), not null # allow_unknown_follows :boolean default(FALSE), not null +# defanged :boolean default(TRUE), not null +# halfmod :boolean default(FALSE), not null +# last_fanged_at :datetime # class User < ApplicationRecord |