]> cat aescling's git repositories - mastodon.git/commitdiff
Add admin function to deactivate all invites (#8279)
authorEugen Rochko <eugen@zeonfederated.com>
Sat, 18 Aug 2018 22:58:53 +0000 (00:58 +0200)
committerGitHub <noreply@github.com>
Sat, 18 Aug 2018 22:58:53 +0000 (00:58 +0200)
Fix #8261

app/controllers/admin/invites_controller.rb
app/policies/invite_policy.rb
app/views/admin/invites/index.html.haml
config/locales/en.yml
config/routes.rb

index faccaa7c899da1be4084738991b065a0233810af..44a8eec77b2eea27baf239b82797c5e87a2ef225 100644 (file)
@@ -30,6 +30,12 @@ module Admin
       redirect_to admin_invites_path
     end
 
+    def deactivate_all
+      authorize :invite, :deactivate_all?
+      Invite.available.in_batches.update_all(expires_at: Time.now.utc)
+      redirect_to admin_invites_path
+    end
+
     private
 
     def resource_params
index a2a65f934d9fd2b2769dd917da73ab5ba7cfb6de..14236f78b8c9ab9babd7c0d9c49531dc590c6f6a 100644 (file)
@@ -9,6 +9,10 @@ class InvitePolicy < ApplicationPolicy
     min_required_role?
   end
 
+  def deactivate_all?
+    admin?
+  end
+
   def destroy?
     owner? || (Setting.min_invite_role == 'admin' ? admin? : staff?)
   end
index 944a6047141b8f3651c87b28a9383a3fc6a4b7d9..42159e9f36750429856bfcba7de82aa8afb6ba66 100644 (file)
@@ -9,22 +9,28 @@
       %li= filter_link_to t('admin.invites.filter.available'), available: 1, expired: nil
       %li= filter_link_to t('admin.invites.filter.expired'), available: nil, expired: 1
 
+%hr.spacer/
+
 - if policy(:invite).create?
   %p= t('invites.prompt')
 
   = render 'invites/form'
 
-  %hr/
+  %hr.spacer/
 
-%table.table
-  %thead
-    %tr
-      %th
-      %th= t('invites.table.uses')
-      %th= t('invites.table.expires_at')
-      %th
-      %th
-  %tbody
-    = render @invites
+.table-wrapper
+  %table.table
+    %thead
+      %tr
+        %th
+        %th= t('invites.table.uses')
+        %th= t('invites.table.expires_at')
+        %th
+        %th
+    %tbody
+      = render @invites
 
 = paginate @invites
+
+- if policy(:invite).deactivate_all?
+  = link_to t('admin.invites.deactivate_all'), deactivate_all_admin_invites_path, method: :post, data: { confirm: t('admin.accounts.are_you_sure') }, class: 'button'
index 66ab8f10a1faba68bd167962d02caba1a157a25b..65fc7b78e07e991e08ea66067e26badadd8e0f76 100644 (file)
@@ -281,6 +281,7 @@ en:
       search: Search
       title: Known instances
     invites:
+      deactivate_all: Deactivate all
       filter:
         all: All
         available: Available
index fd3b5fe4ba1f3bbf6db8374aebde96a23aa91f17..a8716aae593cf0292e9bb258eadb6dfd626c3a5e 100644 (file)
@@ -134,7 +134,12 @@ Rails.application.routes.draw do
     resources :email_domain_blocks, only: [:index, :new, :create, :destroy]
     resources :action_logs, only: [:index]
     resource :settings, only: [:edit, :update]
-    resources :invites, only: [:index, :create, :destroy]
+
+    resources :invites, only: [:index, :create, :destroy] do
+      collection do
+        post :deactivate_all
+      end
+    end
 
     resources :relays, only: [:index, :new, :create, :destroy] do
       member do