Class: BookmarksController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- BookmarksController
- Defined in:
- app/controllers/bookmarks_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
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
#bulk ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'app/controllers/bookmarks_controller.rb', line 78 def bulk if params[:bookmark_ids].present? unless Array === params[:bookmark_ids] raise Discourse::InvalidParameters.new( "Expecting bookmark_ids to contain a list of bookmark ids", ) end bookmark_ids = params[:bookmark_ids].map { |t| t.to_i } else raise ActionController::ParameterMissing.new(:bookmark_ids) end operation = params.require(:operation).permit(:type).to_h.symbolize_keys raise ActionController::ParameterMissing.new(:operation_type) if operation[:type].blank? operator = BookmarksBulkAction.new(current_user, bookmark_ids, operation) changed_bookmark_ids = operator.perform! render_json_dump bookmark_ids: changed_bookmark_ids end |
#create ⇒ Object
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 |
# File 'app/controllers/bookmarks_controller.rb', line 6 def create params.require(:bookmarkable_id) params.require(:bookmarkable_type) params.permit( :bookmarkable_id, :bookmarkable_type, :name, :reminder_at, :auto_delete_preference, ) RateLimiter.new( current_user, "create_bookmark", SiteSetting.max_bookmarks_per_day, 1.day.to_i, ).performed! bookmark_manager = BookmarkManager.new(current_user) bookmark = bookmark_manager.create_for( bookmarkable_id: params[:bookmarkable_id], bookmarkable_type: params[:bookmarkable_type], name: params[:name], reminder_at: params[:reminder_at], options: { auto_delete_preference: params[:auto_delete_preference], }, ) return render json: success_json.merge(id: bookmark.id) if bookmark_manager.errors.empty? render json: failed_json.merge(errors: bookmark_manager.errors.), status: 400 end |
#destroy ⇒ Object
41 42 43 44 45 46 |
# File 'app/controllers/bookmarks_controller.rb', line 41 def destroy params.require(:id) destroyed_bookmark = BookmarkManager.new(current_user).destroy(params[:id]) render json: success_json.merge(BookmarkManager.(destroyed_bookmark, current_user)) end |
#toggle_pin ⇒ Object
67 68 69 70 71 72 73 74 75 76 |
# File 'app/controllers/bookmarks_controller.rb', line 67 def toggle_pin params.require(:bookmark_id) bookmark_manager = BookmarkManager.new(current_user) bookmark_manager.toggle_pin(bookmark_id: params[:bookmark_id]) return render json: success_json if bookmark_manager.errors.empty? render json: failed_json.merge(errors: bookmark_manager.errors.), status: 400 end |
#update ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/controllers/bookmarks_controller.rb', line 48 def update params.require(:id) params.permit(:id, :name, :reminder_at, :auto_delete_preference) bookmark_manager = BookmarkManager.new(current_user) bookmark_manager.update( bookmark_id: params[:id], name: params[:name], reminder_at: params[:reminder_at], options: { auto_delete_preference: params[:auto_delete_preference], }, ) return render json: success_json if bookmark_manager.errors.empty? render json: failed_json.merge(errors: bookmark_manager.errors.), status: 400 end |