diff options
author | Starfall <us@starfall.systems> | 2021-02-26 22:07:00 -0600 |
---|---|---|
committer | Starfall <us@starfall.systems> | 2021-02-26 22:07:00 -0600 |
commit | 033b1b5b900babc9b068ddad0ae644c5f15e9ffe (patch) | |
tree | 76a4d5f8890836e855cccdf4ad7d58fd9c0159ee /app/controllers/admin | |
parent | 35f9f9565e142b8c8e7541549046bad679f1438d (diff) | |
parent | 4aa860b65bd796b09dc0ceffa1fdd7de31060a34 (diff) |
Merge remote-tracking branch 'glitchsoc/main' into main
Diffstat (limited to 'app/controllers/admin')
-rw-r--r-- | app/controllers/admin/rules_controller.rb | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/app/controllers/admin/rules_controller.rb b/app/controllers/admin/rules_controller.rb new file mode 100644 index 000000000..f3bed3ad8 --- /dev/null +++ b/app/controllers/admin/rules_controller.rb @@ -0,0 +1,59 @@ +# frozen_string_literal: true + +module Admin + class RulesController < BaseController + before_action :set_rule, except: [:index, :create] + + def index + authorize :rule, :index? + + @rules = Rule.ordered + @rule = Rule.new + end + + def create + authorize :rule, :create? + + @rule = Rule.new(resource_params) + + if @rule.save + redirect_to admin_rules_path + else + @rules = Rule.ordered + render :index + end + end + + def edit + authorize @rule, :update? + end + + def update + authorize @rule, :update? + + if @rule.update(resource_params) + redirect_to admin_rules_path + else + render :edit + end + end + + def destroy + authorize @rule, :destroy? + + @rule.discard + + redirect_to admin_rules_path + end + + private + + def set_rule + @rule = Rule.find(params[:id]) + end + + def resource_params + params.require(:rule).permit(:text, :priority) + end + end +end |