about summary refs log tree commit diff
path: root/app/controllers/admin/tags_controller.rb
blob: e9f4f2cfa3b35a67101d0957ee6a22f1f66f41fc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# frozen_string_literal: true

module Admin
  class TagsController < BaseController
    before_action :set_tags, only: :index
    before_action :set_tag, except: :index
    before_action :set_filter_params

    def index
      authorize :tag, :index?
    end

    def hide
      authorize @tag, :hide?
      @tag.account_tag_stat.update!(hidden: true)
      redirect_to admin_tags_path(@filter_params)
    end

    def unhide
      authorize @tag, :unhide?
      @tag.account_tag_stat.update!(hidden: false)
      redirect_to admin_tags_path(@filter_params)
    end

    private

    def set_tags
      @tags = Tag.discoverable
      @tags.merge!(Tag.hidden) if filter_params[:hidden]
    end

    def set_tag
      @tag = Tag.find(params[:id])
    end

    def set_filter_params
      @filter_params = filter_params.to_hash.symbolize_keys
    end

    def filter_params
      params.permit(:hidden)
    end
  end
end