Skip to content

Commit

Permalink
allow admin to delete users accounts (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
ice-cronus authored Jan 20, 2024
1 parent d0f4319 commit deb1407
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/eskimo-hut/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ type (
Checksum string `form:"checksum" formMultipart:"checksum"`
}
DeleteUserArg struct {
UserID string `uri:"userId" required:"true" example:"did:ethr:0x4B73C58370AEfcEf86A6021afCDe5673511376B2"`
UserID string `uri:"userId" required:"true" allowForbiddenWriteOperation:"true" example:"did:ethr:0x4B73C58370AEfcEf86A6021afCDe5673511376B2"`
}
GetDeviceLocationArg struct {
// Optional. Set it to `-` if unknown.
Expand Down
5 changes: 5 additions & 0 deletions cmd/eskimo-hut/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,11 @@ func (s *service) DeleteUser( //nolint:gocritic // False negative.
ctx context.Context,
req *server.Request[DeleteUserArg, any],
) (*server.Response[any], *server.Response[server.ErrorResponse]) {
if req.Data.UserID != req.AuthenticatedUser.UserID {
if req.AuthenticatedUser.Role != adminRole {
return nil, server.Forbidden(errors.New("not allowed"))
}
}
if err := s.usersProcessor.DeleteUser(ctx, req.Data.UserID); err != nil {
if errors.Is(err, users.ErrNotFound) {
return server.NoContent(), nil
Expand Down

0 comments on commit deb1407

Please sign in to comment.