FIX 重新定义项目权限控制的相关方法

This commit is contained in:
Jasder 2020-05-18 18:22:50 +08:00
parent 3158a879a4
commit e8ac921aa9
2 changed files with 18 additions and 2 deletions

View File

@ -5,7 +5,7 @@ module OperateProjectAbilityAble
end
def authorizate_user_can_edit_project!
return if current_user.project_manager? @project || current_user.admin?
return if @project.manager?(current_user) || current_user.admin?
render_forbidden('你没有权限操作.')
end

View File

@ -4,7 +4,9 @@ module ProjectOperable
included do
has_many :members, dependent: :destroy
has_many :except_owner_members, -> { joins(:roles).where.not(roles: { name: 'Manager' }) }, class_name: 'Member'
has_many :manager_members, -> { joins(:roles).where(roles: { name: 'Manager' }) }, class_name: 'Member'
has_many :managers, -> { joins(:roles).where(roles: { name: 'Manager' }) }, class_name: 'Member'
has_many :developers, -> { joins(:roles).where(roles: { name: 'Developer' }) }, class_name: 'Member'
has_many :reporters, -> { joins(:roles).where(roles: { name: 'Reporter' }) }, class_name: 'Member'
end
def add_member!(user_id, role_name='Developer')
@ -35,6 +37,20 @@ module ProjectOperable
self.owner == user
end
# 项目管理员(包含项目拥有者),权限:仓库设置、仓库可读可写
def manager?(user)
managers.exists? user
end
# 项目开发者,可读可写权限
def develper?(user)
developers.exists? user
end
# 报告者,只有可读权限
def reporter?(user)
reporters.exists? user
end
def set_developer_role(member)
role = Role.find_by_name 'Developer'
member.member_roles.create!(role: role)