diff --git a/.rubocop_todo/rspec/factory_bot/avoid_create.yml b/.rubocop_todo/rspec/factory_bot/avoid_create.yml index d36df0b01de8b3db61e0070f8a72667221d4993c..88d2255f68117ec0da1b0443fa42671c97eefeac 100644 --- a/.rubocop_todo/rspec/factory_bot/avoid_create.yml +++ b/.rubocop_todo/rspec/factory_bot/avoid_create.yml @@ -583,7 +583,7 @@ RSpec/FactoryBot/AvoidCreate: - 'spec/views/notify/import_issues_csv_email.html.haml_spec.rb' - 'spec/views/notify/pipeline_failed_email.text.erb_spec.rb' - 'spec/views/notify/push_to_merge_request_email.text.haml_spec.rb' - - 'spec/views/profiles/audit_log.html.haml_spec.rb' + - 'spec/views/user_settings/user_settings/authentication_log.html.haml_spec.rb' - 'spec/views/profiles/keys/_key.html.haml_spec.rb' - 'spec/views/profiles/keys/_key_details.html.haml_spec.rb' - 'spec/views/profiles/notifications/show.html.haml_spec.rb' diff --git a/app/controllers/profiles_controller.rb b/app/controllers/profiles_controller.rb index cb29f0f35392ca023583d563e80789208244696b..e427f60718623a09a1565719edc4e454dce79b1e 100644 --- a/app/controllers/profiles_controller.rb +++ b/app/controllers/profiles_controller.rb @@ -14,7 +14,6 @@ class ProfilesController < Profiles::ApplicationController feature_category :user_profile, [:show, :update, :reset_incoming_email_token, :reset_feed_token, :reset_static_object_token, :update_username] - feature_category :system_access, [:audit_log] urgency :low, [:show, :update] def show @@ -65,16 +64,6 @@ def reset_static_object_token notice: s_('Profiles|Static object token was successfully reset') end - # rubocop: disable CodeReuse/ActiveRecord - def audit_log - @events = AuthenticationEvent.where(user: current_user) - .order("created_at DESC") - .page(params[:page]) - - Gitlab::Tracking.event(self.class.name, 'search_audit_event', user: current_user) - end - # rubocop: enable CodeReuse/ActiveRecord - def update_username result = Users::UpdateService.new(current_user, user: @user, username: username_param).execute diff --git a/app/controllers/user_settings/user_settings_controller.rb b/app/controllers/user_settings/user_settings_controller.rb new file mode 100644 index 0000000000000000000000000000000000000000..3d69a9c2fd6ac66a1a8fe3bcbec4c65c46074396 --- /dev/null +++ b/app/controllers/user_settings/user_settings_controller.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +module UserSettings + class UserSettingsController < ApplicationController + layout 'profile' + feature_category :system_access + + def authentication_log + @events = AuthenticationEvent.for_user(current_user) + .order_by_created_at_desc + .page(params[:page]) + + Gitlab::Tracking.event(self.class.name, 'search_audit_event', user: current_user) + end + end +end diff --git a/app/models/authentication_event.rb b/app/models/authentication_event.rb index e9fe49f980d62e75e1a8a7a3e405e1595f1b80cd..e3a5922efd193cf715025a92bc3c4dab48fc7058 100644 --- a/app/models/authentication_event.rb +++ b/app/models/authentication_event.rb @@ -21,6 +21,8 @@ class AuthenticationEvent < MainClusterwide::ApplicationRecord scope :for_provider, ->(provider) { where(provider: provider) } scope :ldap, -> { where('provider LIKE ?', 'ldap%') } + scope :for_user, ->(user) { where(user: user) } + scope :order_by_created_at_desc, -> { reorder(created_at: :desc) } def self.providers STATIC_PROVIDERS | Devise.omniauth_providers.map(&:to_s) diff --git a/app/views/profiles/_event_table.html.haml b/app/views/user_settings/user_settings/_event_table.haml similarity index 100% rename from app/views/profiles/_event_table.html.haml rename to app/views/user_settings/user_settings/_event_table.haml diff --git a/app/views/profiles/audit_log.html.haml b/app/views/user_settings/user_settings/authentication_log.haml similarity index 100% rename from app/views/profiles/audit_log.html.haml rename to app/views/user_settings/user_settings/authentication_log.haml diff --git a/config/routes.rb b/config/routes.rb index cd0bd686cb2873bdc1e175fead479b077b63f767..babc1ffa3d3e97e1b4edd1fd1b0f781820f90111 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -210,6 +210,7 @@ draw :snippets draw :profile + draw :user_settings post '/mailgun/webhooks' => 'mailgun/webhooks#process_webhook' diff --git a/config/routes/profile.rb b/config/routes/profile.rb index 73c8d63b8ec1bb1949f6a56e5a8437019a55fcd3..b4f00fa4ad826a6dcb4e2d93de253ecc7f9f2e76 100644 --- a/config/routes/profile.rb +++ b/config/routes/profile.rb @@ -5,7 +5,7 @@ resource :profile, only: [:show, :update] do member do - get :audit_log + get :audit_log, to: redirect('-/user_settings/authentication_log') get :applications, to: 'oauth/applications#index' put :reset_incoming_email_token diff --git a/config/routes/user_settings.rb b/config/routes/user_settings.rb new file mode 100644 index 0000000000000000000000000000000000000000..478d807c8b581d035428caaaf1a38f4d443d1f89 --- /dev/null +++ b/config/routes/user_settings.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +scope module: 'user_settings' do + namespace :user_settings do + get :authentication_log + end +end diff --git a/lib/sidebars/user_settings/menus/authentication_log_menu.rb b/lib/sidebars/user_settings/menus/authentication_log_menu.rb index c5a27acf1fd869c61e611ca37f8a7957e21861ff..fc4b0bba9c382e50237df218733b4bf51de36e7e 100644 --- a/lib/sidebars/user_settings/menus/authentication_log_menu.rb +++ b/lib/sidebars/user_settings/menus/authentication_log_menu.rb @@ -8,7 +8,7 @@ class AuthenticationLogMenu < ::Sidebars::Menu override :link def link - audit_log_profile_path + user_settings_authentication_log_path end override :title @@ -23,7 +23,7 @@ def sprite_icon override :active_routes def active_routes - { path: 'profiles#audit_log' } + { path: 'user_settings#authentication_log' } end end end diff --git a/spec/controllers/profiles_controller_spec.rb b/spec/controllers/profiles_controller_spec.rb index 4f350ddf1ef4da4a3d452e4531747f19a3eda8f3..26144edb67046cbbd99b52947af6e3cff4bd77da 100644 --- a/spec/controllers/profiles_controller_spec.rb +++ b/spec/controllers/profiles_controller_spec.rb @@ -140,30 +140,6 @@ end end - describe 'GET audit_log' do - let(:auth_event) { create(:authentication_event, user: user) } - - it 'tracks search event', :snowplow do - sign_in(user) - - get :audit_log - - expect_snowplow_event( - category: 'ProfilesController', - action: 'search_audit_event', - user: user - ) - end - - it 'loads page correctly' do - sign_in(user) - - get :audit_log - - expect(response).to have_gitlab_http_status(:success) - end - end - describe 'PUT update_username' do let(:namespace) { user.namespace } let(:gitlab_shell) { Gitlab::Shell.new } diff --git a/spec/features/user_sees_active_nav_items_spec.rb b/spec/features/user_sees_active_nav_items_spec.rb index 966b84913743833486abe1e4f39b2e75d78555fe..1e6b2b8f189c6b0cb2747c83359f64d3b9f82579 100644 --- a/spec/features/user_sees_active_nav_items_spec.rb +++ b/spec/features/user_sees_active_nav_items_spec.rb @@ -32,7 +32,7 @@ context 'when visiting authentication logs' do before do - visit audit_log_profile_path + visit user_settings_authentication_log_path end it 'renders the side navigation with the correct submenu set as active' do diff --git a/spec/lib/sidebars/user_settings/menus/authentication_log_menu_spec.rb b/spec/lib/sidebars/user_settings/menus/authentication_log_menu_spec.rb index 33be5050c377ab362a2700e6f7e1d777e269f56d..5a154d7dafb2ce3be98d10ebf6765df077f057f0 100644 --- a/spec/lib/sidebars/user_settings/menus/authentication_log_menu_spec.rb +++ b/spec/lib/sidebars/user_settings/menus/authentication_log_menu_spec.rb @@ -4,10 +4,10 @@ RSpec.describe Sidebars::UserSettings::Menus::AuthenticationLogMenu, feature_category: :navigation do it_behaves_like 'User settings menu', - link: '/-/profile/audit_log', + link: '/-/user_settings/authentication_log', title: _('Authentication Log'), icon: 'log', - active_routes: { path: 'profiles#audit_log' } + active_routes: { path: 'user_settings#authentication_log' } it_behaves_like 'User settings menu #render? method' end diff --git a/spec/requests/legacy_routes_spec.rb b/spec/requests/legacy_routes_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..65af3c78fd723c59d0a2ceeed02ba1939c0826d7 --- /dev/null +++ b/spec/requests/legacy_routes_spec.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe "Legacy routes", type: :request, feature_category: :system_access do + let(:user) { create(:user) } + + before do + login_as(user) + end + + it "/-/profile/audit_log" do + get "/-/profile/audit_log" + expect(response).to redirect_to('/-/user_settings/authentication_log') + end +end diff --git a/spec/requests/user_settings_spec.rb b/spec/requests/user_settings_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..8298edc9ad0030161c316e2d8eea4a6caf055533 --- /dev/null +++ b/spec/requests/user_settings_spec.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe "UserSettings", type: :request, feature_category: :system_access do + let(:user) { create(:user) } + + describe 'GET authentication_log' do + let(:auth_event) { create(:authentication_event, user: user) } + + it 'tracks search event', :snowplow do + sign_in(user) + + get '/-/user_settings/authentication_log' + + expect_snowplow_event( + category: 'UserSettings::UserSettingsController', + action: 'search_audit_event', + user: user + ) + end + + it 'loads page correctly' do + sign_in(user) + + get '/-/user_settings/authentication_log' + + expect(response).to have_gitlab_http_status(:success) + end + end +end diff --git a/spec/routing/routing_spec.rb b/spec/routing/routing_spec.rb index 7c4f040266ed81ccd56f866a548682b807f0a2cd..1bd138ea1488ec30f632f78021ed3bef8e36a0ef 100644 --- a/spec/routing/routing_spec.rb +++ b/spec/routing/routing_spec.rb @@ -131,10 +131,6 @@ expect(get("/-/profile/account")).to route_to('profiles/accounts#show') end - it "to #audit_log" do - expect(get("/-/profile/audit_log")).to route_to('profiles#audit_log') - end - it "to #reset_feed_token" do expect(put("/-/profile/reset_feed_token")).to route_to('profiles#reset_feed_token') end @@ -397,3 +393,11 @@ expect(get('/-/jwks')).to route_to('jwks#index') end end + +# user_settings_authentication_log GET /-/user_settings/authentication_log(.:format) system_access/user_settings#authentication_log + +RSpec.describe UserSettings::UserSettingsController, 'routing', feature_category: :system_access do + it 'to #authentication_log' do + expect(get('/-/user_settings/authentication_log')).to route_to('user_settings/user_settings#authentication_log') + end +end diff --git a/spec/views/profiles/audit_log.html.haml_spec.rb b/spec/views/user_settings/user_settings/authentication_log.html.haml_spec.rb similarity index 85% rename from spec/views/profiles/audit_log.html.haml_spec.rb rename to spec/views/user_settings/user_settings/authentication_log.html.haml_spec.rb index d5f6a2d64e78e77c0786a79594121f3f274bba5b..4188bdc587f402105c854ae9036e92e4bf47efa5 100644 --- a/spec/views/profiles/audit_log.html.haml_spec.rb +++ b/spec/views/user_settings/user_settings/authentication_log.html.haml_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe 'profiles/audit_log' do +RSpec.describe 'user_settings/user_settings/authentication_log', feature_category: :system_access do let(:user) { create(:user) } before do