mirror of
https://github.com/mainflux/mainflux.git
synced 2025-05-02 22:17:10 +08:00

* remove owner id Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix groups sdk Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix groups sdk Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix groups sdk Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * small fix, revert some changes Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix test fail Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix unassign request Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * decouple util method form group repo Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * resolve comments Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com> * fix param parsing Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
163 lines
3.0 KiB
Go
163 lines
3.0 KiB
Go
package groups
|
|
|
|
import (
|
|
"github.com/mainflux/mainflux/auth"
|
|
"github.com/mainflux/mainflux/pkg/errors"
|
|
)
|
|
|
|
type createGroupReq struct {
|
|
token string
|
|
Name string `json:"name,omitempty"`
|
|
ParentID string `json:"parent_id,omitempty"`
|
|
Description string `json:"description,omitempty"`
|
|
Metadata map[string]interface{} `json:"metadata,omitempty"`
|
|
}
|
|
|
|
func (req createGroupReq) validate() error {
|
|
if req.token == "" {
|
|
return auth.ErrUnauthorizedAccess
|
|
}
|
|
if len(req.Name) > maxNameSize || req.Name == "" {
|
|
return errors.Wrap(auth.ErrMalformedEntity, auth.ErrBadGroupName)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type updateGroupReq struct {
|
|
token string
|
|
id string
|
|
Name string `json:"name,omitempty"`
|
|
Description string `json:"description,omitempty"`
|
|
Metadata map[string]interface{} `json:"metadata,omitempty"`
|
|
}
|
|
|
|
func (req updateGroupReq) validate() error {
|
|
if req.token == "" {
|
|
return auth.ErrUnauthorizedAccess
|
|
}
|
|
|
|
if req.id == "" {
|
|
return auth.ErrMalformedEntity
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type listGroupsReq struct {
|
|
token string
|
|
id string
|
|
level uint64
|
|
// - `true` - result is JSON tree representing groups hierarchy,
|
|
// - `false` - result is JSON array of groups.
|
|
tree bool
|
|
metadata auth.GroupMetadata
|
|
}
|
|
|
|
func (req listGroupsReq) validate() error {
|
|
if req.token == "" {
|
|
return auth.ErrUnauthorizedAccess
|
|
}
|
|
|
|
if req.level > auth.MaxLevel || req.level < auth.MinLevel {
|
|
return auth.ErrMaxLevelExceeded
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type listMembersReq struct {
|
|
token string
|
|
id string
|
|
groupType string
|
|
offset uint64
|
|
limit uint64
|
|
tree bool
|
|
metadata auth.GroupMetadata
|
|
}
|
|
|
|
func (req listMembersReq) validate() error {
|
|
if req.token == "" {
|
|
return auth.ErrUnauthorizedAccess
|
|
}
|
|
|
|
if req.id == "" {
|
|
return auth.ErrMalformedEntity
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type listMembershipsReq struct {
|
|
token string
|
|
id string
|
|
offset uint64
|
|
limit uint64
|
|
tree bool
|
|
metadata auth.GroupMetadata
|
|
}
|
|
|
|
func (req listMembershipsReq) validate() error {
|
|
if req.token == "" {
|
|
return auth.ErrUnauthorizedAccess
|
|
}
|
|
|
|
if req.id == "" {
|
|
return auth.ErrMalformedEntity
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type assignReq struct {
|
|
token string
|
|
groupID string
|
|
Type string `json:"type,omitempty"`
|
|
Members []string `json:"members"`
|
|
}
|
|
|
|
func (req assignReq) validate() error {
|
|
if req.token == "" {
|
|
return auth.ErrUnauthorizedAccess
|
|
}
|
|
|
|
if req.Type == "" || req.groupID == "" || len(req.Members) == 0 {
|
|
return auth.ErrMalformedEntity
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type unassignReq struct {
|
|
assignReq
|
|
}
|
|
|
|
func (req unassignReq) validate() error {
|
|
if req.token == "" {
|
|
return auth.ErrUnauthorizedAccess
|
|
}
|
|
|
|
if req.groupID == "" || len(req.Members) == 0 {
|
|
return auth.ErrMalformedEntity
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type groupReq struct {
|
|
token string
|
|
id string
|
|
}
|
|
|
|
func (req groupReq) validate() error {
|
|
if req.token == "" {
|
|
return auth.ErrUnauthorizedAccess
|
|
}
|
|
|
|
if req.id == "" {
|
|
return auth.ErrMalformedEntity
|
|
}
|
|
|
|
return nil
|
|
}
|