group admin methods for essential management
This commit is contained in:
parent
06bda6e9e6
commit
43210360e9
67
app/controllers/admin/groups_controller.rb
Normal file
67
app/controllers/admin/groups_controller.rb
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module Admin
|
||||||
|
class GroupsController < BaseController
|
||||||
|
before_action :set_group, except: [:index]
|
||||||
|
before_action :set_filter_params
|
||||||
|
|
||||||
|
def index
|
||||||
|
authorize :group, :index?
|
||||||
|
@groups = filtered_groups.page(params[:page])
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
authorize @group, :destroy?
|
||||||
|
@group.destroy!
|
||||||
|
log_action :destroy, @group
|
||||||
|
flash[:notice] = I18n.t('admin.groups.destroyed_msg')
|
||||||
|
redirect_to admin_groups_path(page: params[:page], **@filter_params)
|
||||||
|
end
|
||||||
|
|
||||||
|
def enable_featured
|
||||||
|
authorize @group, :update?
|
||||||
|
@group.is_featured = true
|
||||||
|
@group.save!
|
||||||
|
log_action :update, @group
|
||||||
|
flash[:notice] = I18n.t('admin.groups.updated_msg')
|
||||||
|
redirect_to admin_groups_path(page: params[:page], **@filter_params)
|
||||||
|
end
|
||||||
|
|
||||||
|
def disable_featured
|
||||||
|
authorize @group, :update?
|
||||||
|
@group.is_featured = false
|
||||||
|
@group.save!
|
||||||
|
log_action :update, @group
|
||||||
|
flash[:notice] = I18n.t('admin.groups.updated_msg')
|
||||||
|
redirect_to admin_groups_path(page: params[:page], **@filter_params)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def set_group
|
||||||
|
@group = Group.find(params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
|
def set_filter_params
|
||||||
|
@filter_params = filter_params.to_hash.symbolize_keys
|
||||||
|
end
|
||||||
|
|
||||||
|
def resource_params
|
||||||
|
params.require(:group).permit(:is_featured, :is_nsfw)
|
||||||
|
end
|
||||||
|
|
||||||
|
def filtered_groups
|
||||||
|
query = Group.order('is_featured DESC, member_count DESC')
|
||||||
|
|
||||||
|
if params[:title]
|
||||||
|
query = query.where("LOWER(title) LIKE LOWER(?)", "%#{params[:title]}%")
|
||||||
|
end
|
||||||
|
|
||||||
|
return query
|
||||||
|
end
|
||||||
|
|
||||||
|
def filter_params
|
||||||
|
params.permit(:sort,)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -1,15 +1,27 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class GroupPolicy < ApplicationPolicy
|
class GroupPolicy < ApplicationPolicy
|
||||||
|
def index?
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
def update?
|
def update?
|
||||||
|
if admin?
|
||||||
|
true
|
||||||
|
else
|
||||||
check_archive!
|
check_archive!
|
||||||
is_group_admin?
|
is_group_admin?
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def destroy?
|
def destroy?
|
||||||
|
if admin?
|
||||||
|
true
|
||||||
|
else
|
||||||
check_archive!
|
check_archive!
|
||||||
is_group_admin?
|
is_group_admin?
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def approve_status?
|
def approve_status?
|
||||||
check_archive!
|
check_archive!
|
||||||
|
14
app/views/admin/groups/_group.html.haml
Normal file
14
app/views/admin/groups/_group.html.haml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
%tr
|
||||||
|
%td= group.id
|
||||||
|
%td= group.title
|
||||||
|
%td= group.member_count
|
||||||
|
%td
|
||||||
|
- if group.is_featured?
|
||||||
|
= t('admin.groups.featured')
|
||||||
|
%td
|
||||||
|
- if not group.is_featured?
|
||||||
|
= table_link_to 'power-off', t('admin.groups.enable_featured'), enable_featured_admin_group_path(group, page: params[:page], **@filter_params), method: :post, data: { confirm: t('admin.accounts.are_you_sure') }
|
||||||
|
- else
|
||||||
|
= table_link_to 'power-off', t('admin.groups.disable_featured'), disable_featured_admin_group_path(group, page: params[:page], **@filter_params), method: :post, data: { confirm: t('admin.accounts.are_you_sure') }
|
||||||
|
%td
|
||||||
|
= table_link_to 'times', t('admin.groups.delete'), admin_group_path(group, page: params[:page], **@filter_params), method: :delete, data: { confirm: t('admin.accounts.are_you_sure') }
|
26
app/views/admin/groups/index.html.haml
Normal file
26
app/views/admin/groups/index.html.haml
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
- content_for :page_title do
|
||||||
|
= t('admin.groups.title')
|
||||||
|
|
||||||
|
= form_tag admin_groups_url, method: 'GET', class: 'simple_form' do
|
||||||
|
.fields-group
|
||||||
|
.input.string.optional
|
||||||
|
= text_field_tag :title, params[:title], class: 'string optional', placeholder: I18n.t("admin.groups.name")
|
||||||
|
|
||||||
|
.actions
|
||||||
|
%button= t('admin.accounts.search')
|
||||||
|
= link_to t('admin.accounts.reset'), admin_groups_path, class: 'button negative'
|
||||||
|
|
||||||
|
.table-wrapper
|
||||||
|
%table.table
|
||||||
|
%thead
|
||||||
|
%tr
|
||||||
|
%th= t('admin.groups.id')
|
||||||
|
%th= t('admin.groups.title')
|
||||||
|
%th= t('admin.groups.member_count')
|
||||||
|
%th
|
||||||
|
%th
|
||||||
|
%th
|
||||||
|
%tbody
|
||||||
|
= render @groups
|
||||||
|
|
||||||
|
= paginate @groups
|
@ -224,6 +224,13 @@ en:
|
|||||||
update_status: "%{name} updated status by %{target}"
|
update_status: "%{name} updated status by %{target}"
|
||||||
deleted_status: "(deleted status)"
|
deleted_status: "(deleted status)"
|
||||||
title: Audit log
|
title: Audit log
|
||||||
|
groups:
|
||||||
|
title: Groups
|
||||||
|
name: Group title
|
||||||
|
member_count: Members
|
||||||
|
featured: Featured
|
||||||
|
enable_featured: Feature
|
||||||
|
disable_featured: Unfeature
|
||||||
custom_emojis:
|
custom_emojis:
|
||||||
by_domain: Domain
|
by_domain: Domain
|
||||||
copied_msg: Successfully created local copy of the emoji
|
copied_msg: Successfully created local copy of the emoji
|
||||||
|
@ -48,6 +48,7 @@ SimpleNavigation::Configuration.run do |navigation|
|
|||||||
n.item :admin, safe_join([fa_icon('cogs fw'), t('admin.title')]), admin_dashboard_url, if: proc { current_user.staff? } do |s|
|
n.item :admin, safe_join([fa_icon('cogs fw'), t('admin.title')]), admin_dashboard_url, if: proc { current_user.staff? } do |s|
|
||||||
s.item :dashboard, safe_join([fa_icon('tachometer fw'), t('admin.dashboard.title')]), admin_dashboard_url
|
s.item :dashboard, safe_join([fa_icon('tachometer fw'), t('admin.dashboard.title')]), admin_dashboard_url
|
||||||
s.item :settings, safe_join([fa_icon('cogs fw'), t('admin.settings.title')]), edit_admin_settings_url, if: -> { current_user.admin? }, highlights_on: %r{/admin/settings}
|
s.item :settings, safe_join([fa_icon('cogs fw'), t('admin.settings.title')]), edit_admin_settings_url, if: -> { current_user.admin? }, highlights_on: %r{/admin/settings}
|
||||||
|
s.item :groups, safe_join([fa_icon('smile-o fw'), t('admin.groups.title')]), admin_groups_url, highlights_on: %r{/admin/groups}
|
||||||
s.item :custom_emojis, safe_join([fa_icon('smile-o fw'), t('admin.custom_emojis.title')]), admin_custom_emojis_url, highlights_on: %r{/admin/custom_emojis}
|
s.item :custom_emojis, safe_join([fa_icon('smile-o fw'), t('admin.custom_emojis.title')]), admin_custom_emojis_url, highlights_on: %r{/admin/custom_emojis}
|
||||||
s.item :relays, safe_join([fa_icon('exchange fw'), t('admin.relays.title')]), admin_relays_url, if: -> { current_user.admin? }, highlights_on: %r{/admin/relays}
|
s.item :relays, safe_join([fa_icon('exchange fw'), t('admin.relays.title')]), admin_relays_url, if: -> { current_user.admin? }, highlights_on: %r{/admin/relays}
|
||||||
s.item :subscriptions, safe_join([fa_icon('paper-plane-o fw'), t('admin.subscriptions.title')]), admin_subscriptions_url, if: -> { current_user.admin? }
|
s.item :subscriptions, safe_join([fa_icon('paper-plane-o fw'), t('admin.subscriptions.title')]), admin_subscriptions_url, if: -> { current_user.admin? }
|
||||||
|
@ -245,6 +245,13 @@ Rails.application.routes.draw do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
resources :groups, only: [:index, :destroy] do
|
||||||
|
member do
|
||||||
|
post :enable_featured
|
||||||
|
post :disable_featured
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
resources :account_moderation_notes, only: [:create, :destroy]
|
resources :account_moderation_notes, only: [:create, :destroy]
|
||||||
|
|
||||||
resources :tags, only: [:index] do
|
resources :tags, only: [:index] do
|
||||||
|
Loading…
Reference in New Issue
Block a user