Class: SidebarSectionsController
Constant Summary
ApplicationController::LEGACY_NO_THEMES, ApplicationController::LEGACY_NO_UNOFFICIAL_PLUGINS, ApplicationController::NO_PLUGINS, ApplicationController::NO_THEMES, ApplicationController::NO_UNOFFICIAL_PLUGINS, ApplicationController::SAFE_MODE
CanonicalURL::ControllerExtensions::ALLOWED_CANONICAL_PARAMS
Instance Attribute Summary
#theme_id
Instance Method Summary
collapse
#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, #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
#ensure_vary_header
#add_readonly_header, #allowed_in_staff_writes_only_mode?, #block_if_readonly_mode, #check_readonly_mode, included, #staff_writes_only_mode?
Methods included from Hijack
#hijack
Methods included from GlobalPath
#cdn_path, #cdn_relative_path, #full_cdn_url, #path, #upload_cdn_path
Methods included from JsonError
#create_errors_json
#canonical_url, #default_canonical, included
#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
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'app/controllers/sidebar_sections_controller.rb', line 19
def create
=
SidebarSection.create!(section_params.merge(sidebar_urls_attributes: links_params))
if .public?
StaffActionLogger.new(current_user).()
MessageBus.publish("/refresh-sidebar-sections", nil)
Site.clear_anon_cache!
end
render_serialized(, SidebarSectionSerializer)
rescue ActiveRecord::RecordInvalid => e
render_json_error(e.record.errors.full_messages.first)
rescue ActiveRecord::NestedAttributes::TooManyRecords => e
render_json_error(e.message)
end
|
#destroy ⇒ Object
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# File 'app/controllers/sidebar_sections_controller.rb', line 97
def destroy
= SidebarSection.find_by(id: section_params["id"])
@guardian.ensure_can_delete!()
.destroy!
if .public?
StaffActionLogger.new(current_user).()
MessageBus.publish("/refresh-sidebar-sections", nil)
end
render json: success_json
rescue Discourse::InvalidAccess
render json: failed_json, status: 403
end
|
#index ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
|
# File 'app/controllers/sidebar_sections_controller.rb', line 7
def index
sections =
SidebarSection
.strict_loading
.includes(:sidebar_urls)
.where("public OR user_id = ?", current_user.id)
.order("(public IS TRUE) DESC, title ASC")
.map { |section| SidebarSectionSerializer.new(section, root: false) }
render json: sections
end
|
#links_params ⇒ Object
118
119
120
|
# File 'app/controllers/sidebar_sections_controller.rb', line 118
def links_params
params.permit(links: %i[icon name value id _destroy segment])["links"]
end
|
#reorder ⇒ Object
86
87
88
89
90
91
92
93
94
95
|
# File 'app/controllers/sidebar_sections_controller.rb', line 86
def reorder
= SidebarSection.find_by(id: reorder_params["sidebar_section_id"])
@guardian.ensure_can_edit!()
order = reorder_params["links_order"].map(&:to_i).each_with_index.to_h
set_order(, order)
render_serialized(, SidebarSectionSerializer)
rescue Discourse::InvalidAccess
render json: failed_json, status: 403
end
|
#reorder_params ⇒ Object
122
123
124
|
# File 'app/controllers/sidebar_sections_controller.rb', line 122
def reorder_params
params.permit(:sidebar_section_id, links_order: [])
end
|
#section_params ⇒ Object
112
113
114
115
116
|
# File 'app/controllers/sidebar_sections_controller.rb', line 112
def section_params
section_params = params.permit(:id, :title, :public)
section_params.merge!(user: current_user) if !params[:public]
section_params
end
|
#update ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'app/controllers/sidebar_sections_controller.rb', line 36
def update
= SidebarSection.find_by(id: section_params["id"])
@guardian.ensure_can_edit!()
ActiveRecord::Base.transaction do
.update!(section_params.merge(sidebar_urls_attributes: links_params))
..update_all(user_id: .user_id)
order =
.
.sort_by do |url|
links_params.index { |link| link["name"] == url.name && link["value"] == url.value } ||
-1
end
.each_with_index
.map { |url, index| [url.id, index] }
.to_h
set_order(, order)
end
if .public?
StaffActionLogger.new(current_user).()
MessageBus.publish("/refresh-sidebar-sections", nil)
Site.clear_anon_cache!
end
render_serialized(.reload, SidebarSectionSerializer)
rescue ActiveRecord::RecordInvalid => e
render_json_error(e.record.errors.full_messages.first)
rescue ActiveRecord::NestedAttributes::TooManyRecords => e
render_json_error(e.message)
rescue Discourse::InvalidAccess
render json: failed_json, status: 403
end
|