2015-03-18 22:02:38 +00:00
|
|
|
class IssuePolicy < ApplicationPolicy
|
|
|
|
|
|
|
|
def index?
|
2015-03-19 23:31:41 +00:00
|
|
|
# record.project.has_issues?
|
|
|
|
true
|
2015-03-18 22:02:38 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def show?
|
2015-04-23 06:14:22 +01:00
|
|
|
return true if record.pull_request.present? # for redirect from a issue to a pull request
|
2015-04-06 22:55:51 +01:00
|
|
|
return false unless record.project.has_issues?
|
2015-03-25 00:17:17 +00:00
|
|
|
ProjectPolicy.new(user, record.project).show?
|
2015-03-18 22:02:38 +00:00
|
|
|
end
|
|
|
|
alias_method :create?, :show?
|
|
|
|
alias_method :read?, :show?
|
|
|
|
|
|
|
|
def update?
|
2015-04-10 23:35:36 +01:00
|
|
|
return false if user.guest?
|
2015-04-06 22:55:51 +01:00
|
|
|
is_admin? || record.user_id == user.id || local_admin?(record.project)
|
2015-03-18 22:02:38 +00:00
|
|
|
end
|
|
|
|
|
2015-04-29 00:26:03 +01:00
|
|
|
# Public: Get list of parameters that the user is allowed to alter.
|
|
|
|
#
|
|
|
|
# Returns Array
|
|
|
|
def permitted_attributes
|
|
|
|
pa = %i(title body)
|
|
|
|
if ProjectPolicy.new(user, record.project).write?
|
|
|
|
pa << :assignee_id
|
2015-05-26 22:48:22 +01:00
|
|
|
pa << { labelings_attributes: %i(id name color label_id _destroy) }
|
2015-04-29 00:26:03 +01:00
|
|
|
pa << { labelings: [] }
|
|
|
|
end
|
|
|
|
pa
|
|
|
|
end
|
|
|
|
|
2015-03-18 22:02:38 +00:00
|
|
|
end
|