Changed wording for activities [SCI-8243] (#5356)

* Change wording for access activities in projects and protocols [SCI-8243]
* Add project activity for changing all team members role via project option-edit [SCI-8243]
This commit is contained in:
Soufiane 2023-06-13 16:55:40 +02:00 committed by GitHub
parent 976c29c136
commit 23e248ca02
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 51 additions and 40 deletions

View file

@ -167,64 +167,70 @@ class ProjectsController < ApplicationController
end
def update
@project.assign_attributes(project_update_params)
return_error = false
flash_error = t('projects.update.error_flash', name: escape_input(@project.name))
return render_403 unless can_manage_project?(@project) || @project.archived_changed?
# Check archive permissions if archiving/restoring
if project_params.include? :archived
if (project_params[:archived] == 'true' &&
!can_archive_project?(@project)) ||
(project_params[:archived] == 'false' &&
!can_restore_project?(@project))
if @project.archived_changed? &&
((@project.archived == 'true' && !can_archive_project?(@project)) ||
(@project.archived == 'false' && !can_restore_project?(@project)))
return_error = true
is_archive = project_params[:archived] == 'true' ? 'archive' : 'restore'
is_archive = @project.archived? ? 'archive' : 'restore'
flash_error =
t("projects.#{is_archive}.error_flash", name: escape_input(@project.name))
end
elsif !can_manage_project?(@project)
render_403 && return
end
message_renamed = nil
message_visibility = nil
if (project_params.include? :name) &&
(project_params[:name] != @project.name)
message_renamed = true
end
if (project_params.include? :visibility) &&
(project_params[:visibility] != @project.visibility)
message_visibility = if project_params[:visibility] == 'visible'
t('projects.activity.visibility_visible')
else
t('projects.activity.visibility_hidden')
end
message_renamed = @project.name_changed?
message_visibility = if @project.visibility_changed?
nil
elsif @project.visible?
t('projects.activity.visibility_visible')
else
t('projects.activity.visibility_hidden')
end
message_archived = if !@project.archived_changed?
nil
elsif @project.archived?
'archive'
else
'restore'
end
default_public_user_name = nil
if @project.visibility_changed? && @project.default_public_user_role_id_changed?
default_public_user_name = UserRole.find(project_params[:default_public_user_role_id])&.name
end
@project.last_modified_by = current_user
if !return_error && @project.update(project_params)
# Add activities if needed
if !return_error && @project.save
# Add activities if needed
log_activity(:change_project_visibility, @project, visibility: message_visibility) if message_visibility.present?
log_activity(:rename_project) if message_renamed.present?
log_activity(:archive_project) if project_params[:archived] == 'true'
log_activity(:restore_project) if project_params[:archived] == 'false'
log_activity(:archive_project) if message_archived == 'archive'
log_activity(:restore_project) if message_archived == 'restore'
if default_public_user_name.present?
log_activity(:project_access_changed_all_team_members,
@project,
{ team: @project.team.id, role: default_public_user_name })
end
flash_success = t('projects.update.success_flash', name: escape_input(@project.name))
if project_params[:archived] == 'true'
if message_archived == 'archive'
flash_success = t('projects.archive.success_flash', name: escape_input(@project.name))
elsif project_params[:archived] == 'false'
elsif message_archived == 'restore'
flash_success = t('projects.restore.success_flash', name: escape_input(@project.name))
end
respond_to do |format|
format.html do
# Redirect URL for archive view is different as for other views.
if project_params[:archived] == 'false'
# The project should be restored
@project.restore(current_user) unless @project.archived
elsif @project.archived
# The project should be archived
@project.archive(current_user)
end
@project.restore(current_user) if message_archived == 'restore'
@project.archive(current_user) if message_archived == 'archive'
redirect_to projects_path
flash[:success] = flash_success
end
@ -404,12 +410,17 @@ class ProjectsController < ApplicationController
def project_params
params.require(:project)
.permit(
:name, :team_id, :visibility,
:name, :visibility,
:archived, :project_folder_id,
:default_public_user_role_id
)
end
def project_update_params
params.require(:project)
.permit(:name, :visibility, :archived, :default_public_user_role_id)
end
def view_type_params
params.require(:project).require(:view_type)
end

View file

@ -87,7 +87,7 @@ en:
uncomplete_task_html: "%{user} uncompleted task %{my_module}."
assign_repository_record_html: "%{user} assigned inventory item(s) %{record_names} from inventory %{repository} to task %{my_module}."
unassign_repository_record_html: "%{user} unassigned inventory item(s) %{record_names} from inventory %{repository} to task %{my_module}."
assign_user_to_project_html: "%{user} granted with access %{user_target} with user role %{role} to project %{project}."
assign_user_to_project_html: "%{user} granted access to %{user_target} with user role %{role} to project %{project}."
unassign_user_from_project_html: "%{user} removed %{user_target} with user role %{role} from project %{project}."
change_user_role_on_project_html: "%{user} changed %{user_target}'s role on project %{project} to %{role}."
change_user_role_on_experiment_html: "%{user} changed %{user_target}'s role on experiment %{experiment} to %{role}."
@ -258,10 +258,10 @@ en:
protocol_template_revision_notes_updated_html: "%{user} edited revision notes of %{protocol}."
protocol_template_draft_deleted_html: "%{user} deleted draft of %{protocol}."
protocol_template_draft_created_html: "%{user} created draft of %{protocol}."
protocol_template_access_granted_html: "%{user} granted with access %{user_target} with user role %{role} to protocol template %{protocol}."
protocol_template_access_granted_html: "%{user} granted access to %{user_target} with user role %{role} to protocol template %{protocol}."
protocol_template_access_changed_html: "%{user} changed %{user_target}s role on protocol template %{protocol} to %{role}."
protocol_template_access_revoked_html: "%{user} removed %{user_target} with user role %{role} from protocol template %{protocol}."
protocol_template_access_granted_all_team_members_html: "%{user} granted with access all team members of %{team} team with user role %{role} to protocol template %{protocol}."
protocol_template_access_granted_all_team_members_html: "%{user} granted access to all team members of %{team} team with user role %{role} to protocol template %{protocol}."
protocol_template_access_changed_all_team_members_html: "%{user} changed %{team}s role on protocol template %{protocol} to %{role}."
protocol_template_access_revoked_all_team_members_html: "%{user} removed %{team} team members with user role %{role} from protocol template %{protocol}."
task_protocol_save_to_template_html: "%{user} created a new protocol template %{protocol} from a task."