mirror of
https://github.com/usememos/memos.git
synced 2026-11-19 10:29:11 +01:00
4f46523758
An active application ADMIN now passes every memo-local authorization check on named operations: authorship, audience, Space membership and participation, attachment and reaction ownership. Structural validity still applies, an archived admin holds no privilege, and collection listings keep the audience predicate so feeds never surface other users' private memos. - core/access: admin bypass in the read policy; CanManageMemo and CanManageAttachment as the shared author-level predicates. - store: drivers read the actor's role alongside its lifecycle state in the mutation transaction; validators accept an admin where they required the author or a member; shared attachment binding and removal predicates. - api: handlers use the shared predicates; admins may place memos in any existing Space and see a memo's Space by name. - web: one canManageMemo helper replaces the ad hoc creator checks. - docs: multi-spaces design revised in place; share RPC comments updated.
76 lines
1.6 KiB
Go
76 lines
1.6 KiB
Go
package v1
|
|
|
|
import (
|
|
"encoding/base64"
|
|
|
|
"github.com/pkg/errors"
|
|
"google.golang.org/protobuf/proto"
|
|
|
|
v1pb "github.com/usememos/memos/proto/gen/api/v1"
|
|
"github.com/usememos/memos/store"
|
|
)
|
|
|
|
const (
|
|
// DefaultPageSize is the default page size for requests.
|
|
DefaultPageSize = 50
|
|
// MaxPageSize is the maximum page size for requests.
|
|
MaxPageSize = 1000
|
|
)
|
|
|
|
func convertStateFromStore(rowStatus store.RowStatus) v1pb.State {
|
|
switch rowStatus {
|
|
case store.Normal:
|
|
return v1pb.State_NORMAL
|
|
case store.Archived:
|
|
return v1pb.State_ARCHIVED
|
|
default:
|
|
return v1pb.State_STATE_UNSPECIFIED
|
|
}
|
|
}
|
|
|
|
func convertStateToStore(state v1pb.State) store.RowStatus {
|
|
switch state {
|
|
case v1pb.State_ARCHIVED:
|
|
return store.Archived
|
|
default:
|
|
return store.Normal
|
|
}
|
|
}
|
|
|
|
func getPageToken(limit int, offset int) (string, error) {
|
|
return marshalPageToken(&v1pb.PageToken{
|
|
Limit: int32(limit),
|
|
Offset: int32(offset),
|
|
})
|
|
}
|
|
|
|
func normalizePageSize(pageSize int32) int {
|
|
limit := int(pageSize)
|
|
if limit <= 0 {
|
|
return DefaultPageSize
|
|
}
|
|
if limit > MaxPageSize {
|
|
return MaxPageSize
|
|
}
|
|
return limit
|
|
}
|
|
|
|
func marshalPageToken(pageToken *v1pb.PageToken) (string, error) {
|
|
b, err := proto.Marshal(pageToken)
|
|
if err != nil {
|
|
return "", errors.Wrapf(err, "failed to marshal page token")
|
|
}
|
|
return base64.StdEncoding.EncodeToString(b), nil
|
|
}
|
|
|
|
func unmarshalPageToken(s string, pageToken *v1pb.PageToken) error {
|
|
b, err := base64.StdEncoding.DecodeString(s)
|
|
if err != nil {
|
|
return errors.Wrapf(err, "failed to decode page token")
|
|
}
|
|
if err := proto.Unmarshal(b, pageToken); err != nil {
|
|
return errors.Wrapf(err, "failed to unmarshal page token")
|
|
}
|
|
return nil
|
|
}
|