mirror of
https://github.com/ENSL/ensl.org.git
synced 2024-12-26 20:41:01 +00:00
refined issue to have more clear permission logic
This commit is contained in:
parent
0bf5e74c38
commit
9312a90585
1 changed files with 18 additions and 11 deletions
|
@ -24,6 +24,11 @@ class Issue < ActiveRecord::Base
|
||||||
STATUS_SOLVED = 1
|
STATUS_SOLVED = 1
|
||||||
STATUS_REJECTED = 2
|
STATUS_REJECTED = 2
|
||||||
|
|
||||||
|
CATEGORY_WEBSITE = 17
|
||||||
|
CATEGORY_NSLPLUGIN = 20
|
||||||
|
CATEGORY_LEAGUE = 22
|
||||||
|
CATEGORY_GATHER = 52
|
||||||
|
|
||||||
attr_accessor :assigned_name
|
attr_accessor :assigned_name
|
||||||
attr_protected :id, :created_at, :updated_at
|
attr_protected :id, :created_at, :updated_at
|
||||||
|
|
||||||
|
@ -96,7 +101,11 @@ class Issue < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def can_show? cuser
|
def can_show? cuser
|
||||||
cuser and ((author == cuser) or (Issue::allowed_categories(cuser).include?(self.category_id)))
|
return false unless cuser
|
||||||
|
return true if cuser.admin?
|
||||||
|
|
||||||
|
((author == cuser) or (Issue::allowed_categories(cuser).include?(self.category_id)))
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def can_create? cuser
|
def can_create? cuser
|
||||||
|
@ -104,12 +113,10 @@ class Issue < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def can_update?(cuser, params = {})
|
def can_update?(cuser, params = {})
|
||||||
ret = cuser && Issue::allowed_categories(cuser).include?(self.category_id)
|
return false unless cuser
|
||||||
if ret && !cuser.admin? && params.member?(:category_id)
|
return true if cuser.admin?
|
||||||
ret = (self.category_id.to_s == params[:category_id])
|
return false unless Issue::allowed_categories(cuser).include?(self.category_id)
|
||||||
end
|
!(params.member?(:category_id) && (self.category_id.to_s != params[:category_id]))
|
||||||
|
|
||||||
ret
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def can_destroy? cuser
|
def can_destroy? cuser
|
||||||
|
@ -120,10 +127,10 @@ class Issue < ActiveRecord::Base
|
||||||
|
|
||||||
def self.allowed_categories cuser
|
def self.allowed_categories cuser
|
||||||
allowed = []
|
allowed = []
|
||||||
allowed << 54 if cuser.admin? || cuser.gather_moderator? # gather
|
allowed << CATEGORY_GATHER if cuser.admin? || cuser.gather_moderator? # gather
|
||||||
allowed << 17 if cuser.admin? # website
|
allowed << CATEGORY_WEBSITE if cuser.admin? # website
|
||||||
allowed << 22 if cuser.admin? # league
|
allowed << CATEGORY_LEAGUE if cuser.admin? # league
|
||||||
allowed << 20 if cuser.admin? # ensl plugin
|
allowed << CATEGORY_NSLPLUGIN if cuser.admin? # ensl plugin
|
||||||
allowed
|
allowed
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue