Merge pull request #2431 from okriuchykhin/ok_SCI_4381

Add invite users to the team permission check [SCI-4381]
This commit is contained in:
Alex Kriuchykhin 2020-02-28 16:40:57 +01:00 committed by GitHub
commit f9ad438fb5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 34 deletions

View file

@ -11,17 +11,6 @@
}); });
} }
function AddUserButtonTemplate() {
return `
<a href="#" class="btn btn-primary" data-trigger="invite-users"
data-turbolinks="false" data-modal-id="team-invite-users-modal"
>
<span class="fas fa-plus"></span>
${I18n.t('users.settings.teams.edit.add_user')}
</a>
`;
}
// Initialize users DataTable // Initialize users DataTable
function initUsersTable() { function initUsersTable() {
usersDatatable = $('#users-table').DataTable({ usersDatatable = $('#users-table').DataTable({
@ -70,7 +59,7 @@
sSearch: I18n.t('general.filter') sSearch: I18n.t('general.filter')
} }
}); });
$('.users-datatable .add-new-team-members').html(AddUserButtonTemplate()); $('#add-new-team-members-button').detach().appendTo('.users-datatable .add-new-team-members').removeClass('hidden');
setTimeout(() => { $('#users-table').css('width', '100%'); }, 300); setTimeout(() => { $('#users-table').css('width', '100%'); }, 300);
} }

View file

@ -16,6 +16,11 @@ Canaid::Permissions.register_for(Team) do
user.is_admin_of_team?(team) user.is_admin_of_team?(team)
end end
# team: invite new users to the team
can :invite_team_users do
true
end
# project: create # project: create
can :create_projects do |user, team| can :create_projects do |user, team|
user.is_normal_user_or_admin_of_team?(team) user.is_normal_user_or_admin_of_team?(team)

View file

@ -78,24 +78,21 @@ invite_to_team = type.in?(%w(invite_to_team invite_to_team_with_role))
<% if type.in?(['invite_with_team_selector', 'invite_with_team_selector_and_role']) %> <% if type.in?(['invite_with_team_selector', 'invite_with_team_selector_and_role']) %>
<% # Only allow inviting to teams where user is admin %> <% # Only allow inviting to teams where user is admin %>
<% uos = current_user ? current_user.user_teams.where(role: UserTeam.roles[:admin]).joins(:team) : [] %> <% teams = current_user.teams
<% if uos.count > 0 %> .joins(:user_teams)
.where('user_teams.role': UserTeam.roles[:admin])
.select { |team| can_invite_team_users?(team) } %>
<% if teams.any? %>
<div class="team-selector"> <div class="team-selector">
<div class="heading"> <div class="heading">
<input type="checkbox" data-role="team-selector-checkbox" /> <input type="checkbox" data-role="team-selector-checkbox" />
<span><%= t('invite_users.invite_to_team_heading') %></span> <span><%= t('invite_users.invite_to_team_heading') %></span>
</div> </div>
<%= select_tag( <%= select_tag('team-select',
'team-select', options_for_select(teams.pluck(:name, :id)),
options_for_select( { class: 'form-control selectpicker',
uos.pluck('teams.name', 'teams.id') 'data-role' => 'team-selector-dropdown',
), disabled: 'disabled' }) %>
{
class: 'form-control selectpicker',
'data-role' => 'team-selector-dropdown',
disabled: 'disabled'
}
) %>
</div> </div>
<% end %> <% end %>
<% end %> <% end %>

View file

@ -78,6 +78,18 @@
<!-- USERS TABLE --> <!-- USERS TABLE -->
<div class="users-datatable"> <div class="users-datatable">
<% if can_invite_team_users?(@team) %>
<div id="add-new-team-members-button" class="hidden">
<a href="#" class="btn btn-primary" data-trigger="invite-users" data-turbolinks="false" data-modal-id="team-invite-users-modal">
<span class="fas fa-plus"></span>
<%= I18n.t('users.settings.teams.edit.add_user') %>
</a>
</div>
<%= render(partial: 'shared/invite_users_modal.html.erb',
locals: { modal_id: 'team-invite-users-modal',
type: 'invite_to_team',
team: @team } ) %>
<% end %>
<table id="users-table" class="table" data-source="<%= team_users_datatable_path(@team, format: :json) %>"> <table id="users-table" class="table" data-source="<%= team_users_datatable_path(@team, format: :json) %>">
<thead> <thead>
<tr> <tr>
@ -100,15 +112,6 @@
</div> </div>
<%= render partial: 'users/settings/teams/description_modal.html.erb' %> <%= render partial: 'users/settings/teams/description_modal.html.erb' %>
<%= render(
partial: 'shared/invite_users_modal.html.erb',
locals: {
modal_id: 'team-invite-users-modal',
type: 'invite_to_team',
team: @team
}
)
%>
<%= render partial: 'users/settings/teams/destroy_modal.html.erb', locals: { team: @team } %> <%= render partial: 'users/settings/teams/destroy_modal.html.erb', locals: { team: @team } %>
<%= render partial: 'users/settings/user_teams/destroy_user_team_modal.html.erb' %> <%= render partial: 'users/settings/user_teams/destroy_user_team_modal.html.erb' %>
<%= stylesheet_link_tag 'datatables' %> <%= stylesheet_link_tag 'datatables' %>