Updated admin Group editing page

• Updated:
- admin Group editing page to include list of admin mods, ability to delete group, ability to make (me/admin) admin of the group
This commit is contained in:
mgabdev 2020-12-30 12:16:47 -05:00
parent 381a5bacc6
commit 2e1f12a33a
4 changed files with 76 additions and 37 deletions

View File

@ -3,6 +3,7 @@
module Admin module Admin
class GroupsController < BaseController class GroupsController < BaseController
before_action :set_group, except: [:index] before_action :set_group, except: [:index]
before_action :set_accounts, only: [:show]
before_action :set_filter_params before_action :set_filter_params
def index def index
@ -15,33 +16,24 @@ module Admin
end end
def update def update
# if @group.update(resource_params)
redirect_to admin_group_path(@group.id), notice: I18n.t('generic.changes_saved_msg')
else
render action: :edit
end
end end
def destroy def destroy
authorize @group, :destroy? authorize @group, :destroy?
@group.destroy! @group.destroy!
log_action :destroy, @group log_action :destroy, @group
flash[:notice] = I18n.t('admin.groups.destroyed_msg') flash[:notice] = 'Group destroyed'
redirect_to admin_groups_path(page: params[:page], **@filter_params) redirect_to admin_groups_path
end end
def enable_featured def make_me_admin
authorize @group, :update? GroupAccount.create(group: @group, account: current_account, role: 'admin')
@group.is_featured = true redirect_to admin_group_path(@group.id), notice: 'You are now an admin of this group'
@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 end
private private
@ -50,12 +42,27 @@ module Admin
@group = Group.find(params[:id]) @group = Group.find(params[:id])
end end
def set_accounts
@admins = GroupAccount.where(group: @group, role: 'admin')
@mods = GroupAccount.where(group: @group, role: 'moderator')
end
def set_filter_params def set_filter_params
@filter_params = filter_params.to_hash.symbolize_keys @filter_params = filter_params.to_hash.symbolize_keys
end end
def resource_params def resource_params
params.require(:group).permit(:is_featured, :is_nsfw) params.require(:group).permit(
:title,
:description,
# :slug,
:tags,
:is_private,
:is_archived,
:is_visible,
:is_featured,
:is_nsfw
)
end end
def filtered_groups def filtered_groups

View File

@ -7,11 +7,3 @@
%span Y %span Y
%td %td
= table_link_to '', 'Edit', admin_group_path(group) = table_link_to '', 'Edit', admin_group_path(group)
-# %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

@ -10,7 +10,7 @@
-# view removed accounts -# view removed accounts
.card.h-card{:style => "height:300px"} .card.h-card{:style => "height:300px"}
.card__img .card__img{:style => "height:300px"}
= image_tag full_asset_url(@group.cover_image.url), alt: '', :style => "height:300px" = image_tag full_asset_url(@group.cover_image.url), alt: '', :style => "height:300px"
.dashboard__counters{ style: 'margin-top: 10px' } .dashboard__counters{ style: 'margin-top: 10px' }
@ -58,10 +58,51 @@
.fields-group .fields-group
= f.input :is_visible, as: :boolean, wrapper: :with_label, label: 'Is Visible?' = f.input :is_visible, as: :boolean, wrapper: :with_label, label: 'Is Visible?'
.fields-group
= f.input :is_archived, as: :boolean, wrapper: :with_label, label: 'Is Archived?'
.actions .actions
= f.button :button, t('generic.save_changes'), type: :submit = f.button :button, t('generic.save_changes'), type: :submit
-# : todo : delete %br
-# : todo : list admins %hr
-# : todo : list mods %br
-# : todo : make ME admin
%span Group Admins and Moderators
%br
%br
.table-wrapper
%table.table
%thead
%tr
%th= t('admin.accounts.username')
%th Role
%tbody
- @admins.each do |acct|
%tr
%td
= admin_account_link_to(acct.account)
%td
%span Admin
- @mods.each do |acct|
%tr
%td
= admin_account_link_to(acct.account)
%td
%span Moderator
%br
%hr
%br
.actions
= table_link_to 'arrow-up', 'Make me Admin', make_me_admin_admin_group_path(@group.id), method: :post, data: { confirm: t('admin.accounts.are_you_sure') }
%br
%hr
%br
.actions
= table_link_to 'times', 'Delete Group', admin_group_path(@group.id), method: :delete, data: { confirm: t('admin.accounts.are_you_sure') }

View File

@ -171,8 +171,7 @@ Rails.application.routes.draw do
resources :groups, only: [:index, :show, :update, :destroy] do resources :groups, only: [:index, :show, :update, :destroy] do
member do member do
post :enable_featured post :make_me_admin
post :disable_featured
end end
end end