forked from mirrors/homebox
fix: prevents re-creating locations and labels when someone joins group (#262)
* closes #258 * remove debug statement
This commit is contained in:
parent
bd06fdafaf
commit
504569bed0
2 changed files with 24 additions and 19 deletions
|
@ -54,12 +54,14 @@ func (svc *UserService) RegisterUser(ctx context.Context, data UserRegistration)
|
||||||
err error
|
err error
|
||||||
group repo.Group
|
group repo.Group
|
||||||
token repo.GroupInvitation
|
token repo.GroupInvitation
|
||||||
isOwner = false
|
|
||||||
|
// creatingGroup is true if the user is creating a new group.
|
||||||
|
creatingGroup = false
|
||||||
)
|
)
|
||||||
|
|
||||||
switch data.GroupToken {
|
switch data.GroupToken {
|
||||||
case "":
|
case "":
|
||||||
isOwner = true
|
creatingGroup = true
|
||||||
group, err = svc.repos.Groups.GroupCreate(ctx, "Home")
|
group, err = svc.repos.Groups.GroupCreate(ctx, "Home")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Err(err).Msg("Failed to create group")
|
log.Err(err).Msg("Failed to create group")
|
||||||
|
@ -81,7 +83,7 @@ func (svc *UserService) RegisterUser(ctx context.Context, data UserRegistration)
|
||||||
Password: hashed,
|
Password: hashed,
|
||||||
IsSuperuser: false,
|
IsSuperuser: false,
|
||||||
GroupID: group.ID,
|
GroupID: group.ID,
|
||||||
IsOwner: isOwner,
|
IsOwner: creatingGroup,
|
||||||
}
|
}
|
||||||
|
|
||||||
usr, err := svc.repos.Users.Create(ctx, usrCreate)
|
usr, err := svc.repos.Users.Create(ctx, usrCreate)
|
||||||
|
@ -89,6 +91,8 @@ func (svc *UserService) RegisterUser(ctx context.Context, data UserRegistration)
|
||||||
return repo.UserOut{}, err
|
return repo.UserOut{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create the default labels and locations for the group.
|
||||||
|
if creatingGroup {
|
||||||
for _, label := range defaultLabels() {
|
for _, label := range defaultLabels() {
|
||||||
_, err := svc.repos.Labels.Create(ctx, group.ID, label)
|
_, err := svc.repos.Labels.Create(ctx, group.ID, label)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -102,8 +106,9 @@ func (svc *UserService) RegisterUser(ctx context.Context, data UserRegistration)
|
||||||
return repo.UserOut{}, err
|
return repo.UserOut{}, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Decrement the invitation token if it was used
|
// Decrement the invitation token if it was used.
|
||||||
if token.ID != uuid.Nil {
|
if token.ID != uuid.Nil {
|
||||||
err = svc.repos.Groups.InvitationUpdate(ctx, token.ID, token.Uses-1)
|
err = svc.repos.Groups.InvitationUpdate(ctx, token.ID, token.Uses-1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -653,7 +653,7 @@ func (e *ItemsRepository) GetAllCustomFieldNames(ctx context.Context, GID uuid.U
|
||||||
|
|
||||||
var fields []st
|
var fields []st
|
||||||
|
|
||||||
err := e.db.Debug().Item.Query().
|
err := e.db.Item.Query().
|
||||||
Where(
|
Where(
|
||||||
item.HasGroupWith(group.ID(GID)),
|
item.HasGroupWith(group.ID(GID)),
|
||||||
).
|
).
|
||||||
|
|
Loading…
Reference in a new issue