mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-14 00:54:32 +08:00
rename organization/org/Organization to Team in datatables
This commit is contained in:
parent
9d90b9b42a
commit
9ae799d52c
12 changed files with 300 additions and 286 deletions
|
@ -3,9 +3,9 @@ class LoadFromRepositoryProtocolsDatatable < AjaxDatatablesRails::Base
|
|||
include ActiveRecord::Sanitization::ClassMethods
|
||||
include InputSanitizeHelper
|
||||
|
||||
def initialize(view, organization, type, user)
|
||||
def initialize(view, team, type, user)
|
||||
super(view)
|
||||
@organization = organization
|
||||
@team = team
|
||||
# :public or :private
|
||||
@type = type
|
||||
@user = user
|
||||
|
@ -84,20 +84,22 @@ class LoadFromRepositoryProtocolsDatatable < AjaxDatatablesRails::Base
|
|||
def get_raw_records_base
|
||||
records =
|
||||
Protocol
|
||||
.where(organization: @organization)
|
||||
.where(team: @team)
|
||||
.joins('LEFT OUTER JOIN "protocol_protocol_keywords" ON "protocol_protocol_keywords"."protocol_id" = "protocols"."id"')
|
||||
.joins('LEFT OUTER JOIN "protocol_keywords" ON "protocol_protocol_keywords"."protocol_keyword_id" = "protocol_keywords"."id"')
|
||||
|
||||
if @type == :public
|
||||
records =
|
||||
records
|
||||
.joins('LEFT OUTER JOIN "users" ON "users"."id" = "protocols"."added_by_id"')
|
||||
.where("\"protocols\".\"protocol_type\" = #{Protocol.protocol_types[:in_repository_public]}")
|
||||
.joins('LEFT OUTER JOIN users ON users.id = protocols.added_by_id')
|
||||
.where('protocols.protocol_type = ?',
|
||||
Protocol.protocol_types[:in_repository_public])
|
||||
else
|
||||
records =
|
||||
records
|
||||
.joins('LEFT OUTER JOIN "users" ON "users"."id" = "protocols"."added_by_id"')
|
||||
.where("\"protocols\".\"protocol_type\" = #{Protocol.protocol_types[:in_repository_private]}")
|
||||
.joins('LEFT OUTER JOIN users ON users.id = protocols.added_by_id')
|
||||
.where('protocols.protocol_type = ?',
|
||||
Protocol.protocol_types[:in_repository_private])
|
||||
.where(added_by: @user)
|
||||
end
|
||||
|
||||
|
|
|
@ -1,88 +0,0 @@
|
|||
class OrganizationUsersDatatable < AjaxDatatablesRails::Base
|
||||
include InputSanitizeHelper
|
||||
|
||||
def_delegator :@view, :link_to
|
||||
def_delegator :@view, :update_user_organization_path
|
||||
def_delegator :@view, :destroy_user_organization_html_path
|
||||
|
||||
def initialize(view, org, user)
|
||||
super(view)
|
||||
@org = org
|
||||
@user = user
|
||||
end
|
||||
|
||||
def sortable_columns
|
||||
@sortable_columns ||= [
|
||||
"User.full_name",
|
||||
"User.email",
|
||||
"UserOrganization.created_at",
|
||||
"User.confirmed_at",
|
||||
"UserOrganization.role"
|
||||
]
|
||||
end
|
||||
|
||||
def searchable_columns
|
||||
@searchable_columns ||= [
|
||||
"User.full_name",
|
||||
"User.email",
|
||||
"UserOrganization.created_at"
|
||||
]
|
||||
end
|
||||
|
||||
# A hack that overrides the new_search_contition method default behavior of the ajax-datatables-rails gem
|
||||
# now the method checks if the column is the created_at and generate a custom SQL to parse
|
||||
# it back to the caller method
|
||||
def new_search_condition(column, value)
|
||||
model, column = column.split('.')
|
||||
model = model.constantize
|
||||
formated_date = (I18n.t 'time.formats.datatables_date').gsub!(/^\"|\"?$/, '')
|
||||
if column == 'created_at'
|
||||
casted_column = ::Arel::Nodes::NamedFunction.new('CAST',
|
||||
[ Arel.sql("to_char( users.created_at, '#{ formated_date }' ) AS VARCHAR") ] )
|
||||
else
|
||||
casted_column = ::Arel::Nodes::NamedFunction.new('CAST',
|
||||
[model.arel_table[column.to_sym].as(typecast)])
|
||||
end
|
||||
casted_column.matches("%#{value}%")
|
||||
end
|
||||
private
|
||||
|
||||
# Returns json of current samples (already paginated)
|
||||
def data
|
||||
records.map do |record|
|
||||
{
|
||||
'DT_RowId': record.id,
|
||||
'0': escape_input(record.user.full_name),
|
||||
'1': escape_input(record.user.email),
|
||||
'2': I18n.l(record.created_at, format: :full),
|
||||
'3': record.user.active_status_str,
|
||||
'4': record.role_str,
|
||||
'5': ApplicationController.new.render_to_string(
|
||||
partial: "users/settings/organizations/user_dropdown.html.erb",
|
||||
locals: {
|
||||
user_organization: record,
|
||||
update_role_path: update_user_organization_path(record, format: :json),
|
||||
destroy_uo_link: link_to(
|
||||
I18n.t("users.settings.organizations.edit.user_dropdown.remove_label"),
|
||||
destroy_user_organization_html_path(record, format: :json),
|
||||
remote: true,
|
||||
data: { action: "destroy-user-organization" }
|
||||
),
|
||||
user: @user
|
||||
}
|
||||
)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
# Query database for records (this will be later paginated and filtered)
|
||||
# after that "data" function will return json
|
||||
def get_raw_records
|
||||
UserOrganization
|
||||
.includes(:user)
|
||||
.references(:user)
|
||||
.where(organization: @org)
|
||||
.distinct
|
||||
end
|
||||
|
||||
end
|
|
@ -15,9 +15,9 @@ class ProtocolsDatatable < AjaxDatatablesRails::Base
|
|||
def_delegator :@view, :linked_children_protocol_path
|
||||
def_delegator :@view, :preview_protocol_path
|
||||
|
||||
def initialize(view, organization, type, user)
|
||||
def initialize(view, team, type, user)
|
||||
super(view)
|
||||
@organization = organization
|
||||
@team = team
|
||||
# :public, :private or :archive
|
||||
@type = type
|
||||
@user = user
|
||||
|
@ -88,13 +88,13 @@ class ProtocolsDatatable < AjaxDatatablesRails::Base
|
|||
'DT_CanEdit': can_edit_protocol(protocol),
|
||||
'DT_EditUrl': if can_edit_protocol(protocol)
|
||||
edit_protocol_path(protocol,
|
||||
organization: @organization,
|
||||
team: @team,
|
||||
type: @type)
|
||||
end,
|
||||
'DT_CanClone': can_clone_protocol(protocol),
|
||||
'DT_CloneUrl': if can_clone_protocol(protocol)
|
||||
clone_protocol_path(protocol,
|
||||
organization: @organization,
|
||||
team: @team,
|
||||
type: @type)
|
||||
end,
|
||||
'DT_CanMakePrivate': can_make_protocol_private(protocol),
|
||||
|
@ -120,26 +120,29 @@ class ProtocolsDatatable < AjaxDatatablesRails::Base
|
|||
def get_raw_records_base
|
||||
records =
|
||||
Protocol
|
||||
.where(organization: @organization)
|
||||
.where(team: @team)
|
||||
.joins('LEFT OUTER JOIN "protocol_protocol_keywords" ON "protocol_protocol_keywords"."protocol_id" = "protocols"."id"')
|
||||
.joins('LEFT OUTER JOIN "protocol_keywords" ON "protocol_protocol_keywords"."protocol_keyword_id" = "protocol_keywords"."id"')
|
||||
|
||||
if @type == :public
|
||||
records =
|
||||
records
|
||||
.joins('LEFT OUTER JOIN "users" ON "users"."id" = "protocols"."added_by_id"')
|
||||
.where("\"protocols\".\"protocol_type\" = #{Protocol.protocol_types[:in_repository_public]}")
|
||||
.joins('LEFT OUTER JOIN users ON users.id = protocols.added_by_id"')
|
||||
.where('protocols.protocol_type = ?',
|
||||
Protocol.protocol_types[:in_repository_public])
|
||||
elsif @type == :private
|
||||
records =
|
||||
records
|
||||
.joins('LEFT OUTER JOIN "users" ON "users"."id" = "protocols"."added_by_id"')
|
||||
.where("\"protocols\".\"protocol_type\" = #{Protocol.protocol_types[:in_repository_private]}")
|
||||
.joins('LEFT OUTER JOIN users ON users.id = protocols.added_by_id')
|
||||
.where('protocols.protocol_type = ?',
|
||||
Protocol.protocol_types[:in_repository_private])
|
||||
.where(added_by: @user)
|
||||
else
|
||||
records =
|
||||
records
|
||||
.joins('LEFT OUTER JOIN "users" ON "users"."id" = "protocols"."archived_by_id"')
|
||||
.where("\"protocols\".\"protocol_type\" = #{Protocol.protocol_types[:in_repository_archived]}")
|
||||
.joins('LEFT OUTER JOIN users ON users.id = protocols.archived_by_id')
|
||||
.where('protocols.protocol_type = ?',
|
||||
Protocol.protocol_types[:in_repository_archived])
|
||||
.where(added_by: @user)
|
||||
end
|
||||
|
||||
|
|
|
@ -34,13 +34,13 @@ class SampleDatatable < AjaxDatatablesRails::Base
|
|||
SAMPLES_TABLE_DEFAULT_STATE.freeze
|
||||
|
||||
def initialize(view,
|
||||
organization,
|
||||
team,
|
||||
project = nil,
|
||||
my_module = nil,
|
||||
experiment = nil,
|
||||
user = nil)
|
||||
super(view)
|
||||
@organization = organization
|
||||
@team = team
|
||||
@project = project
|
||||
@my_module = my_module
|
||||
@experiment = experiment
|
||||
|
@ -95,7 +95,7 @@ class SampleDatatable < AjaxDatatablesRails::Base
|
|||
|
||||
# Get array of columns to sort by (for custom fields)
|
||||
def custom_fields_sort_by
|
||||
num_cf = CustomField.where(organization_id: @organization).count
|
||||
num_cf = CustomField.where(team_id: @team).count
|
||||
array = []
|
||||
|
||||
num_cf.times do
|
||||
|
@ -132,7 +132,7 @@ class SampleDatatable < AjaxDatatablesRails::Base
|
|||
sample[@cf_mappings[scf.custom_field_id]] = auto_link(
|
||||
smart_annotation_parser(
|
||||
simple_format(sanitize_input(scf.value)),
|
||||
@organization
|
||||
@team
|
||||
),
|
||||
link: :urls,
|
||||
sanitize: false,
|
||||
|
@ -177,7 +177,7 @@ class SampleDatatable < AjaxDatatablesRails::Base
|
|||
:sample_custom_fields
|
||||
)
|
||||
.where(
|
||||
organization: @organization
|
||||
team: @team
|
||||
)
|
||||
|
||||
if @my_module
|
||||
|
@ -259,9 +259,9 @@ class SampleDatatable < AjaxDatatablesRails::Base
|
|||
.select('"samples"."id"')
|
||||
.distinct
|
||||
|
||||
# grabs the ids that are not the previous one but are still of the same organization
|
||||
# grabs the ids that are not the previous one but are still of the same team
|
||||
unassigned = Sample
|
||||
.where('"samples"."organization_id" = ?', @organization.id)
|
||||
.where('"samples"."team_id" = ?', @team.id)
|
||||
.where('"samples"."id" NOT IN (?)', assigned)
|
||||
.select('"samples"."id"')
|
||||
.distinct
|
||||
|
@ -294,9 +294,9 @@ class SampleDatatable < AjaxDatatablesRails::Base
|
|||
.select('"samples"."id"')
|
||||
.distinct
|
||||
|
||||
# grabs the ids that are not the previous one but are still of the same organization
|
||||
# grabs the ids that are not the previous one but are still of the same team
|
||||
unassigned = Sample
|
||||
.where('"samples"."organization_id" = ?', @organization.id)
|
||||
.where('"samples"."team_id" = ?', @team.id)
|
||||
.where('"samples"."id" NOT IN (?)', assigned)
|
||||
.select('"samples"."id"')
|
||||
.distinct
|
||||
|
@ -326,7 +326,7 @@ class SampleDatatable < AjaxDatatablesRails::Base
|
|||
LEFT OUTER JOIN "sample_types" ON "sample_types"."id" = "samples"."sample_type_id"
|
||||
LEFT OUTER JOIN "sample_groups" ON "sample_groups"."id" = "samples"."sample_group_id"
|
||||
LEFT OUTER JOIN "users" ON "users"."id" = "samples"."user_id"
|
||||
WHERE "samples"."organization_id" = ' + @organization.id.to_s + ' AND ' + conditions.to_sql
|
||||
WHERE "samples"."team_id" = ' + @team.id.to_s + ' AND ' + conditions.to_sql
|
||||
|
||||
records = records.where("samples.id IN (#{filter_query})")
|
||||
end
|
||||
|
@ -436,7 +436,7 @@ class SampleDatatable < AjaxDatatablesRails::Base
|
|||
|
||||
def generate_sortable_displayed_columns
|
||||
sort_order = SamplesTable.where(user: @user,
|
||||
organization: @organization)
|
||||
team: @team)
|
||||
.pluck(:status)
|
||||
.first['ColReorder']
|
||||
|
||||
|
|
95
app/datatables/team_users_datatable.rb
Normal file
95
app/datatables/team_users_datatable.rb
Normal file
|
@ -0,0 +1,95 @@
|
|||
class TeamUsersDatatable < AjaxDatatablesRails::Base
|
||||
include InputSanitizeHelper
|
||||
|
||||
def_delegator :@view, :link_to
|
||||
def_delegator :@view, :update_user_team_path
|
||||
def_delegator :@view, :destroy_user_team_html_path
|
||||
|
||||
def initialize(view, team, user)
|
||||
super(view)
|
||||
@team = team
|
||||
@user = user
|
||||
end
|
||||
|
||||
def sortable_columns
|
||||
@sortable_columns ||= [
|
||||
'User.full_name',
|
||||
'User.email',
|
||||
'UserTeam.created_at',
|
||||
'User.confirmed_at',
|
||||
'UserTeam.role'
|
||||
]
|
||||
end
|
||||
|
||||
def searchable_columns
|
||||
@searchable_columns ||= [
|
||||
'User.full_name',
|
||||
'User.email',
|
||||
'UserTeam.created_at'
|
||||
]
|
||||
end
|
||||
|
||||
# A hack that overrides the new_search_contition method default behavior of
|
||||
# the ajax-datatables-rails gem now the method checks if the column is the
|
||||
# created_at and generate a custom SQL to parse it back to the caller method
|
||||
def new_search_condition(column, value)
|
||||
model, column = column.split('.')
|
||||
model = model.constantize
|
||||
formated_date = (I18n.t 'time.formats.datatables_date')
|
||||
.gsub!(/^\"|\"?$/, '')
|
||||
if column == 'created_at'
|
||||
casted_column = ::Arel::Nodes::NamedFunction.new(
|
||||
'CAST',
|
||||
[Arel.sql(
|
||||
"to_char( users.created_at, '#{formated_date}' ) AS VARCHAR"
|
||||
)]
|
||||
)
|
||||
else
|
||||
casted_column = ::Arel::Nodes::NamedFunction.new(
|
||||
'CAST',
|
||||
[model.arel_table[column.to_sym].as(typecast)]
|
||||
)
|
||||
end
|
||||
casted_column.matches("%#{value}%")
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Returns json of current samples (already paginated)
|
||||
def data
|
||||
records.map do |record|
|
||||
{
|
||||
'DT_RowId': record.id,
|
||||
'0': escape_input(record.user.full_name),
|
||||
'1': escape_input(record.user.email),
|
||||
'2': I18n.l(record.created_at, format: :full),
|
||||
'3': record.user.active_status_str,
|
||||
'4': record.role_str,
|
||||
'5': ApplicationController.new.render_to_string(
|
||||
partial: 'users/settings/teams/user_dropdown.html.erb',
|
||||
locals: {
|
||||
user_team: record,
|
||||
update_role_path: update_user_team_path(record, format: :json),
|
||||
destroy_uo_link: link_to(
|
||||
I18n.t('users.settings.teams.edit.user_dropdown.remove_label'),
|
||||
destroy_user_team_html_path(record, format: :json),
|
||||
remote: true,
|
||||
data: { action: 'destroy-user-team' }
|
||||
),
|
||||
user: @user
|
||||
}
|
||||
)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
# Query database for records (this will be later paginated and filtered)
|
||||
# after that "data" function will return json
|
||||
def get_raw_records
|
||||
UserTeam
|
||||
.includes(:user)
|
||||
.references(:user)
|
||||
.where(team: @team)
|
||||
.distinct
|
||||
end
|
||||
end
|
|
@ -58,9 +58,9 @@ module ApplicationHelper
|
|||
!@experiment.nil?
|
||||
end
|
||||
|
||||
def smart_annotation_parser(text, organization = nil)
|
||||
def smart_annotation_parser(text, team = nil)
|
||||
new_text = smart_annotation_filter_resources(text)
|
||||
new_text = smart_annotation_filter_users(new_text, organization)
|
||||
new_text = smart_annotation_filter_users(new_text, team)
|
||||
new_text
|
||||
end
|
||||
|
||||
|
@ -127,20 +127,20 @@ module ApplicationHelper
|
|||
|
||||
# Check if text have smart annotations of users
|
||||
# and outputs a popover with user information
|
||||
def smart_annotation_filter_users(text, organization)
|
||||
def smart_annotation_filter_users(text, team)
|
||||
sa_user = /\[\@(.*?)~([0-9a-zA-Z]+)\]/
|
||||
new_text = text.gsub(sa_user) do |el|
|
||||
match = el.match(sa_user)
|
||||
user = User.find_by_id(match[2].base62_decode)
|
||||
organization ||= current_organization
|
||||
team ||= current_team
|
||||
|
||||
if user &&
|
||||
organization &&
|
||||
UserOrganization.user_in_organization(user, organization).any?
|
||||
user_org = user
|
||||
.user_organizations
|
||||
.where('user_organizations.organization_id = ?',
|
||||
organization).first
|
||||
team &&
|
||||
UserTeam.user_in_team(user, team).any?
|
||||
user_t, = user
|
||||
.user_teams
|
||||
.where('user_teams.team_id = ?',
|
||||
team).first
|
||||
user_description = %(<div class='col-xs-4'>
|
||||
<img src='#{avatar_path(user, :thumb)}' alt='thumb'>
|
||||
</div><div class='col-xs-8'>
|
||||
|
@ -150,9 +150,9 @@ module ApplicationHelper
|
|||
</div></div><div class='row'><div class='col-xs-12'>
|
||||
<p class='silver'>#{user.email}</p><p>
|
||||
#{I18n.t('atwho.popover_html',
|
||||
role: user_org.role.capitalize,
|
||||
organization: user_org.organization.name,
|
||||
time: user_org.created_at.strftime('%B %Y'))}
|
||||
role: user_t.role.capitalize,
|
||||
team: user_t.team.name,
|
||||
time: user_t.created_at.strftime('%B %Y'))}
|
||||
</p></div></div></div>)
|
||||
|
||||
raw(image_tag(avatar_path(user, :icon_small),
|
||||
|
|
|
@ -18,18 +18,18 @@ module NotificationsHelper
|
|||
AppMailer.delay.notification(user, notification)
|
||||
end
|
||||
|
||||
def generate_notification(user, target_user, org, role, project)
|
||||
if org
|
||||
title = I18n.t('notifications.unassign_user_from_organization',
|
||||
def generate_notification(user, target_user, team, role, project)
|
||||
if team
|
||||
title = I18n.t('notifications.unassign_user_from_team',
|
||||
unassigned_user: target_user.name,
|
||||
organization: org.name,
|
||||
team: team.name,
|
||||
unassigned_by_user: user.name)
|
||||
title = I18n.t('notifications.assign_user_to_organization',
|
||||
title = I18n.t('notifications.assign_user_to_team',
|
||||
assigned_user: target_user.name,
|
||||
role: role,
|
||||
organization: org.name,
|
||||
team: team.name,
|
||||
assigned_by_user: user.name) if role
|
||||
message = "#{I18n.t('search.index.organization')} #{org.name}"
|
||||
message = "#{I18n.t('search.index.team')} #{team.name}"
|
||||
elsif project
|
||||
title = I18n.t('activities.unassign_user_from_project',
|
||||
unassigned_user: target_user.full_name,
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
module OrganizationsHelper
|
||||
# resets the current organization if needed
|
||||
def current_organization_switch(org)
|
||||
if org != current_organization
|
||||
current_user.current_organization_id = org.id
|
||||
current_user.save
|
||||
end
|
||||
end
|
||||
|
||||
def truncate_organization_name(name, len = Constants::NAME_TRUNCATION_LENGTH)
|
||||
if name.length > len
|
||||
sanitize_input("<div class='modal-tooltip'>#{truncate(name, length: len)}
|
||||
<span class='modal-tooltiptext'>#{name}</span>
|
||||
</div>")
|
||||
else
|
||||
name
|
||||
end
|
||||
end
|
||||
end
|
|
@ -8,15 +8,15 @@ module PermissionHelper
|
|||
aspector do
|
||||
# ---- ORGANIZATION ROLES DEFINITIONS ----
|
||||
around [
|
||||
:is_member_of_organization,
|
||||
:is_admin_of_organization,
|
||||
:is_normal_user_of_organization,
|
||||
:is_normal_user_or_admin_of_organization,
|
||||
:is_guest_of_organization
|
||||
:is_member_of_team,
|
||||
:is_admin_of_team,
|
||||
:is_normal_user_of_team,
|
||||
:is_normal_user_or_admin_of_team,
|
||||
:is_guest_of_team
|
||||
] do |proxy, *args, &block|
|
||||
if args[0]
|
||||
@user_organization = current_user.user_organizations.where(organization: args[0]).take
|
||||
@user_organization ? proxy.call(*args, &block) : false
|
||||
@user_team = current_user.user_teams.where(team: args[0]).take
|
||||
@user_team ? proxy.call(*args, &block) : false
|
||||
else
|
||||
false
|
||||
end
|
||||
|
@ -178,25 +178,25 @@ module PermissionHelper
|
|||
# all permissions gathered here in one place.
|
||||
|
||||
# ---- ORGANIZATION ROLES ----
|
||||
def is_member_of_organization(organization)
|
||||
def is_member_of_team(team)
|
||||
# This is already checked by aspector, so just return true
|
||||
true
|
||||
end
|
||||
|
||||
def is_admin_of_organization(organization)
|
||||
@user_organization.admin?
|
||||
def is_admin_of_team(team)
|
||||
@user_team.admin?
|
||||
end
|
||||
|
||||
def is_normal_user_of_organization(organization)
|
||||
@user_organization.normal_user?
|
||||
def is_normal_user_of_team(team)
|
||||
@user_team.normal_user?
|
||||
end
|
||||
|
||||
def is_normal_user_or_admin_of_organization(organization)
|
||||
@user_organization.normal_user? or @user_organization.admin?
|
||||
def is_normal_user_or_admin_of_team(team)
|
||||
@user_team.normal_user? or @user_team.admin?
|
||||
end
|
||||
|
||||
def is_guest_of_organization(organization)
|
||||
@user_organization.guest?
|
||||
def is_guest_of_team(team)
|
||||
@user_team.guest?
|
||||
end
|
||||
|
||||
# ---- PROJECT ROLES ----
|
||||
|
@ -227,8 +227,8 @@ module PermissionHelper
|
|||
|
||||
def is_technician_or_higher_of_project(project)
|
||||
@user_project.technician? or
|
||||
@user_project.normal_user? or
|
||||
@user_project.owner?
|
||||
@user_project.normal_user? or
|
||||
@user_project.owner?
|
||||
end
|
||||
|
||||
def is_viewer_of_project(project)
|
||||
|
@ -247,25 +247,25 @@ module PermissionHelper
|
|||
# at the beginning of this file (via aspector).
|
||||
|
||||
# ---- ATWHO PERMISSIONS ----
|
||||
def can_view_organization_users(organization)
|
||||
is_member_of_organization(organization)
|
||||
def can_view_team_users(team)
|
||||
is_member_of_team(team)
|
||||
end
|
||||
|
||||
# ---- PROJECT PERMISSIONS ----
|
||||
|
||||
def can_view_projects(organization)
|
||||
is_member_of_organization(organization)
|
||||
def can_view_projects(team)
|
||||
is_member_of_team(team)
|
||||
end
|
||||
|
||||
def can_create_project(organization)
|
||||
is_normal_user_or_admin_of_organization(organization)
|
||||
def can_create_project(team)
|
||||
is_normal_user_or_admin_of_team(team)
|
||||
end
|
||||
|
||||
# User can view project if he's assigned onto it, or if
|
||||
# a project is public/visible, and user is a member of that organization
|
||||
# a project is public/visible, and user is a member of that team
|
||||
def can_view_project(project)
|
||||
is_member_of_project(project) or
|
||||
(project.visible? and is_member_of_organization(project.organization))
|
||||
(project.visible? and is_member_of_team(project.team))
|
||||
end
|
||||
|
||||
def can_view_project_activities(project)
|
||||
|
@ -333,7 +333,7 @@ module PermissionHelper
|
|||
end
|
||||
|
||||
def can_view_project_samples(project)
|
||||
can_view_samples(project.organization)
|
||||
can_view_samples(project.team)
|
||||
end
|
||||
|
||||
def can_view_project_archive(project)
|
||||
|
@ -384,17 +384,17 @@ module PermissionHelper
|
|||
end
|
||||
|
||||
def can_view_experiment_samples(experiment)
|
||||
can_view_samples(experiment.project.organization)
|
||||
can_view_samples(experiment.project.team)
|
||||
end
|
||||
|
||||
def can_clone_experiment(experiment)
|
||||
is_user_or_higher_of_project(experiment.project) &&
|
||||
is_normal_user_or_admin_of_organization(experiment.project.organization)
|
||||
is_normal_user_or_admin_of_team(experiment.project.team)
|
||||
end
|
||||
|
||||
def can_move_experiment(experiment)
|
||||
is_user_or_higher_of_project(experiment.project) &&
|
||||
is_normal_user_or_admin_of_organization(experiment.project.organization)
|
||||
is_normal_user_or_admin_of_team(experiment.project.team)
|
||||
end
|
||||
# ---- WORKFLOW PERMISSIONS ----
|
||||
|
||||
|
@ -523,7 +523,7 @@ module PermissionHelper
|
|||
|
||||
def can_view_module_samples(my_module)
|
||||
can_view_module(my_module) and
|
||||
can_view_samples(my_module.experiment.project.organization)
|
||||
can_view_samples(my_module.experiment.project.team)
|
||||
end
|
||||
|
||||
def can_view_module_archive(my_module)
|
||||
|
@ -537,7 +537,8 @@ module PermissionHelper
|
|||
end
|
||||
|
||||
def can_view_or_download_result_assets(my_module)
|
||||
is_member_of_project(my_module.experiment.project) || can_view_project(my_module.experiment.project)
|
||||
is_member_of_project(my_module.experiment.project) ||
|
||||
can_view_project(my_module.experiment.project)
|
||||
end
|
||||
|
||||
def can_view_result_comments(my_module)
|
||||
|
@ -629,19 +630,19 @@ module PermissionHelper
|
|||
|
||||
# ---- SAMPLE PERMISSIONS ----
|
||||
|
||||
def can_create_samples(organization)
|
||||
is_normal_user_or_admin_of_organization(organization)
|
||||
def can_create_samples(team)
|
||||
is_normal_user_or_admin_of_team(team)
|
||||
end
|
||||
|
||||
def can_view_samples(organization)
|
||||
is_member_of_organization(organization)
|
||||
def can_view_samples(team)
|
||||
is_member_of_team(team)
|
||||
end
|
||||
|
||||
# Only person who created the sample
|
||||
# or organization admin can edit it
|
||||
# or team admin can edit it
|
||||
def can_edit_sample(sample)
|
||||
is_admin_of_organization(sample.organization) or
|
||||
sample.user == current_user
|
||||
is_admin_of_team(sample.team) or
|
||||
sample.user == current_user
|
||||
end
|
||||
|
||||
# Only person who created sample can delete it
|
||||
|
@ -649,8 +650,8 @@ module PermissionHelper
|
|||
sample.user == current_user
|
||||
end
|
||||
|
||||
def can_delete_samples(organization)
|
||||
is_normal_user_or_admin_of_organization(organization)
|
||||
def can_delete_samples(team)
|
||||
is_normal_user_or_admin_of_team(team)
|
||||
end
|
||||
|
||||
def can_add_samples_to_module(my_module)
|
||||
|
@ -663,70 +664,70 @@ module PermissionHelper
|
|||
|
||||
# ---- SAMPLE TYPES PERMISSIONS ----
|
||||
|
||||
def can_create_sample_type_in_organization(organization)
|
||||
is_normal_user_or_admin_of_organization(organization)
|
||||
def can_create_sample_type_in_team(team)
|
||||
is_normal_user_or_admin_of_team(team)
|
||||
end
|
||||
|
||||
# ---- SAMPLE GROUPS PERMISSIONS ----
|
||||
|
||||
def can_create_sample_group_in_organization(organization)
|
||||
is_normal_user_or_admin_of_organization(organization)
|
||||
def can_create_sample_group_in_team(team)
|
||||
is_normal_user_or_admin_of_team(team)
|
||||
end
|
||||
|
||||
# ---- CUSTOM FIELDS PERMISSIONS ----
|
||||
|
||||
def can_create_custom_field_in_organization(organization)
|
||||
is_normal_user_or_admin_of_organization(organization)
|
||||
def can_create_custom_field_in_team(team)
|
||||
is_normal_user_or_admin_of_team(team)
|
||||
end
|
||||
|
||||
def can_edit_custom_field(custom_field)
|
||||
custom_field.user == current_user ||
|
||||
is_admin_of_organization(custom_field.organization)
|
||||
is_admin_of_team(custom_field.team)
|
||||
end
|
||||
|
||||
def can_delete_custom_field(custom_field)
|
||||
custom_field.user == current_user ||
|
||||
is_admin_of_organization(custom_field.organization)
|
||||
is_admin_of_team(custom_field.team)
|
||||
end
|
||||
|
||||
# ---- PROTOCOL PERMISSIONS ----
|
||||
|
||||
def can_view_organization_protocols(organization)
|
||||
is_member_of_organization(organization)
|
||||
def can_view_team_protocols(team)
|
||||
is_member_of_team(team)
|
||||
end
|
||||
|
||||
def can_create_new_protocol(organization)
|
||||
is_normal_user_or_admin_of_organization(organization)
|
||||
def can_create_new_protocol(team)
|
||||
is_normal_user_or_admin_of_team(team)
|
||||
end
|
||||
|
||||
def can_import_protocols(organization)
|
||||
is_normal_user_or_admin_of_organization(organization)
|
||||
def can_import_protocols(team)
|
||||
is_normal_user_or_admin_of_team(team)
|
||||
end
|
||||
|
||||
def can_view_protocol(protocol)
|
||||
if protocol.in_repository_public?
|
||||
is_member_of_organization(protocol.organization)
|
||||
elsif (protocol.in_repository_private? or protocol.in_repository_archived?)
|
||||
is_member_of_organization(protocol.organization) and
|
||||
protocol.added_by == current_user
|
||||
is_member_of_team(protocol.team)
|
||||
elsif protocol.in_repository_private? or protocol.in_repository_archived?
|
||||
is_member_of_team(protocol.team) and
|
||||
protocol.added_by == current_user
|
||||
elsif protocol.in_module?
|
||||
my_module = protocol.my_module
|
||||
my_module.active? &&
|
||||
my_module.experiment.project.active? &&
|
||||
can_view_module(my_module) &&
|
||||
my_module.experiment.active?
|
||||
my_module.experiment.project.active? &&
|
||||
can_view_module(my_module) &&
|
||||
my_module.experiment.active?
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
def can_edit_protocol(protocol)
|
||||
is_normal_user_or_admin_of_organization(protocol.organization) and
|
||||
is_normal_user_or_admin_of_team(protocol.team) and
|
||||
current_user == protocol.added_by and (not protocol.in_repository_archived?)
|
||||
end
|
||||
|
||||
def can_clone_protocol(protocol)
|
||||
is_normal_user_or_admin_of_organization(protocol.organization) and
|
||||
is_normal_user_or_admin_of_team(protocol.team) and
|
||||
(
|
||||
protocol.in_repository_public? or
|
||||
(protocol.in_repository_private? and current_user == protocol.added_by)
|
||||
|
@ -744,28 +745,29 @@ module PermissionHelper
|
|||
end
|
||||
|
||||
def can_export_protocol(protocol)
|
||||
(protocol.in_repository_public? and is_member_of_organization(protocol.organization)) or
|
||||
(protocol.in_repository_private? and protocol.added_by == current_user) or
|
||||
(protocol.in_module? and can_export_protocol_from_module(protocol.my_module))
|
||||
(protocol.in_repository_public? and is_member_of_team(protocol.team)) or
|
||||
(protocol.in_repository_private? and protocol.added_by == current_user) or
|
||||
(protocol.in_module? and
|
||||
can_export_protocol_from_module(protocol.my_module))
|
||||
end
|
||||
|
||||
def can_archive_protocol(protocol)
|
||||
protocol.added_by == current_user and
|
||||
(protocol.in_repository_public? or protocol.in_repository_private?)
|
||||
(protocol.in_repository_public? or protocol.in_repository_private?)
|
||||
end
|
||||
|
||||
def can_restore_protocol(protocol)
|
||||
protocol.added_by == current_user and
|
||||
protocol.in_repository_archived?
|
||||
protocol.in_repository_archived?
|
||||
end
|
||||
|
||||
def can_unlink_protocol(protocol)
|
||||
if protocol.linked?
|
||||
my_module = protocol.my_module
|
||||
my_module.active? &&
|
||||
my_module.experiment.project.active? &&
|
||||
is_user_or_higher_of_project(my_module.experiment.project) &&
|
||||
my_module.experiment.active?
|
||||
my_module.experiment.project.active? &&
|
||||
is_user_or_higher_of_project(my_module.experiment.project) &&
|
||||
my_module.experiment.active?
|
||||
else
|
||||
false
|
||||
end
|
||||
|
@ -775,9 +777,9 @@ module PermissionHelper
|
|||
if protocol.linked?
|
||||
my_module = protocol.my_module
|
||||
my_module.active? &&
|
||||
my_module.experiment.project.active? &&
|
||||
is_user_or_higher_of_project(my_module.experiment.project) &&
|
||||
my_module.experiment.active?
|
||||
my_module.experiment.project.active? &&
|
||||
is_user_or_higher_of_project(my_module.experiment.project) &&
|
||||
my_module.experiment.active?
|
||||
else
|
||||
false
|
||||
end
|
||||
|
@ -787,9 +789,9 @@ module PermissionHelper
|
|||
if protocol.linked?
|
||||
my_module = protocol.my_module
|
||||
my_module.active? &&
|
||||
my_module.experiment.project.active? &&
|
||||
is_user_or_higher_of_project(my_module.experiment.project) &&
|
||||
my_module.experiment.active?
|
||||
my_module.experiment.project.active? &&
|
||||
is_user_or_higher_of_project(my_module.experiment.project) &&
|
||||
my_module.experiment.active?
|
||||
else
|
||||
false
|
||||
end
|
||||
|
@ -799,9 +801,9 @@ module PermissionHelper
|
|||
if can_view_protocol(source)
|
||||
my_module = protocol.my_module
|
||||
my_module.active? &&
|
||||
my_module.experiment.project.active? &&
|
||||
is_user_or_higher_of_project(my_module.experiment.project) &&
|
||||
my_module.experiment.active?
|
||||
my_module.experiment.project.active? &&
|
||||
is_user_or_higher_of_project(my_module.experiment.project) &&
|
||||
my_module.experiment.active?
|
||||
else
|
||||
false
|
||||
end
|
||||
|
@ -813,12 +815,12 @@ module PermissionHelper
|
|||
parent = protocol.parent
|
||||
|
||||
my_module.active? &&
|
||||
my_module.experiment.project.active? &&
|
||||
my_module.experiment.active? &&
|
||||
is_normal_user_or_admin_of_organization(parent.organization) &&
|
||||
is_user_or_higher_of_project(my_module.experiment.project) &&
|
||||
(parent.in_repository_public? or parent.in_repository_private?) &&
|
||||
parent.added_by == current_user
|
||||
my_module.experiment.project.active? &&
|
||||
my_module.experiment.active? &&
|
||||
is_normal_user_or_admin_of_team(parent.team) &&
|
||||
is_user_or_higher_of_project(my_module.experiment.project) &&
|
||||
(parent.in_repository_public? or parent.in_repository_private?) &&
|
||||
parent.added_by == current_user
|
||||
else
|
||||
false
|
||||
end
|
||||
|
@ -835,21 +837,21 @@ module PermissionHelper
|
|||
end
|
||||
|
||||
def can_copy_protocol_to_repository(my_module)
|
||||
is_normal_user_or_admin_of_organization(my_module.experiment.project.organization)
|
||||
is_normal_user_or_admin_of_team(my_module.experiment.project.team)
|
||||
end
|
||||
|
||||
def can_link_copied_protocol_in_repository(protocol)
|
||||
can_copy_protocol_to_repository(protocol.my_module) and
|
||||
is_user_or_higher_of_project(protocol.my_module.experiment.project)
|
||||
is_user_or_higher_of_project(protocol.my_module.experiment.project)
|
||||
end
|
||||
|
||||
def can_view_steps_in_protocol(protocol)
|
||||
if protocol.in_module?
|
||||
my_module = protocol.my_module
|
||||
my_module.active? &&
|
||||
my_module.experiment.project.active? &&
|
||||
my_module.experiment.active? &&
|
||||
can_view_module(my_module)
|
||||
my_module.experiment.project.active? &&
|
||||
my_module.experiment.active? &&
|
||||
can_view_module(my_module)
|
||||
elsif protocol.in_repository?
|
||||
protocol.in_repository_active? and can_view_protocol(protocol)
|
||||
else
|
||||
|
@ -875,9 +877,9 @@ module PermissionHelper
|
|||
if protocol.in_module?
|
||||
my_module = protocol.my_module
|
||||
my_module.active? &&
|
||||
my_module.experiment.project.active? &&
|
||||
my_module.experiment.active? &&
|
||||
is_user_or_higher_of_project(my_module.experiment.project)
|
||||
my_module.experiment.project.active? &&
|
||||
my_module.experiment.active? &&
|
||||
is_user_or_higher_of_project(my_module.experiment.project)
|
||||
elsif protocol.in_repository?
|
||||
protocol.in_repository_active? and can_edit_protocol(protocol)
|
||||
else
|
||||
|
@ -909,9 +911,9 @@ module PermissionHelper
|
|||
if protocol.in_module?
|
||||
my_module = protocol.my_module
|
||||
my_module.active? &&
|
||||
my_module.experiment.project.active? &&
|
||||
my_module.experiment.active? &&
|
||||
is_owner_of_project(my_module.experiment.project)
|
||||
my_module.experiment.project.active? &&
|
||||
my_module.experiment.active? &&
|
||||
is_owner_of_project(my_module.experiment.project)
|
||||
elsif protocol.in_repository?
|
||||
protocol.in_repository_active? and can_edit_protocol(protocol)
|
||||
else
|
||||
|
@ -923,9 +925,9 @@ module PermissionHelper
|
|||
if protocol.in_module?
|
||||
my_module = protocol.my_module
|
||||
my_module.active? &&
|
||||
my_module.experiment.project.active? &&
|
||||
my_module.experiment.active? &&
|
||||
can_view_project(my_module.experiment.project)
|
||||
my_module.experiment.project.active? &&
|
||||
my_module.experiment.active? &&
|
||||
can_view_project(my_module.experiment.project)
|
||||
else
|
||||
# In repository, comments are disabled
|
||||
false
|
||||
|
@ -936,9 +938,9 @@ module PermissionHelper
|
|||
if protocol.in_module?
|
||||
my_module = protocol.my_module
|
||||
my_module.active? &&
|
||||
my_module.experiment.project.active? &&
|
||||
my_module.experiment.active? &&
|
||||
is_technician_or_higher_of_project(my_module.experiment.project)
|
||||
my_module.experiment.project.active? &&
|
||||
my_module.experiment.active? &&
|
||||
is_technician_or_higher_of_project(my_module.experiment.project)
|
||||
else
|
||||
# In repository, user cannot complete steps
|
||||
false
|
||||
|
@ -977,9 +979,10 @@ module PermissionHelper
|
|||
if protocol.in_module?
|
||||
my_module = protocol.my_module
|
||||
my_module.active? &&
|
||||
my_module.experiment.project.active? &&
|
||||
my_module.experiment.active? &&
|
||||
(is_member_of_project(my_module.experiment.project) || can_view_project(my_module.experiment.project))
|
||||
my_module.experiment.project.active? &&
|
||||
my_module.experiment.active? &&
|
||||
(is_member_of_project(my_module.experiment.project) ||
|
||||
can_view_project(my_module.experiment.project))
|
||||
elsif protocol.in_repository?
|
||||
protocol.in_repository_active? and can_view_protocol(protocol)
|
||||
else
|
||||
|
@ -991,9 +994,9 @@ module PermissionHelper
|
|||
if protocol.in_module?
|
||||
my_module = protocol.my_module
|
||||
my_module.active? &&
|
||||
my_module.experiment.project.active? &&
|
||||
my_module.experiment.active? &&
|
||||
is_technician_or_higher_of_project(my_module.experiment.project)
|
||||
my_module.experiment.project.active? &&
|
||||
my_module.experiment.active? &&
|
||||
is_technician_or_higher_of_project(my_module.experiment.project)
|
||||
else
|
||||
# In repository, user cannot complete steps
|
||||
false
|
||||
|
@ -1017,9 +1020,9 @@ module PermissionHelper
|
|||
if protocol.in_module?
|
||||
my_module = protocol.my_module
|
||||
my_module.active? &&
|
||||
my_module.experiment.project.active? &&
|
||||
my_module.experiment.active? &&
|
||||
is_technician_or_higher_of_project(my_module.experiment.project)
|
||||
my_module.experiment.project.active? &&
|
||||
my_module.experiment.active? &&
|
||||
is_technician_or_higher_of_project(my_module.experiment.project)
|
||||
else
|
||||
# In repository, user cannot check checkboxes
|
||||
false
|
||||
|
@ -1030,13 +1033,12 @@ module PermissionHelper
|
|||
if protocol.in_module?
|
||||
my_module = protocol.my_module
|
||||
my_module.active? &&
|
||||
my_module.experiment.project.active? &&
|
||||
my_module.experiment.active? &&
|
||||
is_user_or_higher_of_project(my_module.experiment.project)
|
||||
my_module.experiment.project.active? &&
|
||||
my_module.experiment.active? &&
|
||||
is_user_or_higher_of_project(my_module.experiment.project)
|
||||
else
|
||||
# In repository, user cannot check checkboxes
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -7,14 +7,14 @@ module SamplesHelper
|
|||
module_page? && can_delete_samples_from_module(@my_module)
|
||||
end
|
||||
|
||||
def can_add_sample_related_things_to_organization
|
||||
can_create_custom_field_in_organization(@organization) &&
|
||||
can_create_sample_type_in_organization(@organization) &&
|
||||
can_create_sample_group_in_organization(@organization)
|
||||
def can_add_sample_related_things_to_team
|
||||
can_create_custom_field_in_team(@team) &&
|
||||
can_create_sample_type_in_team(@team) &&
|
||||
can_create_sample_group_in_team(@team)
|
||||
end
|
||||
|
||||
def all_custom_fields
|
||||
CustomField.where(organization_id: @organization).order(:created_at)
|
||||
CustomField.where(team_id: @team).order(:created_at)
|
||||
end
|
||||
|
||||
def num_of_columns
|
||||
|
|
|
@ -7,24 +7,24 @@ module SearchHelper
|
|||
experiments.uniq
|
||||
end
|
||||
|
||||
def route_to_other_org(path, search_org, text)
|
||||
if search_org != current_organization
|
||||
def route_to_other_team(path, search_team, text)
|
||||
if search_team != current_team
|
||||
link_to text,
|
||||
path,
|
||||
data: { confirm: t('users.settings.changed_org_in_search',
|
||||
team: search_org.name) }
|
||||
data: { confirm: t('users.settings.changed_team_in_search',
|
||||
team: search_team.name) }
|
||||
else
|
||||
link_to text, path
|
||||
end
|
||||
end
|
||||
|
||||
def route_to_other_org_btn(path, search_org, text)
|
||||
if search_org != current_organization
|
||||
def route_to_other_team_btn(path, search_team, text)
|
||||
if search_team != current_team
|
||||
link_to text,
|
||||
path,
|
||||
class: 'btn btn-primary',
|
||||
data: { confirm: t('users.settings.changed_org_in_search',
|
||||
team: search_org.name) }
|
||||
data: { confirm: t('users.settings.changed_team_in_search',
|
||||
team: search_team.name) }
|
||||
else
|
||||
link_to text, path, class: 'btn btn-primary'
|
||||
end
|
||||
|
|
19
app/helpers/teams_helper.rb
Normal file
19
app/helpers/teams_helper.rb
Normal file
|
@ -0,0 +1,19 @@
|
|||
module TeamsHelper
|
||||
# resets the current team if needed
|
||||
def current_team_switch(team)
|
||||
if team != current_team
|
||||
current_user.current_team_id = team.id
|
||||
current_user.save
|
||||
end
|
||||
end
|
||||
|
||||
def truncate_team_name(name, len = Constants::NAME_TRUNCATION_LENGTH)
|
||||
if name.length > len
|
||||
sanitize_input("<div class='modal-tooltip'>#{truncate(name, length: len)}
|
||||
<span class='modal-tooltiptext'>#{name}</span>
|
||||
</div>")
|
||||
else
|
||||
name
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue