Documentation ¶
Overview ¶
Package groups contains the domain concept definitions needed to support Magistrala groups functionality.
Index ¶
Constants ¶
const ( Disabled = "disabled" Enabled = "enabled" Deleted = "deleted" All = "all" Unknown = "unknown" )
String representation of the possible status values.
const MaxLevel = uint64(5)
MaxLevel represents the maximum group hierarchy level.
Variables ¶
var ( // ErrInvalidStatus indicates invalid status. ErrInvalidStatus = errors.New("invalid groups status") // ErrEnableGroup indicates error in enabling group. ErrEnableGroup = errors.New("failed to enable group") // ErrDisableGroup indicates error in disabling group. ErrDisableGroup = errors.New("failed to disable group") )
Functions ¶
This section is empty.
Types ¶
type Group ¶
type Group struct { ID string `json:"id"` Domain string `json:"domain_id,omitempty"` Parent string `json:"parent_id,omitempty"` Name string `json:"name"` Description string `json:"description,omitempty"` Metadata Metadata `json:"metadata,omitempty"` Level int `json:"level,omitempty"` Path string `json:"path,omitempty"` Children []*Group `json:"children,omitempty"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at,omitempty"` UpdatedBy string `json:"updated_by,omitempty"` Status Status `json:"status"` Permissions []string `json:"permissions,omitempty"` }
Group represents the group of Clients. Indicates a level in tree hierarchy. Root node is level 1. Path in a tree consisting of group IDs Paths are unique per domain.
type MembersPage ¶
type MembersPage struct { Total uint64 `json:"total"` Offset uint64 `json:"offset"` Limit uint64 `json:"limit"` Members []Member `json:"members"` }
Memberships contains page related metadata as well as list of memberships that belong to this page.
type Metadata ¶ added in v0.15.0
type Metadata map[string]interface{}
Metadata represents arbitrary JSON.
type Page ¶
type Page struct { PageMeta Path string Level uint64 ParentID string Permission string ListPerms bool Direction int64 // ancestors (+1) or descendants (-1) Groups []Group }
Page contains page related metadata as well as list of Groups that belong to the page.
type PageMeta ¶
type PageMeta struct { Total uint64 `json:"total"` Offset uint64 `json:"offset"` Limit uint64 `json:"limit"` Name string `json:"name,omitempty"` ID string `json:"id,omitempty"` DomainID string `json:"domain_id,omitempty"` Tag string `json:"tag,omitempty"` Metadata Metadata `json:"metadata,omitempty"` Status Status `json:"status,omitempty"` }
PageMeta contains page metadata that helps navigation.
type Repository ¶
type Repository interface { // Save group. Save(ctx context.Context, g Group) (Group, error) // Update a group. Update(ctx context.Context, g Group) (Group, error) // RetrieveByID retrieves group by its id. RetrieveByID(ctx context.Context, id string) (Group, error) // RetrieveAll retrieves all groups. RetrieveAll(ctx context.Context, gm Page) (Page, error) // RetrieveByIDs retrieves group by ids and query. RetrieveByIDs(ctx context.Context, gm Page, ids ...string) (Page, error) // ChangeStatus changes groups status to active or inactive ChangeStatus(ctx context.Context, group Group) (Group, error) // AssignParentGroup assigns parent group id to a given group id AssignParentGroup(ctx context.Context, parentGroupID string, groupIDs ...string) error // UnassignParentGroup unassign parent group id fr given group id UnassignParentGroup(ctx context.Context, parentGroupID string, groupIDs ...string) error // Delete a group Delete(ctx context.Context, groupID string) error }
Repository specifies a group persistence API.
type Service ¶
type Service interface { // CreateGroup creates new group. CreateGroup(ctx context.Context, session authn.Session, kind string, g Group) (Group, error) // UpdateGroup updates the group identified by the provided ID. UpdateGroup(ctx context.Context, session authn.Session, g Group) (Group, error) // ViewGroup retrieves data about the group identified by ID. ViewGroup(ctx context.Context, session authn.Session, id string) (Group, error) // ViewGroupPerms retrieves permissions on the group id for the given authorized token. ViewGroupPerms(ctx context.Context, session authn.Session, id string) ([]string, error) // ListGroups retrieves a list of groups basesd on entity type and entity id. ListGroups(ctx context.Context, session authn.Session, memberKind, memberID string, gm Page) (Page, error) // ListMembers retrieves everything that is assigned to a group identified by groupID. ListMembers(ctx context.Context, session authn.Session, groupID, permission, memberKind string) (MembersPage, error) // EnableGroup logically enables the group identified with the provided ID. EnableGroup(ctx context.Context, session authn.Session, id string) (Group, error) // DisableGroup logically disables the group identified with the provided ID. DisableGroup(ctx context.Context, session authn.Session, id string) (Group, error) // DeleteGroup delete the given group id DeleteGroup(ctx context.Context, session authn.Session, id string) error // Assign member to group Assign(ctx context.Context, session authn.Session, groupID, relation, memberKind string, memberIDs ...string) (err error) // Unassign member from group Unassign(ctx context.Context, session authn.Session, groupID, relation, memberKind string, memberIDs ...string) (err error) }
type Status ¶ added in v0.15.0
type Status uint8
Status represents User status.
const ( // EnabledStatus represents enabled User. EnabledStatus Status = iota // DisabledStatus represents disabled User. DisabledStatus // DeletedStatus represents a user that will be deleted. DeletedStatus // AllStatus is used for querying purposes to list users irrespective // of their status - both enabled and disabled. It is never stored in the // database as the actual User status and should always be the largest // value in this enumeration. AllStatus )
Possible User status values.
func (Status) MarshalJSON ¶ added in v0.15.0
Custom Marshaller for Uesr/Groups.
func (*Status) UnmarshalJSON ¶ added in v0.15.0
Custom Unmarshaler for User/Groups.