group admin methods for essential management

This commit is contained in:
2458773093
2019-07-29 22:45:29 +03:00
parent 06bda6e9e6
commit 43210360e9
7 changed files with 138 additions and 4 deletions

View 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

View File

@@ -1,14 +1,26 @@
# 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?

View 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') }

View 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