2018-03-29 21:55:26 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module SmartAnnotations
|
|
|
|
class PermissionEval
|
|
|
|
class << self
|
|
|
|
include Canaid::Helpers::PermissionsHelper
|
|
|
|
|
2019-03-20 19:58:22 +08:00
|
|
|
def check(user, team, type, object)
|
2019-05-31 15:56:54 +08:00
|
|
|
__send__("validate_#{type}_permissions", user, team, object)
|
2018-03-29 21:55:26 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2019-03-20 19:58:22 +08:00
|
|
|
def validate_prj_permissions(user, team, object)
|
|
|
|
object.team.id == team.id && can_read_project?(user, object)
|
2018-03-29 21:55:26 +08:00
|
|
|
end
|
|
|
|
|
2019-03-20 19:58:22 +08:00
|
|
|
def validate_exp_permissions(user, team, object)
|
|
|
|
object.project.team.id == team.id && can_read_experiment?(user, object)
|
2018-03-29 21:55:26 +08:00
|
|
|
end
|
|
|
|
|
2019-03-20 19:58:22 +08:00
|
|
|
def validate_tsk_permissions(user, team, object)
|
|
|
|
object.experiment.project.team.id == team.id &&
|
|
|
|
can_read_experiment?(user, object.experiment)
|
2018-03-29 21:55:26 +08:00
|
|
|
end
|
|
|
|
|
2019-03-20 19:58:22 +08:00
|
|
|
def validate_rep_item_permissions(user, team, object)
|
|
|
|
if object.repository
|
2019-09-09 21:11:18 +08:00
|
|
|
return can_read_repository?(user, object.repository)
|
2019-03-20 19:58:22 +08:00
|
|
|
end
|
|
|
|
|
2018-05-25 17:41:43 +08:00
|
|
|
# handles discarded repositories
|
|
|
|
repository = Repository.with_discarded.find_by_id(object.repository_id)
|
|
|
|
# evaluate to false if repository not found
|
|
|
|
return false unless repository
|
2019-03-20 19:58:22 +08:00
|
|
|
|
2019-07-26 21:41:23 +08:00
|
|
|
(repository.team.id == team.id ||
|
2019-08-07 19:44:57 +08:00
|
|
|
repository.team_repositories.where(team_id: team.id).any?) &&
|
2019-07-26 21:41:23 +08:00
|
|
|
can_read_repository?(user, repository)
|
2018-03-29 21:55:26 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|