From 56e1e889c5ae76e6acad2dbcc32a1f4899366852 Mon Sep 17 00:00:00 2001 From: nrosandich Date: Tue, 8 Apr 2025 10:37:32 +1200 Subject: [PATCH 1/2] Add user_profile_visibility_updated audit event Changelog: added EE: true --- doc/user/compliance/audit_event_types.md | 3 +- .../types/user_profile_visibility_updated.yml | 10 +++++ .../types/user_profile_visiblity_updated.yml | 2 +- ee/lib/users/user_setting_changes_auditor.rb | 8 ++++ .../user_setting_changes_auditor_spec.rb | 41 +++++++++++++------ 5 files changed, 50 insertions(+), 14 deletions(-) create mode 100644 ee/config/audit_events/types/user_profile_visibility_updated.yml diff --git a/doc/user/compliance/audit_event_types.md b/doc/user/compliance/audit_event_types.md index 487e48a8186586..a9fc38c3b83722 100644 --- a/doc/user/compliance/audit_event_types.md +++ b/doc/user/compliance/audit_event_types.md @@ -673,7 +673,8 @@ Audit event types belong to the following product categories. | [`user_auditor_status_updated`](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/136456) | A user is either made an auditor or removed as an auditor | {{< icon name="check-circle" >}} Yes | GitLab [16.6](https://gitlab.com/gitlab-org/gitlab/-/issues/430235) | User | | [`user_email_address_updated`](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/2103) | A user updates their email address | {{< icon name="check-circle" >}} Yes | GitLab [10.1](https://gitlab.com/gitlab-org/gitlab-ee/issues/1370) | User | | [`user_name_updated`](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/167484) | A user's name is updated | {{< icon name="check-circle" >}} Yes | GitLab [17.5](https://gitlab.com/gitlab-org/gitlab/-/issues/486532) | User | -| [`user_profile_visiblity_updated`](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/129149) | User toggles private profile user setting | {{< icon name="dotted-circle" >}} No | GitLab [16.3](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/129149) | User | +| [`user_profile_visibility_updated`](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/187207) | User toggles private profile user setting | {{< icon name="dotted-circle" >}} No | GitLab [17.11](https://gitlab.com/gitlab-org/gitlab/-/issues/474386) | User | +| [`user_profile_visiblity_updated`](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/129149) | User toggles private profile user setting (DEPRECATED) | {{< icon name="dotted-circle" >}} No | GitLab [16.3](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/129149) | User | | [`user_username_updated`](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/106086) | A user's username is updated | {{< icon name="check-circle" >}} Yes | GitLab [15.7](https://gitlab.com/gitlab-org/gitlab/-/issues/369329) | User | ### Value stream management diff --git a/ee/config/audit_events/types/user_profile_visibility_updated.yml b/ee/config/audit_events/types/user_profile_visibility_updated.yml new file mode 100644 index 00000000000000..c8999204353241 --- /dev/null +++ b/ee/config/audit_events/types/user_profile_visibility_updated.yml @@ -0,0 +1,10 @@ +--- +name: user_profile_visibility_updated +description: User toggles private profile user setting +introduced_by_issue: https://gitlab.com/gitlab-org/gitlab/-/issues/474386 +introduced_by_mr: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/187207 +feature_category: user_profile +milestone: '17.11' +saved_to_database: false +streamed: true +scope: [User] diff --git a/ee/config/audit_events/types/user_profile_visiblity_updated.yml b/ee/config/audit_events/types/user_profile_visiblity_updated.yml index 495c0914f986ff..65ed1df48afa18 100644 --- a/ee/config/audit_events/types/user_profile_visiblity_updated.yml +++ b/ee/config/audit_events/types/user_profile_visiblity_updated.yml @@ -1,6 +1,6 @@ --- name: user_profile_visiblity_updated -description: User toggles private profile user setting +description: User toggles private profile user setting (DEPRECATED) introduced_by_issue: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/129149 introduced_by_mr: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/129149 feature_category: user_profile diff --git a/ee/lib/users/user_setting_changes_auditor.rb b/ee/lib/users/user_setting_changes_auditor.rb index f5b1c6473821cf..d8277fe2c73258 100644 --- a/ee/lib/users/user_setting_changes_auditor.rb +++ b/ee/lib/users/user_setting_changes_auditor.rb @@ -16,6 +16,14 @@ def execute model: model, event_type: 'user_profile_visiblity_updated' ) + + audit_changes( + :private_profile, + as: 'user_profile_visibility', + entity: @current_user, + model: model, + event_type: 'user_profile_visibility_updated' + ) end private diff --git a/ee/spec/lib/users/user_setting_changes_auditor_spec.rb b/ee/spec/lib/users/user_setting_changes_auditor_spec.rb index 90fc66da8dbe2b..fd43ad9d44f891 100644 --- a/ee/spec/lib/users/user_setting_changes_auditor_spec.rb +++ b/ee/spec/lib/users/user_setting_changes_auditor_spec.rb @@ -14,34 +14,51 @@ end context 'when user setting is updated' do - where(:column, :change, :event, :change_from, :change_to) do - 'private_profile' | 'user_profile_visiblity' | 'user_profile_visiblity_updated' | true | false - 'private_profile' | 'user_profile_visiblity' | 'user_profile_visiblity_updated' | false | true + where(:column, :changes, :events) do + 'private_profile' | [{ change: 'user_profile_visiblity', event_type: 'user_profile_visiblity_updated' }, + { change: 'user_profile_visibility', event_type: 'user_profile_visibility_updated' }] | + [true, false] end with_them do before do - user.update!(column.to_sym => change_from) + user.update!(column.to_sym => events.first) end - it 'calls auditor' do - user.update!(column.to_sym => change_to) + it 'calls auditor for both the legacy misspelled event and the new correctly spelled event' do + user.update!(column.to_sym => events.last) expect(Gitlab::Audit::Auditor).to receive(:audit).with( { - name: event, + name: changes.first[:event_type], author: user, scope: user, target: user, - message: "Changed #{change} from #{change_from} to #{change_to}", + message: "Changed #{changes.first[:change]} from #{events.first} to #{events.last}", additional_details: { - change: change.to_s, - from: change_from, - to: change_to + change: changes.first[:change].to_s, + from: events.first, + to: events.last }, target_details: nil } - ).and_call_original + ).ordered.and_call_original + + expect(Gitlab::Audit::Auditor).to receive(:audit).with( + { + name: changes.last[:event_type], + author: user, + scope: user, + target: user, + message: "Changed #{changes.last[:change]} from #{events.first} to #{events.last}", + additional_details: { + change: changes.last[:change].to_s, + from: events.first, + to: events.last + }, + target_details: nil + } + ).ordered.and_call_original user_setting_changes_auditor.execute end -- GitLab From 1e89cf740fb8798cc012b76dda139aa20fe6951c Mon Sep 17 00:00:00 2001 From: nrosandich Date: Tue, 8 Apr 2025 15:12:00 +1200 Subject: [PATCH 2/2] Add new event to deprecated --- doc/user/compliance/audit_event_types.md | 2 +- ee/config/audit_events/types/user_profile_visiblity_updated.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/user/compliance/audit_event_types.md b/doc/user/compliance/audit_event_types.md index a9fc38c3b83722..7a46519900696c 100644 --- a/doc/user/compliance/audit_event_types.md +++ b/doc/user/compliance/audit_event_types.md @@ -674,7 +674,7 @@ Audit event types belong to the following product categories. | [`user_email_address_updated`](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/2103) | A user updates their email address | {{< icon name="check-circle" >}} Yes | GitLab [10.1](https://gitlab.com/gitlab-org/gitlab-ee/issues/1370) | User | | [`user_name_updated`](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/167484) | A user's name is updated | {{< icon name="check-circle" >}} Yes | GitLab [17.5](https://gitlab.com/gitlab-org/gitlab/-/issues/486532) | User | | [`user_profile_visibility_updated`](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/187207) | User toggles private profile user setting | {{< icon name="dotted-circle" >}} No | GitLab [17.11](https://gitlab.com/gitlab-org/gitlab/-/issues/474386) | User | -| [`user_profile_visiblity_updated`](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/129149) | User toggles private profile user setting (DEPRECATED) | {{< icon name="dotted-circle" >}} No | GitLab [16.3](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/129149) | User | +| [`user_profile_visiblity_updated`](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/129149) | User toggles private profile user setting (DEPRECATED). Use `user_profile_visibility_updated` instead. | {{< icon name="dotted-circle" >}} No | GitLab [16.3](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/129149) | User | | [`user_username_updated`](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/106086) | A user's username is updated | {{< icon name="check-circle" >}} Yes | GitLab [15.7](https://gitlab.com/gitlab-org/gitlab/-/issues/369329) | User | ### Value stream management diff --git a/ee/config/audit_events/types/user_profile_visiblity_updated.yml b/ee/config/audit_events/types/user_profile_visiblity_updated.yml index 65ed1df48afa18..66a64d0b550284 100644 --- a/ee/config/audit_events/types/user_profile_visiblity_updated.yml +++ b/ee/config/audit_events/types/user_profile_visiblity_updated.yml @@ -1,6 +1,6 @@ --- name: user_profile_visiblity_updated -description: User toggles private profile user setting (DEPRECATED) +description: User toggles private profile user setting (DEPRECATED). Use `user_profile_visibility_updated` instead. introduced_by_issue: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/129149 introduced_by_mr: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/129149 feature_category: user_profile -- GitLab