From 826773ee79e6bb406ebd2c033564c81b57d91954 Mon Sep 17 00:00:00 2001 From: 2458773093 <2458773093@protonmail.com> Date: Tue, 16 Jul 2019 00:51:05 +0300 Subject: [PATCH] admin tool for editing pro status of accounts --- app/controllers/admin/accounts_controller.rb | 17 ++++++++++++++++- app/policies/account_policy.rb | 4 ++++ .../admin/accounts/_edit_pro_fields.html.haml | 7 +++++++ app/views/admin/accounts/edit_pro.html.haml | 8 ++++++++ app/views/admin/accounts/show.html.haml | 3 +++ config/routes.rb | 2 ++ 6 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 app/views/admin/accounts/_edit_pro_fields.html.haml create mode 100644 app/views/admin/accounts/edit_pro.html.haml diff --git a/app/controllers/admin/accounts_controller.rb b/app/controllers/admin/accounts_controller.rb index 5acbf749..0fa6d072 100644 --- a/app/controllers/admin/accounts_controller.rb +++ b/app/controllers/admin/accounts_controller.rb @@ -2,7 +2,7 @@ module Admin class AccountsController < BaseController - before_action :set_account, only: [:show, :subscribe, :unsubscribe, :redownload, :remove_avatar, :remove_header, :enable, :unsilence, :unsuspend, :memorialize, :approve, :reject, :verify, :unverify, :add_donor_badge, :remove_donor_badge, :add_investor_badge, :remove_investor_badge] + before_action :set_account, only: [:show, :subscribe, :unsubscribe, :redownload, :remove_avatar, :remove_header, :enable, :unsilence, :unsuspend, :memorialize, :approve, :reject, :verify, :unverify, :add_donor_badge, :remove_donor_badge, :add_investor_badge, :remove_investor_badge, :edit_pro, :save_pro] before_action :require_remote_account!, only: [:subscribe, :unsubscribe, :redownload] before_action :require_local_account!, only: [:enable, :memorialize, :approve, :reject] @@ -162,6 +162,17 @@ module Admin redirect_to admin_account_path(@account.id) end + def edit_pro + authorize @account, :edit_pro? + end + + def save_pro + authorize @account, :edit_pro? + + @account.update!(pro_params) + redirect_to edit_pro_admin_account_path(@account.id) + end + private def set_account @@ -196,5 +207,9 @@ module Admin :staff ) end + + def pro_params + params.require(:account).permit(:is_pro, :pro_expires_at) + end end end diff --git a/app/policies/account_policy.rb b/app/policies/account_policy.rb index d838f16e..7e95367f 100644 --- a/app/policies/account_policy.rb +++ b/app/policies/account_policy.rb @@ -61,6 +61,10 @@ class AccountPolicy < ApplicationPolicy staff? end + def edit_pro? + staff? + end + def update_badges? staff? end diff --git a/app/views/admin/accounts/_edit_pro_fields.html.haml b/app/views/admin/accounts/_edit_pro_fields.html.haml new file mode 100644 index 00000000..a48a5980 --- /dev/null +++ b/app/views/admin/accounts/_edit_pro_fields.html.haml @@ -0,0 +1,7 @@ +.fields-row + .fields-row__column.fields-row__column-6.fields-group + %label{for: "is_pro"} + PRO + = f.check_box :is_pro, wrapper: :with_label, hint: false, id: "is_pro" + .fields-row__column.fields-row__column-6.fields-group + = f.input :pro_expires_at, as: :string, wrapper: :with_label, hint: false \ No newline at end of file diff --git a/app/views/admin/accounts/edit_pro.html.haml b/app/views/admin/accounts/edit_pro.html.haml new file mode 100644 index 00000000..66a0f17d --- /dev/null +++ b/app/views/admin/accounts/edit_pro.html.haml @@ -0,0 +1,8 @@ +- content_for :page_title do + = 'Edit PRO status of @' + @account.acct + += simple_form_for @account, url: save_pro_admin_account_path(@account.id), method: :put do |f| + = render 'edit_pro_fields', f: f + + .actions + = f.button :button, t('generic.save_changes'), type: :submit \ No newline at end of file diff --git a/app/views/admin/accounts/show.html.haml b/app/views/admin/accounts/show.html.haml index a45f7a6a..4e709352 100644 --- a/app/views/admin/accounts/show.html.haml +++ b/app/views/admin/accounts/show.html.haml @@ -134,6 +134,9 @@ - if @account.is_pro? =fa_icon 'check' %time.formatted{ datetime: @account.pro_expires_at.iso8601, title: l(@account.pro_expires_at) }= l @account.pro_expires_at + %td + - if @account.local? + = table_link_to '', t('admin.accounts.edit_pro'), edit_pro_admin_account_path(@account.id), class: 'button' if can?(:verify, @account) %tr %th= t('admin.accounts.is_verified') diff --git a/config/routes.rb b/config/routes.rb index 5966cc72..b1a24b99 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -201,6 +201,8 @@ Rails.application.routes.draw do post :remove_donor_badge post :add_investor_badge post :remove_investor_badge + get :edit_pro + put :save_pro end resource :change_email, only: [:show, :update]