diff --git a/app/controllers/admin/groups_controller.rb b/app/controllers/admin/groups_controller.rb index efac4830..74c4760f 100644 --- a/app/controllers/admin/groups_controller.rb +++ b/app/controllers/admin/groups_controller.rb @@ -3,6 +3,7 @@ module Admin class GroupsController < BaseController before_action :set_group, except: [:index] + before_action :set_accounts, only: [:show] before_action :set_filter_params def index @@ -15,33 +16,24 @@ module Admin end 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 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) + flash[:notice] = 'Group destroyed' + redirect_to admin_groups_path 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) + + 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' end private @@ -50,12 +42,27 @@ module Admin @group = Group.find(params[:id]) end + def set_accounts + @admins = GroupAccount.where(group: @group, role: 'admin') + @mods = GroupAccount.where(group: @group, role: 'moderator') + 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) + params.require(:group).permit( + :title, + :description, + # :slug, + :tags, + :is_private, + :is_archived, + :is_visible, + :is_featured, + :is_nsfw + ) end def filtered_groups diff --git a/app/views/admin/groups/_group.html.haml b/app/views/admin/groups/_group.html.haml index 9ad252e2..ed0487ab 100644 --- a/app/views/admin/groups/_group.html.haml +++ b/app/views/admin/groups/_group.html.haml @@ -6,12 +6,4 @@ - if group.is_featured? %span Y %td - = 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') } + = table_link_to '', 'Edit', admin_group_path(group) \ No newline at end of file diff --git a/app/views/admin/groups/show.html.haml b/app/views/admin/groups/show.html.haml index 658d01cf..b35a490a 100644 --- a/app/views/admin/groups/show.html.haml +++ b/app/views/admin/groups/show.html.haml @@ -10,7 +10,7 @@ -# view removed accounts .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" .dashboard__counters{ style: 'margin-top: 10px' } @@ -58,10 +58,51 @@ .fields-group = 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 = f.button :button, t('generic.save_changes'), type: :submit --# : todo : delete --# : todo : list admins --# : todo : list mods --# : todo : make ME admin \ No newline at end of file +%br +%hr +%br + +%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') } diff --git a/config/routes.rb b/config/routes.rb index cb3abd93..d2a09a75 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -171,8 +171,7 @@ Rails.application.routes.draw do resources :groups, only: [:index, :show, :update, :destroy] do member do - post :enable_featured - post :disable_featured + post :make_me_admin end end