diff options
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/members/invite_service.rb | 16 | ||||
-rw-r--r-- | app/services/projects/create_service.rb | 7 |
2 files changed, 17 insertions, 6 deletions
diff --git a/app/services/members/invite_service.rb b/app/services/members/invite_service.rb index cfab5c3ef9d..60ebbaface2 100644 --- a/app/services/members/invite_service.rb +++ b/app/services/members/invite_service.rb @@ -20,8 +20,8 @@ module Members emails.each do |email| next if existing_member?(source, email) - next if existing_invite?(source, email) + next if existing_request?(source, email) if existing_user?(email) add_existing_user_as_member(current_user, source, params, email) @@ -44,8 +44,7 @@ module Members access_level: params[:access_level], invite_email: email, created_by_id: current_user.id, - expires_at: params[:expires_at], - requested_at: Time.current.utc) + expires_at: params[:expires_at]) unless new_member.valid? && new_member.persisted? errors[params[:email]] = new_member.errors.full_messages.to_sentence @@ -92,6 +91,17 @@ module Members false end + def existing_request?(source, email) + existing_request = source.requesters.with_user_by_email(email).exists? + + if existing_request + errors[email] = "Member cannot be invited because they already requested to join #{source.name}" + return true + end + + false + end + def existing_user(email) User.find_by_email(email) end diff --git a/app/services/projects/create_service.rb b/app/services/projects/create_service.rb index 8f18a23aa0f..a01db4b498c 100644 --- a/app/services/projects/create_service.rb +++ b/app/services/projects/create_service.rb @@ -67,7 +67,7 @@ module Projects @project rescue ActiveRecord::RecordInvalid => e - message = "Unable to save #{e.record.type}: #{e.record.errors.full_messages.join(", ")} " + message = "Unable to save #{e.inspect}: #{e.record.errors.full_messages.join(", ")}" fail(error: message) rescue => e @project.errors.add(:base, e.message) if @project @@ -122,8 +122,9 @@ module Projects only_concrete_membership: true) if group_access_level > GroupMember::NO_ACCESS - current_user.project_authorizations.create!(project: @project, - access_level: group_access_level) + current_user.project_authorizations.safe_find_or_create_by!( + project: @project, + access_level: group_access_level) end if Feature.enabled?(:specialized_project_authorization_workers) |