Skip to content

Commit

Permalink
check for nil user before impersonating
Browse files Browse the repository at this point in the history
Signed-off-by: jkoberg <jkoberg@owncloud.com>
  • Loading branch information
kobergj committed Feb 28, 2023
1 parent eb0d678 commit 00fb265
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion services/userlog/pkg/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,17 @@ func (ul *UserlogService) DeleteEvents(userid string, evids []string) error {
}

func (ul *UserlogService) impersonate(u *user.UserId) context.Context {
if u == nil {
ul.log.Error().Msg("empty user")
return nil
}

ctx, _, err := utils.Impersonate(u, ul.gwClient, ul.cfg.MachineAuthAPIKey)
if err != nil {
ul.log.Error().Err(err).Str("userid", u.GetOpaqueId()).Msg("failed to impersonate user")
return context.Background()
return nil
}

return ctx
}

Expand Down Expand Up @@ -288,6 +294,10 @@ func (ul *UserlogService) alterUserEventList(userid string, alter func([]string)
// we need an owner to query space members
// we need to check the user has the required role to see the event
func (ul *UserlogService) findSpaceMembers(ctx context.Context, spaceID string, requiredRole permissionChecker) ([]string, error) {
if ctx == nil {
return nil, errors.New("need authenticated context to find space members")
}

space, err := ul.getSpace(ctx, spaceID)
if err != nil {
return nil, err
Expand Down

0 comments on commit 00fb265

Please sign in to comment.