about summary refs log tree commit diff
path: root/app/models/concerns
diff options
context:
space:
mode:
authormultiple creatures <dev@multiple-creature.party>2020-02-18 02:02:54 -0600
committermultiple creatures <dev@multiple-creature.party>2020-02-18 02:18:09 -0600
commit0f3b01eaab82325baaf1c7a4c75a322d3c21a67f (patch)
treef3d19c99328336997919803ffc6850a96d5a6411 /app/models/concerns
parentfc69e4a0bb4e3d2fdcb2ffef0f3211f8c347ed15 (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/concerns')
-rw-r--r--app/models/concerns/user_roles.rb45
1 files changed, 40 insertions, 5 deletions
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