groups

package
v0.14.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 29, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package groups contains the domain concept definitions needed to support Magistrala groups functionality.

Index

Constants

View Source
const MaxLevel = uint64(5)

MaxLevel represents the maximum group hierarchy level.

Variables

View Source
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")

	// ErrStatusAlreadyAssigned indicated that the group has already been assigned the status.
	ErrStatusAlreadyAssigned = errors.New("status already assigned")
)

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    clients.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      clients.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 Member

type Member struct {
	ID   string `json:"id"`
	Type string `json:"type"`
}

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 Page

type Page struct {
	PageMeta
	Path       string
	Level      uint64
	ID         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"`
	DomainID string           `json:"domain_id,omitempty"`
	Tag      string           `json:"tag,omitempty"`
	Metadata clients.Metadata `json:"metadata,omitempty"`
	Status   clients.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, token, kind string, g Group) (Group, error)

	// UpdateGroup updates the group identified by the provided ID.
	UpdateGroup(ctx context.Context, token string, g Group) (Group, error)

	// ViewGroup retrieves data about the group identified by ID.
	ViewGroup(ctx context.Context, token, id string) (Group, error)

	// ViewGroupPerms retrieves permissions on the group id for the given authorized token.
	ViewGroupPerms(ctx context.Context, token, id string) ([]string, error)

	// ListGroups retrieves
	ListGroups(ctx context.Context, token, memberKind, memberID string, gm Page) (Page, error)

	// ListMembers retrieves everything that is assigned to a group identified by groupID.
	ListMembers(ctx context.Context, token, groupID, permission, memberKind string) (MembersPage, error)

	// EnableGroup logically enables the group identified with the provided ID.
	EnableGroup(ctx context.Context, token, id string) (Group, error)

	// DisableGroup logically disables the group identified with the provided ID.
	DisableGroup(ctx context.Context, token, id string) (Group, error)

	// DeleteGroup delete the given group id
	DeleteGroup(ctx context.Context, token, id string) error

	// Assign member to group
	Assign(ctx context.Context, token, groupID, relation, memberKind string, memberIDs ...string) (err error)

	// Unassign member from group
	Unassign(ctx context.Context, token, groupID, relation, memberKind string, memberIDs ...string) (err error)
}

Directories

Path Synopsis
Package mocks contains mocks for testing purposes.
Package mocks contains mocks for testing purposes.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL