2019-07-29 20:45:29 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Admin
|
2020-12-16 00:31:30 +00:00
|
|
|
class GroupsController < BaseController
|
|
|
|
before_action :set_group, except: [:index]
|
2020-12-30 17:16:47 +00:00
|
|
|
before_action :set_accounts, only: [:show]
|
2020-12-16 00:31:30 +00:00
|
|
|
|
|
|
|
def index
|
|
|
|
authorize :group, :index?
|
|
|
|
@groups = filtered_groups.page(params[:page])
|
|
|
|
end
|
2019-07-29 20:45:29 +01:00
|
|
|
|
2020-12-16 00:31:30 +00:00
|
|
|
def show
|
|
|
|
authorize :group, :index?
|
|
|
|
end
|
2019-07-29 20:45:29 +01:00
|
|
|
|
2020-12-16 00:31:30 +00:00
|
|
|
def update
|
2020-12-30 17:16:47 +00:00
|
|
|
if @group.update(resource_params)
|
|
|
|
redirect_to admin_group_path(@group.id), notice: I18n.t('generic.changes_saved_msg')
|
|
|
|
else
|
|
|
|
render action: :edit
|
|
|
|
end
|
2020-12-16 00:31:30 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
authorize @group, :destroy?
|
|
|
|
@group.destroy!
|
|
|
|
log_action :destroy, @group
|
2020-12-30 17:16:47 +00:00
|
|
|
flash[:notice] = 'Group destroyed'
|
|
|
|
redirect_to admin_groups_path
|
2020-12-16 00:31:30 +00:00
|
|
|
end
|
2020-12-30 17:16:47 +00:00
|
|
|
|
|
|
|
def make_me_admin
|
|
|
|
GroupAccount.create(group: @group, account: current_account, role: 'admin')
|
|
|
|
redirect_to admin_group_path(@group.id), notice: 'You are now an admin of this group'
|
2020-12-16 00:31:30 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def set_group
|
|
|
|
@group = Group.find(params[:id])
|
|
|
|
end
|
|
|
|
|
2020-12-30 17:16:47 +00:00
|
|
|
def set_accounts
|
|
|
|
@admins = GroupAccount.where(group: @group, role: 'admin')
|
|
|
|
@mods = GroupAccount.where(group: @group, role: 'moderator')
|
|
|
|
end
|
|
|
|
|
2020-12-16 00:31:30 +00:00
|
|
|
def resource_params
|
2020-12-30 17:16:47 +00:00
|
|
|
params.require(:group).permit(
|
|
|
|
:title,
|
|
|
|
:description,
|
|
|
|
# :slug,
|
|
|
|
:tags,
|
|
|
|
:is_private,
|
|
|
|
:is_archived,
|
|
|
|
:is_visible,
|
|
|
|
:is_featured,
|
|
|
|
:is_nsfw
|
|
|
|
)
|
2020-12-16 00:31:30 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def filtered_groups
|
2021-01-19 06:25:25 +00:00
|
|
|
GroupFilter.new(filter_params).results
|
2020-12-16 00:31:30 +00:00
|
|
|
end
|
2021-01-19 06:25:25 +00:00
|
|
|
|
2020-12-16 00:31:30 +00:00
|
|
|
def filter_params
|
2021-01-19 06:25:25 +00:00
|
|
|
params.permit(
|
|
|
|
:title,
|
|
|
|
:description,
|
|
|
|
:id,
|
|
|
|
:member_count_gte,
|
|
|
|
:created_at_gte
|
|
|
|
)
|
2019-07-29 20:45:29 +01:00
|
|
|
end
|
2020-12-16 00:31:30 +00:00
|
|
|
end
|
2019-07-29 20:45:29 +01:00
|
|
|
end
|
2020-12-16 00:31:30 +00:00
|
|
|
|