Merge pull request #3513 from okriuchykhin/ok_SCI_5663

Allow project management to it's creator if project has no assigned users [SCI-5663]
This commit is contained in:
Alex Kriuchykhin 2021-09-14 11:08:25 +02:00 committed by GitHub
commit 3ca593d7f9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -7,7 +7,6 @@ module User::ProjectRoles
# Check if user is member of project
around %i(
is_member_of_project?
is_owner_of_project?
is_user_of_project?
is_user_or_higher_of_project?
is_technician_of_project?
@ -15,7 +14,7 @@ module User::ProjectRoles
is_viewer_of_project?
) do |proxy, *args, &block|
if args[0]
@user_project = user_projects.where(project: args[0]).take
@user_project = user_projects.find_by(project: args[0])
@user_project ? proxy.call(*args, &block) : false
else
false
@ -33,7 +32,13 @@ module User::ProjectRoles
end
def is_owner_of_project?(project)
@user_project.owner?
# if project has no assigned users, creator can manage it
if project.user_projects.none? && project.created_by_id == id
true
else
user_project = user_projects.find_by(project: project)
user_project.present? ? user_project.owner? : false
end
end
def is_user_of_project?(project)