mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-07-13 00:52:01 -04:00
* JMAP query limit of 0 is synonymous with "no limit", but we actually want to be able to perform queries without any results, for cases where we only want to count the total number of objects, and also because it makes more sense semantically * introduce query parameter validation checks, in order to only allow query parameters that are actually supported, which is going to be useful during development of clients
53 lines
2.4 KiB
Go
53 lines
2.4 KiB
Go
package jmap
|
|
|
|
var NS_PRINCIPALS = ns(JmapPrincipals)
|
|
|
|
func (j *Client) GetPrincipals(accountId string, ids []string, ctx Context) (PrincipalGetResponse, SessionState, State, Language, Error) {
|
|
return get(j, "GetPrincipals", PrincipalType,
|
|
func(accountId string, ids []string) PrincipalGetCommand {
|
|
return PrincipalGetCommand{AccountId: accountId, Ids: ids}
|
|
},
|
|
PrincipalGetResponse{},
|
|
identity1,
|
|
accountId, ids,
|
|
ctx,
|
|
)
|
|
}
|
|
|
|
type PrincipalSearchResults SearchResultsTemplate[Principal]
|
|
|
|
var _ SearchResults[Principal] = &PrincipalSearchResults{}
|
|
|
|
func (r *PrincipalSearchResults) GetResults() []Principal { return r.Results }
|
|
func (r *PrincipalSearchResults) GetCanCalculateChanges() bool { return r.CanCalculateChanges }
|
|
func (r *PrincipalSearchResults) GetPosition() uint { return r.Position }
|
|
func (r *PrincipalSearchResults) GetLimit() *uint { return r.Limit }
|
|
func (r *PrincipalSearchResults) GetTotal() *uint { return r.Total }
|
|
func (r *PrincipalSearchResults) RemoveResults() { r.Results = nil }
|
|
func (r *PrincipalSearchResults) SetLimit(limit *uint) { r.Limit = limit }
|
|
|
|
func (j *Client) QueryPrincipals(accountId string,
|
|
filter PrincipalFilterElement, sortBy []PrincipalComparator,
|
|
position uint, limit *uint, calculateTotal bool,
|
|
ctx Context) (*PrincipalSearchResults, SessionState, State, Language, Error) {
|
|
return query(j, "QueryPrincipals", PrincipalType,
|
|
[]PrincipalComparator{{Property: PrincipalPropertyName, IsAscending: true}},
|
|
func(filter PrincipalFilterElement, sortBy []PrincipalComparator, position uint, limit *uint) PrincipalQueryCommand {
|
|
return PrincipalQueryCommand{AccountId: accountId, Filter: filter, Sort: sortBy, Position: position, Limit: limit, CalculateTotal: calculateTotal}
|
|
},
|
|
func(cmd Command, path string, rof string) PrincipalGetRefCommand {
|
|
return PrincipalGetRefCommand{AccountId: accountId, IdsRef: &ResultReference{Name: cmd, Path: path, ResultOf: rof}}
|
|
},
|
|
func(query PrincipalQueryResponse, get PrincipalGetResponse) *PrincipalSearchResults {
|
|
return &PrincipalSearchResults{
|
|
Results: get.List,
|
|
CanCalculateChanges: query.CanCalculateChanges,
|
|
Position: query.Position,
|
|
Total: ptrIf(query.Total, calculateTotal),
|
|
Limit: ptrIf(query.Limit, limit != nil),
|
|
}
|
|
},
|
|
filter, sortBy, limit, position, ctx,
|
|
)
|
|
}
|