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)
|
2020-09-21 20:09:11 +08:00
|
|
|
object.archived = false
|
2020-09-21 20:41:51 +08:00
|
|
|
permission_check = object.team.id == team.id && can_read_project?(user, object)
|
2020-09-24 17:56:17 +08:00
|
|
|
object.archived = true if object.archived_changed?
|
2020-09-21 20:41:51 +08:00
|
|
|
permission_check
|
2018-03-29 21:55:26 +08:00
|
|
|
end
|
|
|
|
|
2019-03-20 19:58:22 +08:00
|
|
|
def validate_exp_permissions(user, team, object)
|
2020-09-21 20:09:11 +08:00
|
|
|
object.archived = false
|
2020-11-06 18:47:18 +08:00
|
|
|
permission_check = validate_prj_permissions(user, team, object.project)
|
2020-09-24 17:56:17 +08:00
|
|
|
object.archived = true if object.archived_changed?
|
2020-09-21 20:41:51 +08:00
|
|
|
permission_check
|
2018-03-29 21:55:26 +08:00
|
|
|
end
|
|
|
|
|
2019-03-20 19:58:22 +08:00
|
|
|
def validate_tsk_permissions(user, team, object)
|
2020-09-21 20:09:11 +08:00
|
|
|
validate_exp_permissions(user, team, 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)
|
2020-10-23 19:32:19 +08:00
|
|
|
if object.repository
|
|
|
|
return Repository.accessible_by_teams(team).find_by(id: object.repository_id).present? &&
|
|
|
|
can_read_repository?(user, object.repository)
|
|
|
|
end
|
2019-03-20 19:58:22 +08:00
|
|
|
|
2018-05-25 17:41:43 +08:00
|
|
|
# handles discarded repositories
|
2020-09-21 20:09:11 +08:00
|
|
|
repository = Repository.with_discarded.find_by(id: object.repository_id)
|
2018-05-25 17:41:43 +08:00
|
|
|
# evaluate to false if repository not found
|
|
|
|
return false unless repository
|
2018-03-29 21:55:26 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|