where i deviate from standard mastodon assets
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tags_controller.rb 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # frozen_string_literal: true
  2. module Admin
  3. class TagsController < BaseController
  4. before_action :set_tags, only: :index
  5. before_action :set_tag, except: :index
  6. def index
  7. authorize :tag, :index?
  8. end
  9. def show
  10. authorize @tag, :show?
  11. end
  12. def update
  13. authorize @tag, :update?
  14. if @tag.update(tag_params.merge(reviewed_at: Time.now.utc))
  15. redirect_to admin_tag_path(@tag.id)
  16. else
  17. render :show
  18. end
  19. end
  20. private
  21. def set_tags
  22. @tags = filtered_tags.page(params[:page])
  23. end
  24. def set_tag
  25. @tag = Tag.find(params[:id])
  26. end
  27. def filtered_tags
  28. scope = Tag
  29. scope = scope.discoverable if filter_params[:context] == 'directory'
  30. scope = scope.reviewed if filter_params[:review] == 'reviewed'
  31. scope = scope.pending_review if filter_params[:review] == 'pending_review'
  32. scope.reorder(score: :desc)
  33. end
  34. def filter_params
  35. params.slice(:context, :review).permit(:context, :review)
  36. end
  37. def tag_params
  38. params.require(:tag).permit(:name, :trendable, :usable, :listable)
  39. end
  40. end
  41. end