(ctx context.Context, req *adminv1.RevokeMagicAuthTokenRequest)
| 225 | } |
| 226 | |
| 227 | func (s *Server) RevokeMagicAuthToken(ctx context.Context, req *adminv1.RevokeMagicAuthTokenRequest) (*adminv1.RevokeMagicAuthTokenResponse, error) { |
| 228 | observability.AddRequestAttributes(ctx, |
| 229 | attribute.String("args.token_id", req.TokenId), |
| 230 | ) |
| 231 | |
| 232 | tkn, err := s.admin.DB.FindMagicAuthToken(ctx, req.TokenId, false) |
| 233 | if err != nil { |
| 234 | return nil, err |
| 235 | } |
| 236 | |
| 237 | proj, err := s.admin.DB.FindProject(ctx, tkn.ProjectID) |
| 238 | if err != nil { |
| 239 | return nil, err |
| 240 | } |
| 241 | |
| 242 | claims := auth.GetClaims(ctx) |
| 243 | projPerms := claims.ProjectPermissions(ctx, proj.OrganizationID, proj.ID) |
| 244 | if !projPerms.ManageMagicAuthTokens { |
| 245 | // If they don't have manage permissions, they can only revoke tokens they created themselves. |
| 246 | isCreator := tkn.CreatedByUserID != nil && *tkn.CreatedByUserID == claims.OwnerID() |
| 247 | if !projPerms.CreateMagicAuthTokens || !isCreator { |
| 248 | return nil, status.Error(codes.PermissionDenied, "not allowed to revoke this magic auth token") |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | err = s.admin.DB.DeleteMagicAuthToken(ctx, tkn.ID) |
| 253 | if err != nil { |
| 254 | return nil, err |
| 255 | } |
| 256 | |
| 257 | return &adminv1.RevokeMagicAuthTokenResponse{}, nil |
| 258 | } |
| 259 | |
| 260 | func (s *Server) magicAuthTokensToPB(tkns []*database.MagicAuthTokenWithUser, org *database.Organization, proj *database.Project) ([]*adminv1.MagicAuthToken, error) { |
| 261 | var pbs []*adminv1.MagicAuthToken |
nothing calls this directly
no test coverage detected