diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-01-20 12:16:11 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-01-20 12:16:11 +0300 |
commit | edaa33dee2ff2f7ea3fac488d41558eb5f86d68c (patch) | |
tree | 11f143effbfeba52329fb7afbd05e6e2a3790241 /app/controllers/concerns | |
parent | d8a5691316400a0f7ec4f83832698f1988eb27c1 (diff) |
Add latest changes from gitlab-org/gitlab@14-7-stable-eev14.7.0-rc42
Diffstat (limited to 'app/controllers/concerns')
5 files changed, 93 insertions, 1 deletions
diff --git a/app/controllers/concerns/access_tokens_actions.rb b/app/controllers/concerns/access_tokens_actions.rb new file mode 100644 index 00000000000..451841c43bb --- /dev/null +++ b/app/controllers/concerns/access_tokens_actions.rb @@ -0,0 +1,83 @@ +# frozen_string_literal: true + +module AccessTokensActions + extend ActiveSupport::Concern + + included do + before_action -> { check_permission(:read_resource_access_tokens) }, only: [:index] + before_action -> { check_permission(:destroy_resource_access_tokens) }, only: [:revoke] + before_action -> { check_permission(:create_resource_access_tokens) }, only: [:create] + end + + # rubocop:disable Gitlab/ModuleWithInstanceVariables + def index + @resource_access_token = PersonalAccessToken.new + set_index_vars + end + # rubocop:enable Gitlab/ModuleWithInstanceVariables + + # rubocop:disable Gitlab/ModuleWithInstanceVariables + def create + token_response = ResourceAccessTokens::CreateService.new(current_user, resource, create_params).execute + + if token_response.success? + @resource_access_token = token_response.payload[:access_token] + PersonalAccessToken.redis_store!(key_identity, @resource_access_token.token) + + redirect_to resource_access_tokens_path, notice: _("Your new access token has been created.") + else + redirect_to resource_access_tokens_path, alert: _("Failed to create new access token: %{token_response_message}") % { token_response_message: token_response.message } + end + end + # rubocop:enable Gitlab/ModuleWithInstanceVariables + + # rubocop:disable Gitlab/ModuleWithInstanceVariables + def revoke + @resource_access_token = finder.find(params[:id]) + revoked_response = ResourceAccessTokens::RevokeService.new(current_user, resource, @resource_access_token).execute + + if revoked_response.success? + flash[:notice] = _("Revoked access token %{access_token_name}!") % { access_token_name: @resource_access_token.name } + else + flash[:alert] = _("Could not revoke access token %{access_token_name}.") % { access_token_name: @resource_access_token.name } + end + + redirect_to resource_access_tokens_path + end + # rubocop:enable Gitlab/ModuleWithInstanceVariables + + private + + def check_permission(action) + render_404 unless can?(current_user, action, resource) + end + + def create_params + params.require(:resource_access_token).permit(:name, :expires_at, :access_level, scopes: []) + end + + # rubocop:disable Gitlab/ModuleWithInstanceVariables + def set_index_vars + # Loading resource members so that we can fetch access level of the bot + # user in the resource without multiple queries. + resource.members.load + + @scopes = Gitlab::Auth.resource_bot_scopes + @active_resource_access_tokens = finder(state: 'active').execute.preload_users + @inactive_resource_access_tokens = finder(state: 'inactive', sort: 'expires_at_asc').execute.preload_users + @new_resource_access_token = PersonalAccessToken.redis_getdel(key_identity) + end + # rubocop:enable Gitlab/ModuleWithInstanceVariables + + def finder(options = {}) + PersonalAccessTokensFinder.new({ user: bot_users, impersonation: false }.merge(options)) + end + + def bot_users + resource.bots + end + + def key_identity + "#{current_user.id}:#{resource.id}" + end +end diff --git a/app/controllers/concerns/check_rate_limit.rb b/app/controllers/concerns/check_rate_limit.rb index 5ccdf843525..0eaf74fd3a9 100644 --- a/app/controllers/concerns/check_rate_limit.rb +++ b/app/controllers/concerns/check_rate_limit.rb @@ -8,6 +8,7 @@ # See lib/api/helpers/rate_limiter.rb for API version module CheckRateLimit def check_rate_limit!(key, scope:, redirect_back: false, **options) + return if bypass_header_set? return unless rate_limiter.throttled?(key, scope: scope, **options) rate_limiter.log_request(request, "#{key}_request_limit".to_sym, current_user) @@ -28,4 +29,8 @@ module CheckRateLimit def rate_limiter ::Gitlab::ApplicationRateLimiter end + + def bypass_header_set? + ::Gitlab::Throttle.bypass_header.present? && request.get_header(Gitlab::Throttle.bypass_header) == '1' + end end diff --git a/app/controllers/concerns/integrations/actions.rb b/app/controllers/concerns/integrations/actions.rb index 1f788860c8f..f6e98c25b72 100644 --- a/app/controllers/concerns/integrations/actions.rb +++ b/app/controllers/concerns/integrations/actions.rb @@ -8,6 +8,9 @@ module Integrations::Actions include IntegrationsHelper before_action :integration, only: [:edit, :update, :overrides, :test] + before_action do + push_frontend_feature_flag(:vue_integration_form, current_user, default_enabled: :yaml) + end urgency :low, [:test] end diff --git a/app/controllers/concerns/integrations/params.rb b/app/controllers/concerns/integrations/params.rb index 201fb1dc83f..945540d1f8c 100644 --- a/app/controllers/concerns/integrations/params.rb +++ b/app/controllers/concerns/integrations/params.rb @@ -11,6 +11,7 @@ module Integrations :api_key, :api_token, :api_url, + :archive_trace_events, :bamboo_url, :branches_to_be_notified, :labels_to_be_notified, diff --git a/app/controllers/concerns/sessionless_authentication.rb b/app/controllers/concerns/sessionless_authentication.rb index c6d926c8a8d..1f17f9f4e1b 100644 --- a/app/controllers/concerns/sessionless_authentication.rb +++ b/app/controllers/concerns/sessionless_authentication.rb @@ -20,7 +20,7 @@ module SessionlessAuthentication end def sessionless_sign_in(user) - if can?(user, :log_in) && !user.password_expired_if_applicable? + if user.can_log_in_with_non_expired_password? # Notice we are passing store false, so the user is not # actually stored in the session and a token is needed # for every request. If you want the token to work as a |