Class: ComposerController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- ComposerController
- Defined in:
- app/controllers/composer_controller.rb
Constant Summary
Constants inherited from ApplicationController
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, #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 ReadOnlyMixin
#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
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
#mentions ⇒ 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 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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'app/controllers/composer_controller.rb', line 6 def mentions @names = params.require(:names) raise Discourse::InvalidParameters.new(:names) if !@names.kind_of?(Array) || @names.size > 20 if params[:topic_id].present? @topic = Topic.find_by(id: params[:topic_id]) guardian.ensure_can_see!(@topic) end # allowed_names is necessary just for new private messages. @allowed_names = if params[:allowed_names].present? raise Discourse.InvalidParameters(:allowed_names) if !params[:allowed_names].is_a?(Array) params[:allowed_names] << current_user.username else [] end user_reasons = {} group_reasons = {} @names.each do |name| if user = users[name] reason = user_reason(user) user_reasons[name] = reason if reason.present? elsif group = groups[name] reason = group_reason(group) group_reasons[name] = reason if reason.present? end end if @topic && @names.include?(SiteSetting.here_mention) && guardian.can_mention_here? here_count = PostAlerter.new.(@topic.first_post, exclude_ids: [current_user.id]).size end serialized_groups = groups .values .reduce({}) do |hash, group| serialized_group = { user_count: group.user_count } if group_reasons[group.name] == :not_allowed && members_visible_group_ids.include?(group.id) && (@topic&. || @allowed_names.present?) # Find users that are notified already because they have been invited # directly or via a group notified_count = GroupUser # invited directly .where(user_id: topic_allowed_user_ids) .or( # invited via a group GroupUser.where( user_id: GroupUser.where(group_id: topic_allowed_group_ids).select(:user_id), ), ) .where(group_id: group.id) .select(:user_id) .distinct .count if notified_count > 0 if notified_count == group.user_count group_reasons.delete(group.name) else group_reasons[group.name] = :some_not_allowed serialized_group[:notified_count] = notified_count end end end hash[group.name] = serialized_group hash end render json: { users: users.keys, user_reasons: user_reasons, groups: serialized_groups, group_reasons: group_reasons, here_count: here_count, max_users_notified_per_group_mention: SiteSetting.max_users_notified_per_group_mention, } end |