Commit a8f2cde1 authored by Jose Ivan Vargas's avatar Jose Ivan Vargas

Merge branch '250843-check-usage-of-app-views-shared-members-update-js-haml' into 'master'

Remove legacy `shared/members/update.js.haml` in favor of vanilla JS

See merge request gitlab-org/gitlab!44048
parents 00567127 fd79b3dc
...@@ -77,13 +77,19 @@ export default class Members { ...@@ -77,13 +77,19 @@ export default class Members {
$expiresInText.text(sprintf(__('Expires in %{expires_at}'), { expires_at: expiresIn })); $expiresInText.text(sprintf(__('Expires in %{expires_at}'), { expires_at: expiresIn }));
const { expires_soon: expiresSoon } = data; const { expires_soon: expiresSoon, expires_at_formatted: expiresAtFormatted } = data;
if (expiresSoon) { if (expiresSoon) {
$expiresInText.addClass('text-warning'); $expiresInText.addClass('text-warning');
} else { } else {
$expiresInText.removeClass('text-warning'); $expiresInText.removeClass('text-warning');
} }
// Update tooltip
if (expiresAtFormatted) {
$expiresInText.attr('title', expiresAtFormatted);
$expiresInText.attr('data-original-title', expiresAtFormatted);
}
} else { } else {
$expiresIn.addClass('gl-display-none'); $expiresIn.addClass('gl-display-none');
} }
......
...@@ -22,10 +22,14 @@ module MembershipActions ...@@ -22,10 +22,14 @@ module MembershipActions
.new(current_user, update_params) .new(current_user, update_params)
.execute(member) .execute(member)
member = present_members([member]).first if member.expires?
render json: {
respond_to do |format| expires_in: helpers.distance_of_time_in_words_to_now(member.expires_at),
format.js { render 'shared/members/update', locals: { member: member } } expires_soon: member.expires_soon?,
expires_at_formatted: member.expires_at.to_time.in_time_zone.to_s(:medium)
}
else
render json: {}
end end
end end
......
...@@ -40,10 +40,11 @@ ...@@ -40,10 +40,11 @@
= _("Requested %{time_ago}").html_safe % { time_ago: time_ago_with_tooltip(member.requested_at) } = _("Requested %{time_ago}").html_safe % { time_ago: time_ago_with_tooltip(member.requested_at) }
- else - else
= _("Given access %{time_ago}").html_safe % { time_ago: time_ago_with_tooltip(member.created_at) } = _("Given access %{time_ago}").html_safe % { time_ago: time_ago_with_tooltip(member.created_at) }
- if member.expires? %span.js-expires-in{ class: ('gl-display-none' unless member.expires?) }
· ·
%span{ class: "#{"text-warning" if member.expires_soon?} has-tooltip", title: member.expires_at.to_time.in_time_zone.to_s(:medium) } %span.js-expires-in-text{ class: "has-tooltip#{' text-warning' if member.expires_soon?}", title: (member.expires_at.to_time.in_time_zone.to_s(:medium) if member.expires?) }
= _("Expires in %{expires_at}").html_safe % { expires_at: distance_of_time_in_words_to_now(member.expires_at) } - if member.expires?
= _("Expires in %{expires_at}").html_safe % { expires_at: distance_of_time_in_words_to_now(member.expires_at) }
- else - else
= image_tag avatar_icon_for_email(member.invite_email, 40), class: "avatar s40 flex-shrink-0 flex-grow-0", alt: '' = image_tag avatar_icon_for_email(member.invite_email, 40), class: "avatar s40 flex-shrink-0 flex-grow-0", alt: ''
......
- member = local_assigns.fetch(:member)
:plain
var $listItem = $('#{escape_javascript(render('shared/members/member', member: member))}');
$("##{dom_id(member)} .list-item-name").replaceWith($listItem.find('.list-item-name'));
gl.utils.localTimeAgo($('.js-timeago'), $("##{dom_id(member)}"));
...@@ -233,6 +233,42 @@ RSpec.describe Groups::GroupMembersController do ...@@ -233,6 +233,42 @@ RSpec.describe Groups::GroupMembersController do
end end
end end
end end
context 'expiration date' do
let(:expiry_date) { 1.month.from_now.to_date }
before do
travel_to Time.now.utc.beginning_of_day
put(
:update,
params: {
group_member: { expires_at: expiry_date },
group_id: group,
id: requester
},
format: :json
)
end
context 'when `expires_at` is set' do
it 'returns correct json response' do
expect(json_response).to eq({
"expires_in" => "about 1 month",
"expires_soon" => false,
"expires_at_formatted" => expiry_date.to_time.in_time_zone.to_s(:medium)
})
end
end
context 'when `expires_at` is not set' do
let(:expiry_date) { nil }
it 'returns empty json response' do
expect(json_response).to be_empty
end
end
end
end end
describe 'DELETE destroy' do describe 'DELETE destroy' do
...@@ -441,7 +477,7 @@ RSpec.describe Groups::GroupMembersController do ...@@ -441,7 +477,7 @@ RSpec.describe Groups::GroupMembersController do
group_id: group, group_id: group,
id: membership id: membership
}, },
format: :js format: :json
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
end end
......
...@@ -228,6 +228,43 @@ RSpec.describe Projects::ProjectMembersController do ...@@ -228,6 +228,43 @@ RSpec.describe Projects::ProjectMembersController do
end end
end end
end end
context 'expiration date' do
let(:expiry_date) { 1.month.from_now.to_date }
before do
travel_to Time.now.utc.beginning_of_day
put(
:update,
params: {
project_member: { expires_at: expiry_date },
namespace_id: project.namespace,
project_id: project,
id: requester
},
format: :json
)
end
context 'when `expires_at` is set' do
it 'returns correct json response' do
expect(json_response).to eq({
"expires_in" => "about 1 month",
"expires_soon" => false,
"expires_at_formatted" => expiry_date.to_time.in_time_zone.to_s(:medium)
})
end
end
context 'when `expires_at` is not set' do
let(:expiry_date) { nil }
it 'returns empty json response' do
expect(json_response).to be_empty
end
end
end
end end
describe 'DELETE destroy' do describe 'DELETE destroy' do
......
...@@ -6,65 +6,66 @@ RSpec.describe 'Groups > Members > Owner adds member with expiration date', :js ...@@ -6,65 +6,66 @@ RSpec.describe 'Groups > Members > Owner adds member with expiration date', :js
include Select2Helper include Select2Helper
include ActiveSupport::Testing::TimeHelpers include ActiveSupport::Testing::TimeHelpers
let(:user1) { create(:user, name: 'John Doe') } let_it_be(:user1) { create(:user, name: 'John Doe') }
let!(:new_member) { create(:user, name: 'Mary Jane') } let_it_be(:group) { create(:group) }
let(:group) { create(:group) } let(:new_member) { create(:user, name: 'Mary Jane') }
before do before do
stub_feature_flags(vue_group_members_list: false) stub_feature_flags(vue_group_members_list: false)
travel_to Time.now.utc.beginning_of_day
group.add_owner(user1) group.add_owner(user1)
sign_in(user1) sign_in(user1)
end end
it 'expiration date is displayed in the members list' do it 'expiration date is displayed in the members list' do
travel_to Time.zone.parse('2016-08-06 08:00') do visit group_group_members_path(group)
date = 4.days.from_now
visit group_group_members_path(group) page.within '.invite-users-form' do
select2(new_member.id, from: '#user_ids', multiple: true)
page.within '.invite-users-form' do
select2(new_member.id, from: '#user_ids', multiple: true) fill_in 'expires_at', with: 3.days.from_now.to_date
fill_in 'expires_at', with: date.to_s(:medium) + "\n" find_field('expires_at').native.send_keys :enter
click_on 'Invite'
end click_on 'Invite'
end
page.within "#group_member_#{group_member_id(new_member)}" do
expect(page).to have_content('Expires in 4 days') page.within "#group_member_#{group_member_id}" do
end expect(page).to have_content('Expires in 3 days')
end end
end end
it 'change expiration date' do it 'changes expiration date' do
travel_to Time.zone.parse('2016-08-06 08:00') do group.add_developer(new_member)
date = 3.days.from_now visit group_group_members_path(group)
group.add_developer(new_member)
page.within "#group_member_#{group_member_id}" do
fill_in 'Expiration date', with: 3.days.from_now.to_date
find_field('Expiration date').native.send_keys :enter
visit group_group_members_path(group) wait_for_requests
page.within "#group_member_#{group_member_id(new_member)}" do expect(page).to have_content('Expires in 3 days')
find('.js-access-expiration-date').set date.to_s(:medium) + "\n"
wait_for_requests
expect(page).to have_content('Expires in 3 days')
end
end end
end end
it 'remove expiration date' do it 'clears expiration date' do
travel_to Time.zone.parse('2016-08-06 08:00') do create(:group_member, :developer, user: new_member, group: group, expires_at: 3.days.from_now.to_date)
date = 3.days.from_now visit group_group_members_path(group)
group_member = create(:group_member, :developer, user: new_member, group: group, expires_at: date.to_s(:medium))
page.within "#group_member_#{group_member_id}" do
expect(page).to have_content('Expires in 3 days')
find('.js-clear-input').click
visit group_group_members_path(group) wait_for_requests
page.within "#group_member_#{group_member.id}" do expect(page).not_to have_content('Expires in')
find('.js-clear-input').click
wait_for_requests
expect(page).not_to have_content('Expires in 3 days')
end
end end
end end
def group_member_id(user) def group_member_id
group.members.find_by(user_id: new_member).id group.members.find_by(user_id: new_member).id
end end
end end
...@@ -6,43 +6,64 @@ RSpec.describe 'Projects > Members > Maintainer adds member with expiration date ...@@ -6,43 +6,64 @@ RSpec.describe 'Projects > Members > Maintainer adds member with expiration date
include Select2Helper include Select2Helper
include ActiveSupport::Testing::TimeHelpers include ActiveSupport::Testing::TimeHelpers
let(:maintainer) { create(:user) } let_it_be(:maintainer) { create(:user) }
let(:project) { create(:project) } let_it_be(:project) { create(:project) }
let!(:new_member) { create(:user) } let(:new_member) { create(:user) }
before do before do
travel_to Time.now.utc.beginning_of_day
project.add_maintainer(maintainer) project.add_maintainer(maintainer)
sign_in(maintainer) sign_in(maintainer)
end end
it 'expiration date is displayed in the members list' do it 'expiration date is displayed in the members list' do
travel_to Time.zone.parse('2016-08-06 08:00') do visit project_project_members_path(project)
date = 4.days.from_now
visit project_project_members_path(project) page.within '.invite-users-form' do
select2(new_member.id, from: '#user_ids', multiple: true)
page.within '.invite-users-form' do
select2(new_member.id, from: '#user_ids', multiple: true) fill_in 'expires_at', with: 3.days.from_now.to_date
fill_in 'expires_at', with: date.to_s(:medium) + "\n" find_field('expires_at').native.send_keys :enter
click_on 'Invite'
end click_on 'Invite'
end
page.within "#project_member_#{new_member.project_members.first.id}" do
expect(page).to have_content('Expires in 4 days') page.within "#project_member_#{project_member_id}" do
end expect(page).to have_content('Expires in 3 days')
end
end
it 'changes expiration date' do
project.team.add_users([new_member.id], :developer, expires_at: Date.today.to_date)
visit project_project_members_path(project)
page.within "#project_member_#{project_member_id}" do
fill_in 'Expiration date', with: 3.days.from_now.to_date
find_field('Expiration date').native.send_keys :enter
wait_for_requests
expect(page).to have_content('Expires in 3 days')
end end
end end
it 'change expiration date' do it 'clears expiration date' do
travel_to Time.zone.parse('2016-08-06 08:00') do project.team.add_users([new_member.id], :developer, expires_at: 3.days.from_now.to_date)
date = 3.days.from_now visit project_project_members_path(project)
project.team.add_users([new_member.id], :developer, expires_at: Date.today.to_s(:medium))
visit project_project_members_path(project) page.within "#project_member_#{project_member_id}" do
expect(page).to have_content('Expires in 3 days')
page.within "#project_member_#{new_member.project_members.first.id}" do
find('.js-access-expiration-date').set date.to_s(:medium) + "\n" find('.js-clear-input').click
wait_for_requests
expect(page).to have_content('Expires in 3 days') wait_for_requests
end
expect(page).not_to have_content('Expires in')
end end
end end
def project_member_id
project.members.find_by(user_id: new_member).id
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