Commit ca3da647 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch '345388-add-last-activity-column-to-csv-export-in-admin-users' into 'master'

Resolve "Add "Last Activity" column to CSV export in /admin/users"

See merge request gitlab-org/gitlab!75652
parents 37cf5ab6 c95987e5
...@@ -25,7 +25,7 @@ class Member < ApplicationRecord ...@@ -25,7 +25,7 @@ class Member < ApplicationRecord
belongs_to :source, polymorphic: true # rubocop:disable Cop/PolymorphicAssociations belongs_to :source, polymorphic: true # rubocop:disable Cop/PolymorphicAssociations
has_one :member_task has_one :member_task
delegate :name, :username, :email, to: :user, prefix: true delegate :name, :username, :email, :last_activity_on, to: :user, prefix: true
delegate :tasks_to_be_done, to: :member_task, allow_nil: true delegate :tasks_to_be_done, to: :member_task, allow_nil: true
validates :expires_at, allow_blank: true, future_date: true validates :expires_at, allow_blank: true, future_date: true
......
...@@ -199,6 +199,7 @@ The following data is included in the export: ...@@ -199,6 +199,7 @@ The following data is included in the export:
- Type - Type
- Path - Path
- Access level ([Project](../permissions.md#project-members-permissions) and [Group](../permissions.md#group-members-permissions)) - Access level ([Project](../permissions.md#project-members-permissions) and [Group](../permissions.md#group-members-permissions))
- Date of last activity ([introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/345388) in GitLab 14.6). For a list of activities that populate this column, see the [Users API documentation](../../api/users.md#get-user-activities-admin-only).
![user permission export button](img/export_permissions_v13_11.png) ![user permission export button](img/export_permissions_v13_11.png)
......
...@@ -36,7 +36,8 @@ module UserPermissions ...@@ -36,7 +36,8 @@ module UserPermissions
'Email' => 'user_email', 'Email' => 'user_email',
'Type' => 'source_kind', 'Type' => 'source_kind',
'Path' => -> (member) { member.source&.full_path }, 'Path' => -> (member) { member.source&.full_path },
'Access Level' => 'human_access' 'Access Level' => 'human_access',
'Last Activity' => 'user_last_activity_on'
} }
end end
end end
......
...@@ -24,9 +24,9 @@ RSpec.describe Admin::UserPermissionExportsController do ...@@ -24,9 +24,9 @@ RSpec.describe Admin::UserPermissionExportsController do
context 'when successful' do context 'when successful' do
let(:csv_data) do let(:csv_data) do
<<~CSV <<~CSV
Username,Email,Type,Path,Access Username,Email,Type,Path,Access,Last Activity
alvina,alvina@test.com,Group,gitlab-org,Developer alvina,alvina@test.com,Group,gitlab-org,Developer,2020-12-18
jasper,jasper@test.com,Project,gitlab-org/www,Maintainer jasper,jasper@test.com,Project,gitlab-org/www,Maintainer,2020-12-16
CSV CSV
end end
...@@ -51,19 +51,21 @@ RSpec.describe Admin::UserPermissionExportsController do ...@@ -51,19 +51,21 @@ RSpec.describe Admin::UserPermissionExportsController do
subject subject
expect(csv_response).to eq([ expect(csv_response).to eq([
%w( [
Username 'Username',
Email 'Email',
Type 'Type',
Path 'Path',
Access 'Access',
), 'Last Activity'
],
%w( %w(
alvina alvina
alvina@test.com alvina@test.com
Group Group
gitlab-org gitlab-org
Developer Developer
2020-12-18
), ),
%w( %w(
jasper jasper
...@@ -71,6 +73,7 @@ RSpec.describe Admin::UserPermissionExportsController do ...@@ -71,6 +73,7 @@ RSpec.describe Admin::UserPermissionExportsController do
Project Project
gitlab-org/www gitlab-org/www
Maintainer Maintainer
2020-12-16
) )
]) ])
end end
......
...@@ -6,7 +6,7 @@ RSpec.describe UserPermissions::ExportService do ...@@ -6,7 +6,7 @@ RSpec.describe UserPermissions::ExportService do
let(:service) { described_class.new(current_user) } let(:service) { described_class.new(current_user) }
let_it_be(:admin) { create(:admin) } let_it_be(:admin) { create(:admin) }
let_it_be(:user) { create(:user, username: 'Jessica', email: 'jessica@test.com') } let_it_be(:user) { create(:user, username: 'Jessica', email: 'jessica@test.com', last_activity_on: Date.new(2020, 12, 16)) }
context 'access' do context 'access' do
shared_examples 'allowed to export user permissions' do shared_examples 'allowed to export user permissions' do
...@@ -67,7 +67,7 @@ RSpec.describe UserPermissions::ExportService do ...@@ -67,7 +67,7 @@ RSpec.describe UserPermissions::ExportService do
it 'includes the appropriate headers' do it 'includes the appropriate headers' do
expect(csv.headers).to eq([ expect(csv.headers).to eq([
'Username', 'Email', 'Type', 'Path', 'Access Level' 'Username', 'Email', 'Type', 'Path', 'Access Level', 'Last Activity'
]) ])
end end
...@@ -91,9 +91,13 @@ RSpec.describe UserPermissions::ExportService do ...@@ -91,9 +91,13 @@ RSpec.describe UserPermissions::ExportService do
expect(csv[0]['Access Level']).to eq('Owner') expect(csv[0]['Access Level']).to eq('Owner')
end end
specify 'Last Activity' do
expect(csv[0]['Last Activity']).to eq('2020-12-16')
end
context 'when user is member of a sub group' do context 'when user is member of a sub group' do
let_it_be(:sub_group) { create(:group, parent: group) } let_it_be(:sub_group) { create(:group, parent: group) }
let_it_be(:sub_group_user) { create(:user, username: 'Oliver', email: 'oliver@test.com') } let_it_be(:sub_group_user) { create(:user, username: 'Oliver', email: 'oliver@test.com', last_activity_on: Date.new(2020, 12, 18)) }
let_it_be(:sub_group_maintainer) { create(:group_member, :maintainer, group: sub_group, user: sub_group_user) } let_it_be(:sub_group_maintainer) { create(:group_member, :maintainer, group: sub_group, user: sub_group_user) }
it 'displays attributes correctly', :aggregate_failures do it 'displays attributes correctly', :aggregate_failures do
...@@ -102,12 +106,13 @@ RSpec.describe UserPermissions::ExportService do ...@@ -102,12 +106,13 @@ RSpec.describe UserPermissions::ExportService do
expect(row['Path']).to eq(sub_group.full_path) expect(row['Path']).to eq(sub_group.full_path)
expect(row['Type']).to eq('Sub group') expect(row['Type']).to eq('Sub group')
expect(row['Access Level']).to eq('Maintainer') expect(row['Access Level']).to eq('Maintainer')
expect(row['Last Activity']).to eq('2020-12-18')
end end
end end
context 'when user is member of a project' do context 'when user is member of a project' do
let_it_be(:project) { create(:project, namespace: group) } let_it_be(:project) { create(:project, namespace: group) }
let_it_be(:project_user) { create(:user, username: 'Theo', email: 'theo@test.com') } let_it_be(:project_user) { create(:user, username: 'Theo', email: 'theo@test.com', last_activity_on: nil) }
let_it_be(:project_developer) { create(:project_member, :developer, project: project, user: project_user) } let_it_be(:project_developer) { create(:project_member, :developer, project: project, user: project_user) }
it 'displays attributes correctly', :aggregate_failures do it 'displays attributes correctly', :aggregate_failures do
...@@ -116,6 +121,7 @@ RSpec.describe UserPermissions::ExportService do ...@@ -116,6 +121,7 @@ RSpec.describe UserPermissions::ExportService do
expect(row['Path']).to eq(project.full_path) expect(row['Path']).to eq(project.full_path)
expect(row['Type']).to eq('Project') expect(row['Type']).to eq('Project')
expect(row['Access Level']).to eq('Developer') expect(row['Access Level']).to eq('Developer')
expect(row['Last Activity']).to be_nil
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment