Class: TagGroupsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- TagGroupsController
- Defined in:
- app/controllers/tag_groups_controller.rb
Constant Summary
Constants inherited from ApplicationController
ApplicationController::CHALLENGE_KEY, ApplicationController::HONEYPOT_KEY, ApplicationController::LEGACY_NO_THEMES, ApplicationController::LEGACY_NO_UNOFFICIAL_PLUGINS, ApplicationController::NO_PLUGINS, ApplicationController::NO_THEMES, ApplicationController::NO_UNOFFICIAL_PLUGINS, ApplicationController::SAFE_MODE
Constants included from CanonicalURL::ControllerExtensions
CanonicalURL::ControllerExtensions::ALLOWED_CANONICAL_PARAMS
Instance Attribute Summary
Attributes inherited from ApplicationController
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #search ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Methods inherited from ApplicationController
#application_layout, #can_cache_content?, #clear_notifications, #conditionally_allow_site_embedding, #current_homepage, #discourse_expires_in, #dont_cache_page, #ember_cli_required?, #fetch_user_from_params, #guardian, #handle_permalink, #handle_theme, #handle_unverified_request, #has_escaped_fragment?, #immutable_for, #login_method, #no_cookies, #perform_refresh_session, #post_ids_including_replies, #preload_json, #rate_limit_second_factor!, #redirect_with_client_support, #render_json_dump, #render_serialized, requires_plugin, #rescue_discourse_actions, #resolve_safe_mode, #secure_session, #serialize_data, #set_current_user_for_logs, #set_layout, #set_mobile_view, #set_mp_snapshot_fields, #show_browser_update?, #store_preloaded, #use_crawler_layout?, #with_resolved_locale
Methods included from VaryHeader
Methods included from ThemeResolver
Methods included from ReadOnlyMixin
#add_readonly_header, #allowed_in_staff_writes_only_mode?, #block_if_readonly_mode, #check_readonly_mode, #get_or_check_readonly_mode, #get_or_check_staff_writes_only_mode, included, #staff_writes_only_mode?
Methods included from Hijack
Methods included from GlobalPath
#cdn_path, #cdn_relative_path, #full_cdn_url, #path, #upload_cdn_path
Methods included from JsonError
Methods included from CanonicalURL::ControllerExtensions
#canonical_url, #default_canonical, included
Methods included from CurrentUser
#clear_current_user, #current_user, has_auth_cookie?, #is_api?, #is_user_api?, #log_off_user, #log_on_user, lookup_from_env, #refresh_session
Instance Method Details
#create ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'app/controllers/tag_groups_controller.rb', line 50 def create guardian.ensure_can_admin_tag_groups! @tag_group = TagGroup.new(tag_groups_params) if @tag_group.save StaffActionLogger.new(current_user).log_tag_group_create( @tag_group.name, TagGroupSerializer.new(@tag_group).to_json(root: false), ) render_serialized(@tag_group, TagGroupSerializer) else render_json_error(@tag_group) end end |
#destroy ⇒ Object
74 75 76 77 78 79 80 81 82 |
# File 'app/controllers/tag_groups_controller.rb', line 74 def destroy guardian.ensure_can_admin_tag_groups! StaffActionLogger.new(current_user).log_tag_group_destroy( @tag_group.name, TagGroupSerializer.new(@tag_group).to_json(root: false), ) @tag_group.destroy render json: success_json end |
#index ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/controllers/tag_groups_controller.rb', line 10 def index tag_groups = TagGroup.order("name ASC").includes(:parent_tag).preload(:tags).all serializer = ActiveModel::ArraySerializer.new( tag_groups, each_serializer: TagGroupSerializer, root: "tag_groups", ) respond_to do |format| format.html do store_preloaded "tagGroups", MultiJson.dump(serializer) render "default/empty" end format.json { render_json_dump(serializer) } end end |
#new ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/controllers/tag_groups_controller.rb', line 38 def new tag_groups = TagGroup.order("name ASC").includes(:parent_tag).preload(:tags).all serializer = ActiveModel::ArraySerializer.new( tag_groups, each_serializer: TagGroupSerializer, root: "tag_groups", ) store_preloaded "tagGroup", MultiJson.dump(serializer) render "default/empty" end |
#search ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'app/controllers/tag_groups_controller.rb', line 84 def search matches = TagGroup.includes(:tags).visible(guardian).all matches = matches.where("lower(name) ILIKE ?", "%#{params[:q].strip}%") if params[:q].present? if params[:names].present? matches = matches.where("lower(NAME) in (?)", params[:names].map(&:downcase)) end matches = matches.order("name").limit( fetch_limit_from_params(default: 5, max: SiteSetting.max_tag_search_results), ) render json: { results: matches.map { |x| { name: x.name, tag_names: x...pluck(:name).sort } }, } end |
#show ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'app/controllers/tag_groups_controller.rb', line 27 def show serializer = TagGroupSerializer.new(@tag_group) respond_to do |format| format.html do store_preloaded "tagGroup", MultiJson.dump(serializer) render "default/empty" end format.json { render_json_dump(serializer) } end end |
#update ⇒ Object
64 65 66 67 68 69 70 71 72 |
# File 'app/controllers/tag_groups_controller.rb', line 64 def update guardian.ensure_can_admin_tag_groups! old_data = TagGroupSerializer.new(@tag_group).to_json(root: false) json_result(@tag_group, serializer: TagGroupSerializer) do |tag_group| @tag_group.update(tag_groups_params) new_data = TagGroupSerializer.new(@tag_group).to_json(root: false) StaffActionLogger.new(current_user).log_tag_group_change(@tag_group.name, old_data, new_data) end end |