Skip to content

Commit

Permalink
Make role undelete dispatch event buss events
Browse files Browse the repository at this point in the history
This makes it consistent with other resource updaters.
  • Loading branch information
tjerman committed Jun 30, 2023
1 parent 1cd5c22 commit 6558efc
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions server/system/service/role.go
Expand Up @@ -506,7 +506,7 @@ func (svc role) Delete(ctx context.Context, roleID uint64) (err error) {

func (svc role) Undelete(ctx context.Context, roleID uint64) (err error) {
var (
r *types.Role
r, upd *types.Role
raProps = &roleActionProps{role: &types.Role{ID: roleID}}
)

Expand All @@ -519,18 +519,23 @@ func (svc role) Undelete(ctx context.Context, roleID uint64) (err error) {
return RoleErrNotAllowedToUndelete()
}

raProps.setRole(r)
upd = r.Clone()
if err = svc.eventbus.WaitFor(ctx, event.RoleBeforeUpdate(upd, r)); err != nil {
return
}

if !svc.ac.CanDeleteRole(ctx, r) {
raProps.setRole(upd)

if !svc.ac.CanDeleteRole(ctx, upd) {
return RoleErrNotAllowedToDelete()
}

r.DeletedAt = nil

if err = store.UpdateRole(ctx, svc.store, r); err != nil {
upd.DeletedAt = nil
if err = store.UpdateRole(ctx, svc.store, upd); err != nil {
return
}

svc.eventbus.Dispatch(ctx, event.RoleAfterUpdate(upd, r))
return nil
}()

Expand Down

0 comments on commit 6558efc

Please sign in to comment.