Files
b0esche_cloud/go_cloud/internal/permission/permission.go
Leon Bösche e10e499b6c Backend: Fix organization API endpoints and RBAC
- Fix member list API response format to match frontend expectations
- Fix join requests API response format
- Add proper JSON tags to Invitation struct
- Grant OrgManage permission to admin role for proper RBAC

These changes ensure frontend-backend API contracts are aligned and admins can manage organizations.
2026-01-23 23:48:10 +01:00

48 lines
1.1 KiB
Go

package permission
import (
"context"
"fmt"
"go.b0esche.cloud/backend/internal/database"
"github.com/google/uuid"
)
type Permission string
const (
FileRead Permission = "file.read"
FileWrite Permission = "file.write"
FileDelete Permission = "file.delete"
DocumentView Permission = "document.view"
DocumentEdit Permission = "document.edit"
OrgManage Permission = "org.manage"
)
var rolePermissions = map[string][]Permission{
"owner": {FileRead, FileWrite, FileDelete, DocumentView, DocumentEdit, OrgManage},
"admin": {FileRead, FileWrite, FileDelete, DocumentView, DocumentEdit, OrgManage},
"member": {FileRead, DocumentView},
}
// HasPermission checks if user has permission in org
func HasPermission(ctx context.Context, db *database.DB, userID, orgID uuid.UUID, perm Permission) (bool, error) {
membership, err := db.GetUserMembership(ctx, userID, orgID)
if err != nil {
return false, err
}
perms, ok := rolePermissions[membership.Role]
if !ok {
return false, fmt.Errorf("unknown role: %s", membership.Role)
}
for _, p := range perms {
if p == perm {
return true, nil
}
}
return false, nil
}