Skip to content
代码片段 群组 项目
提交 bc5903ab 编辑于 作者: Nicolas Dular's avatar Nicolas Dular
浏览文件

Merge branch '415490-provide-resource_id-to-chat-bot' into 'master'

No related branches found
No related tags found
无相关合并请求
...@@ -12,6 +12,7 @@ module IssuableActions ...@@ -12,6 +12,7 @@ module IssuableActions
before_action :authorize_destroy_issuable!, only: :destroy before_action :authorize_destroy_issuable!, only: :destroy
before_action :check_destroy_confirmation!, only: :destroy before_action :check_destroy_confirmation!, only: :destroy
before_action :authorize_admin_issuable!, only: :bulk_update before_action :authorize_admin_issuable!, only: :bulk_update
before_action :set_application_context!, only: :show
end end
def show def show
...@@ -226,6 +227,10 @@ def authorize_update_issuable! ...@@ -226,6 +227,10 @@ def authorize_update_issuable!
render_404 unless can?(current_user, :"update_#{resource_name}", issuable) render_404 unless can?(current_user, :"update_#{resource_name}", issuable)
end end
def set_application_context!
# no-op. The logic is defined in EE module.
end
def bulk_update_params def bulk_update_params
clean_bulk_update_params( clean_bulk_update_params(
params.require(:update).permit(bulk_update_permitted_keys) params.require(:update).permit(bulk_update_permitted_keys)
......
...@@ -75,6 +75,8 @@ def resolve_conflicts ...@@ -75,6 +75,8 @@ def resolve_conflicts
private private
alias_method :issuable, :merge_request
def authorize_can_resolve_conflicts! def authorize_can_resolve_conflicts!
@conflicts_list = ::MergeRequests::Conflicts::ListService.new(@merge_request) @conflicts_list = ::MergeRequests::Conflicts::ListService.new(@merge_request)
......
...@@ -1045,6 +1045,7 @@ Input type: `AdminSidekiqQueuesDeleteJobsInput` ...@@ -1045,6 +1045,7 @@ Input type: `AdminSidekiqQueuesDeleteJobsInput`
   
| Name | Type | Description | | Name | Type | Description |
| ---- | ---- | ----------- | | ---- | ---- | ----------- |
| <a id="mutationadminsidekiqqueuesdeletejobsairesource"></a>`aiResource` | [`String`](#string) | Delete jobs matching ai_resource in the context metadata. |
| <a id="mutationadminsidekiqqueuesdeletejobsartifactsize"></a>`artifactSize` | [`String`](#string) | Delete jobs matching artifact_size in the context metadata. | | <a id="mutationadminsidekiqqueuesdeletejobsartifactsize"></a>`artifactSize` | [`String`](#string) | Delete jobs matching artifact_size in the context metadata. |
| <a id="mutationadminsidekiqqueuesdeletejobsartifactusedcdn"></a>`artifactUsedCdn` | [`String`](#string) | Delete jobs matching artifact_used_cdn in the context metadata. | | <a id="mutationadminsidekiqqueuesdeletejobsartifactusedcdn"></a>`artifactUsedCdn` | [`String`](#string) | Delete jobs matching artifact_used_cdn in the context metadata. |
| <a id="mutationadminsidekiqqueuesdeletejobsartifactsdependenciescount"></a>`artifactsDependenciesCount` | [`String`](#string) | Delete jobs matching artifacts_dependencies_count in the context metadata. | | <a id="mutationadminsidekiqqueuesdeletejobsartifactsdependenciescount"></a>`artifactsDependenciesCount` | [`String`](#string) | Delete jobs matching artifacts_dependencies_count in the context metadata. |
...@@ -18,5 +18,10 @@ module IssuableActions ...@@ -18,5 +18,10 @@ module IssuableActions
def bulk_update_permitted_keys def bulk_update_permitted_keys
@permitted_keys ||= (super + EE_PERMITTED_KEYS).freeze @permitted_keys ||= (super + EE_PERMITTED_KEYS).freeze
end end
override :set_application_context!
def set_application_context!
::Gitlab::ApplicationContext.push(ai_resource: issuable.try(:to_global_id))
end
end end
end end
...@@ -21,9 +21,7 @@ module IssuesController ...@@ -21,9 +21,7 @@ module IssuesController
before_action only: :show do before_action only: :show do
push_licensed_feature(:escalation_policies, project) push_licensed_feature(:escalation_policies, project)
push_force_frontend_feature_flag(:summarize_comments, can?(current_user, :summarize_notes, issue)) push_force_frontend_feature_flag(:summarize_comments, can?(current_user, :summarize_notes, issue))
push_force_frontend_feature_flag(:generate_description_ai, push_force_frontend_feature_flag(:generate_description_ai, can?(current_user, :generate_description, issue))
can?(current_user, :generate_description, issue))
@ai_resource_id = issue.to_global_id
end end
before_action :redirect_if_test_case, only: [:show] before_action :redirect_if_test_case, only: [:show]
......
- return unless ::Gitlab::Llm::TanukiBot.enabled_for?(user: current_user) - return unless ::Gitlab::Llm::TanukiBot.enabled_for?(user: current_user)
- resource_id = Gitlab::ApplicationContext.current_context_attribute(:ai_resource).presence
#js-tanuki-bot-chat-app{ data: { user_id: current_user.to_global_id, resource_id: @ai_resource_id } } #js-tanuki-bot-chat-app{ data: { user_id: current_user.to_global_id, resource_id: resource_id } }
...@@ -6,8 +6,15 @@ module ApplicationContext ...@@ -6,8 +6,15 @@ module ApplicationContext
extend ::Gitlab::Utils::Override extend ::Gitlab::Utils::Override
extend ActiveSupport::Concern extend ActiveSupport::Concern
Attribute = Struct.new(:name, :type)
EE_KNOWN_KEYS = [ EE_KNOWN_KEYS = [
:subscription_plan :subscription_plan,
:ai_resource
].freeze
EE_APPLICATION_ATTRIBUTES = [
Attribute.new(:ai_resource, ::GlobalID)
].freeze ].freeze
class_methods do class_methods do
...@@ -17,11 +24,18 @@ module ApplicationContext ...@@ -17,11 +24,18 @@ module ApplicationContext
def known_keys def known_keys
super + EE_KNOWN_KEYS super + EE_KNOWN_KEYS
end end
override :application_attributes
def application_attributes
super + EE_APPLICATION_ATTRIBUTES
end
end end
override :to_lazy_hash override :to_lazy_hash
def to_lazy_hash def to_lazy_hash
super.tap do |hash| super.tap do |hash|
assign_hash_if_value(hash, :ai_resource)
hash[:subscription_plan] = -> { subcription_plan_name } if include_namespace? hash[:subscription_plan] = -> { subcription_plan_name } if include_namespace?
end end
end end
......
...@@ -50,6 +50,7 @@ def result(context) ...@@ -50,6 +50,7 @@ def result(context)
[:remote_ip] | [:remote_ip, :client_id] [:remote_ip] | [:remote_ip, :client_id]
[:runner] | [:project, :root_namespace, :client_id, :subscription_plan] [:runner] | [:project, :root_namespace, :client_id, :subscription_plan]
[:caller_id] | [:caller_id] [:caller_id] | [:caller_id]
[:ai_resource] | [:ai_resource]
[] | [] [] | []
end end
......
...@@ -115,12 +115,6 @@ def get_show ...@@ -115,12 +115,6 @@ def get_show
end end
end end
end end
it 'assigns ai_resource_id' do
get_show
expect(assigns(:ai_resource_id)).to eq(issue.to_global_id)
end
end end
describe 'GET #index' do describe 'GET #index' do
......
...@@ -47,11 +47,16 @@ class ApplicationContext ...@@ -47,11 +47,16 @@ class ApplicationContext
Attribute.new(:root_caller_id, String), Attribute.new(:root_caller_id, String),
Attribute.new(:merge_action_status, String) Attribute.new(:merge_action_status, String)
].freeze ].freeze
private_constant :APPLICATION_ATTRIBUTES
def self.known_keys def self.known_keys
KNOWN_KEYS KNOWN_KEYS
end end
def self.application_attributes
APPLICATION_ATTRIBUTES
end
def self.with_context(args, &block) def self.with_context(args, &block)
application_context = new(**args) application_context = new(**args)
application_context.use(&block) application_context.use(&block)
...@@ -79,12 +84,13 @@ def self.current_context_attribute(attribute_name) ...@@ -79,12 +84,13 @@ def self.current_context_attribute(attribute_name)
end end
def initialize(**args) def initialize(**args)
unknown_attributes = args.keys - APPLICATION_ATTRIBUTES.map(&:name) unknown_attributes = args.keys - self.class.application_attributes.map(&:name)
raise ArgumentError, "#{unknown_attributes} are not known keys" if unknown_attributes.any? raise ArgumentError, "#{unknown_attributes} are not known keys" if unknown_attributes.any?
@set_values = args.keys @set_values = args.keys
assign_attributes(args) assign_attributes(args)
set_attr_readers
end end
# rubocop: disable Metrics/CyclomaticComplexity # rubocop: disable Metrics/CyclomaticComplexity
...@@ -122,12 +128,14 @@ def use ...@@ -122,12 +128,14 @@ def use
attr_reader :set_values attr_reader :set_values
APPLICATION_ATTRIBUTES.each do |attr| def set_attr_readers
lazy_attr_reader attr.name, type: attr.type self.class.application_attributes.each do |attr|
self.class.lazy_attr_reader attr.name, type: attr.type
end
end end
def assign_hash_if_value(hash, attribute_name) def assign_hash_if_value(hash, attribute_name)
unless KNOWN_KEYS.include?(attribute_name) unless self.class.known_keys.include?(attribute_name)
raise ArgumentError, "unknown attribute `#{attribute_name}`" raise ArgumentError, "unknown attribute `#{attribute_name}`"
end end
...@@ -137,7 +145,7 @@ def assign_hash_if_value(hash, attribute_name) ...@@ -137,7 +145,7 @@ def assign_hash_if_value(hash, attribute_name)
end end
def assign_attributes(values) def assign_attributes(values)
values.slice(*APPLICATION_ATTRIBUTES.map(&:name)).each do |name, value| values.slice(*self.class.application_attributes.map(&:name)).each do |name, value|
instance_variable_set("@#{name}", value) instance_variable_set("@#{name}", value)
end end
end end
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册