Identity: Unfurl UserID and Email in pkg/api to user identity.Requester (#76112)

* Unfurl OrgRole in pkg/api to allow using identity.Requester interface

* Unfurl Email in pkg/api to allow using identity.Requester interface

* Update UserID in pkg/api to allow using identity.Requester interface

* fix authed test

* fix datasource tests

* guard login

* fix preferences anon testing

* fix anonymous index rendering

* do not error with user id 0
This commit is contained in:
Jo
2023-10-09 16:07:28 +02:00
committed by GitHub
parent 8bf914ac0b
commit 8919cafcb4
12 changed files with 145 additions and 25 deletions
+18
View File
@@ -87,3 +87,21 @@ func IntIdentifier(namespace, identifier string) (int64, error) {
return 0, ErrNotIntIdentifier
}
// UserIdentifier converts a string identifier to an int64.
// Errors if the identifier is not initialized or if namespace is not recognized.
// Returns 0 if the namespace is not user or service account
func UserIdentifier(namespace, identifier string) (int64, error) {
userID, err := IntIdentifier(namespace, identifier)
if err != nil {
// FIXME: return this error once entity namespaces are handled by stores
return 0, nil
}
switch namespace {
case NamespaceUser, NamespaceServiceAccount:
return userID, nil
}
return 0, nil
}