Commit 43210360 authored by 2458773093's avatar 2458773093

group admin methods for essential management

parent 06bda6e9
# 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
# frozen_string_literal: true
class GroupPolicy < ApplicationPolicy
def index?
true
end
def update?
check_archive!
is_group_admin?
if admin?
true
else
check_archive!
is_group_admin?
end
end
def destroy?
check_archive!
is_group_admin?
if admin?
true
else
check_archive!
is_group_admin?
end
end
def approve_status?
......
%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') }
- 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
\ No newline at end of file
......@@ -224,6 +224,13 @@ en:
update_status: "%{name} updated status by %{target}"
deleted_status: "(deleted status)"
title: Audit log
groups:
title: Groups
name: Group title
member_count: Members
featured: Featured
enable_featured: Feature
disable_featured: Unfeature
custom_emojis:
by_domain: Domain
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|
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 :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 :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? }
......
......@@ -245,6 +245,13 @@ Rails.application.routes.draw do
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 :tags, only: [:index] do
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment