mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-03 18:35:36 +08:00
Merge pull request #5116 from aignatov-bio/ai-sci-8063-add-all-team-members-through-access-modal
Add all team members through access modal [SCI-8063]
This commit is contained in:
commit
a50f5d270c
6 changed files with 92 additions and 25 deletions
|
@ -53,21 +53,36 @@ module AccessPermissions
|
|||
permitted_create_params[:resource_members].each do |_k, user_assignment_params|
|
||||
next unless user_assignment_params[:assign] == '1'
|
||||
|
||||
user_assignment = UserAssignment.find_or_initialize_by(
|
||||
assignable: @project,
|
||||
user_id: user_assignment_params[:user_id],
|
||||
team: current_team
|
||||
)
|
||||
if user_assignment_params[:user_id] == 'all'
|
||||
@project.update!(visibility: :visible, default_public_user_role_id: user_assignment_params[:user_role_id])
|
||||
Activities::CreateActivityService
|
||||
.call(activity_type: :change_project_visibility,
|
||||
owner: current_user,
|
||||
subject: @project,
|
||||
team: @project.team,
|
||||
project: @project,
|
||||
message_items: {
|
||||
project: @project.id,
|
||||
visibility: t('projects.activity.visibility_visible')
|
||||
})
|
||||
else
|
||||
|
||||
user_assignment.update!(
|
||||
user_role_id: user_assignment_params[:user_role_id],
|
||||
assigned_by: current_user,
|
||||
assigned: :manually
|
||||
)
|
||||
user_assignment = UserAssignment.find_or_initialize_by(
|
||||
assignable: @project,
|
||||
user_id: user_assignment_params[:user_id],
|
||||
team: current_team
|
||||
)
|
||||
|
||||
log_activity(:assign_user_to_project, user_assignment)
|
||||
created_count += 1
|
||||
propagate_job(user_assignment)
|
||||
user_assignment.update!(
|
||||
user_role_id: user_assignment_params[:user_role_id],
|
||||
assigned_by: current_user,
|
||||
assigned: :manually
|
||||
)
|
||||
|
||||
log_activity(:assign_user_to_project, user_assignment)
|
||||
created_count += 1
|
||||
propagate_job(user_assignment)
|
||||
end
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
|
|
|
@ -51,25 +51,31 @@ module AccessPermissions
|
|||
permitted_create_params[:resource_members].each do |_k, user_assignment_params|
|
||||
next unless user_assignment_params[:assign] == '1'
|
||||
|
||||
user_assignment = UserAssignment.find_or_initialize_by(
|
||||
assignable: @protocol,
|
||||
user_id: user_assignment_params[:user_id],
|
||||
team: current_team
|
||||
)
|
||||
if user_assignment_params[:user_id] == 'all'
|
||||
@protocol.update!(visibility: :visible, default_public_user_role_id: user_assignment_params[:user_role_id])
|
||||
else
|
||||
user_assignment = UserAssignment.find_or_initialize_by(
|
||||
assignable: @protocol,
|
||||
user_id: user_assignment_params[:user_id],
|
||||
team: current_team
|
||||
)
|
||||
|
||||
user_assignment.update!(
|
||||
user_role_id: user_assignment_params[:user_role_id],
|
||||
assigned_by: current_user,
|
||||
assigned: :manually
|
||||
)
|
||||
user_assignment.update!(
|
||||
user_role_id: user_assignment_params[:user_role_id],
|
||||
assigned_by: current_user,
|
||||
assigned: :manually
|
||||
)
|
||||
|
||||
created_count += 1
|
||||
log_activity(:protocol_template_access_granted, user_assignment)
|
||||
created_count += 1
|
||||
log_activity(:protocol_template_access_granted, user_assignment)
|
||||
end
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
@message = t('access_permissions.create.success', count: created_count)
|
||||
format.json { render :edit }
|
||||
end
|
||||
|
||||
rescue ActiveRecord::RecordInvalid
|
||||
respond_to do |format|
|
||||
@message = t('access_permissions.create.failure')
|
||||
|
|
|
@ -21,6 +21,7 @@ class Protocol < ApplicationRecord
|
|||
after_save :update_user_assignments, if: -> { saved_change_to_visibility? && in_repository? }
|
||||
after_save :update_linked_children
|
||||
skip_callback :create, :after, :create_users_assignments, if: -> { in_module? }
|
||||
before_update :sync_protocol_assignments, if: :visibility_changed?
|
||||
|
||||
enum visibility: { hidden: 0, visible: 1 }
|
||||
enum protocol_type: {
|
||||
|
@ -798,4 +799,12 @@ class Protocol < ApplicationRecord
|
|||
errors.add(:base, I18n.t('activerecord.errors.models.protocol.wrong_parent_draft_number'))
|
||||
end
|
||||
end
|
||||
|
||||
def sync_protocol_assignments
|
||||
if visible?
|
||||
auto_assign_protocol_members
|
||||
else
|
||||
user_assignments.where(assigned: :automatically).destroy_all
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -16,6 +16,11 @@
|
|||
<%= text_field_tag :search_users, '', placeholder: t('.find_people_html'), class: 'sci-input-field', data: { action: 'filter-list', target: 'new-user-assignment-to-project-form' } %>
|
||||
<i class="fas fa-search"></i>
|
||||
</div>
|
||||
<% if assignable.visibility && assignable.visibility == 'hidden' %>
|
||||
<%= f.fields_for :users, UserAssignment.new do |user_form| %>
|
||||
<%= render 'access_permissions/partials/public_assignment_field.html.erb', user_form: user_form, assignable: assignable %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% users.each do |user| %>
|
||||
<%= f.fields_for :users, UserAssignment.new(user: user) do |user_form| %>
|
||||
<%= render 'access_permissions/partials/user_assignment_field.html.erb', user_form: user_form, assignable: assignable %>
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
<% # frozen_string_literal: true %>
|
||||
|
||||
<div class="member-item new-member-item">
|
||||
<%= user_form.hidden_field :user_id, value: :all, name:"access_permissions_new_user_form[resource_members][0][user_id]" %>
|
||||
<div class="user-assignment-info">
|
||||
<div class="sci-checkbox-container">
|
||||
<%= user_form.check_box :assign,
|
||||
name: "access_permissions_new_user_form[resource_members][0][assign]",
|
||||
data: { action: 'toggle-visibility', target: 'usersAll' },
|
||||
class: "sci-checkbox"
|
||||
%>
|
||||
<span class="sci-checkbox-label"></span>
|
||||
</div>
|
||||
<div class="global-avatar-container">
|
||||
<%= image_tag "icon/team.png", class: 'img-circle pull-left' %>
|
||||
</div>
|
||||
<div>
|
||||
<%= t('user_assignment.assign_all_team_members') %>
|
||||
</div>
|
||||
</div>
|
||||
<div class="user-assignment-controls">
|
||||
<div class="user-assignment-role hidden" id="usersAll">
|
||||
<%= user_form.select :user_role_id,
|
||||
options_for_select(user_roles_collection(assignable)),
|
||||
{},
|
||||
name: "access_permissions_new_user_form[resource_members][0][user_role_id]",
|
||||
class: 'form-control selectpicker pull-right',
|
||||
title: t('user_assignment.select_role') %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
|
@ -3207,6 +3207,7 @@ en:
|
|||
change_experiment_role: "Change experiment role"
|
||||
change_my_module_role: "Change task role"
|
||||
select_role: "Select role"
|
||||
assign_all_team_members: "Grant access to all team members"
|
||||
from_project: "%{user_role} [from project]"
|
||||
from_experiment: "%{user_role} [from experiment]"
|
||||
experiment_select_role: "Change experiment role"
|
||||
|
|
Loading…
Add table
Reference in a new issue