Skip to content

Commit 46010f0

Browse files
authored
fix: show meaningful message when user already belonged to group (#57)
Signed-off-by: romanetar <roman_ag@hotmail.com>
1 parent 42418cb commit 46010f0

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

app/libs/Auth/Models/User.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,10 +713,12 @@ public function belongToGroup(string $slug): bool
713713

714714
/**
715715
* @param Group $group
716+
* @throws ValidationException
716717
*/
717718
public function addToGroup(Group $group)
718719
{
719-
if ($this->groups->contains($group)) return;
720+
if ($this->groups->contains($group))
721+
throw new ValidationException("User is already assigned to this group.");
720722
$this->groups->add($group);
721723
}
722724

public/assets/js/ajax.utils.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ function ajaxError(jqXHR, textStatus, errorThrown){
44
response = $.parseJSON(jqXHR.responseText);
55
if(HTTP_status == 412 ){
66
var msg = '';
7-
for(var property in response.messages) {
8-
msg +='* '+ response.messages[property]+'\n';
7+
8+
for(const error of response.errors) {
9+
msg +='* '+ error+'\n';
910
}
1011
displayErrorMessage('Validation error', msg);
1112
return;

0 commit comments

Comments
 (0)