More progress. Fixed storage bug. Need to get media stuff going
This commit is contained in:
Melody Becker 2024-11-05 16:29:01 +01:00
parent 1bb6cd8a70
commit 83f47d17be
11 changed files with 209 additions and 27 deletions

View file

@ -27,6 +27,11 @@ func StorageFromRequest(r *http.Request) *storage.Storage {
return store
}
func ActorIdFromRequest(r *http.Request) (string, bool) {
id, ok := r.Context().Value(ContextKeyActorId).(string)
return id, ok
}
func NoteIdFromRequest(r *http.Request) string {
return r.PathValue("noteId")
}
@ -34,3 +39,16 @@ func NoteIdFromRequest(r *http.Request) string {
func AccountIdFromRequest(r *http.Request) string {
return r.PathValue("accountId")
}
func CheckIfAccountIdHasPermissions(accId string, perms storage.Role, store *storage.Storage) bool {
acc, err := store.FindAccountById(accId)
if err != nil {
return false
}
roles, err := store.FindRolesByNames(acc.Roles)
if err != nil {
return false
}
collapsed := storage.CollapseRolesIntoOne(roles...)
return storage.CompareRoles(&collapsed, &perms)
}