group

package
v0.0.0-...-01681b2 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2018 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const MAXREQUEST int = 100

Variables

View Source
var (
	ErrNestedGroupUnsupported     = errors.New("Nested Group is unsupported")
	ErrGroupIncludingFailed       = errors.New("Group cycle not allowed, or group depth exceeding the limit")
	ErrBackendGroupShouldBeAtomic = errors.New("Backend group is atomic")
)
View Source
var (
	ErrGroupNotFound      = errors.New("Group not found")
	ErrBackendUnsupported = errors.New("unsupported backend type")
)

Functions

func DeleteGroup

func DeleteGroup(ctx *models.Context, group *Group) error

1. 作为子组:从多个父节点删掉该组 2. 作为父组:删掉多个与子组的关联关系 3. 删掉 groupdepth 表项 4. 删掉 member 5. 删掉 group 表项

func EnableNestedGroup

func EnableNestedGroup()

func GetAdminIdsOfGroup

func GetAdminIdsOfGroup(ctx *models.Context, gId int) ([]int, error)

func GetGroupsOfUserByIds

func GetGroupsOfUserByIds(ctx *models.Context, userIds []int) (map[int][]Group, error)

direct groups of the users, for now it is used only in "管理员特供"

func GroupCanBeNested

func GroupCanBeNested() bool

func InitDatabase

func InitDatabase(ctx *models.Context)

func ListAdminFathersOfGroups

func ListAdminFathersOfGroups(ctx *models.Context, sonIds []int) ([]int, error)

func ListFathersOfGroups

func ListFathersOfGroups(ctx *models.Context, sonIds []int) ([]int, error)

func NewTestHelper

func NewTestHelper(t *testing.T) testhelper.TestHelper

func RemoveUserFromAllGroups

func RemoveUserFromAllGroups(ctx *models.Context, user iuser.User) error

func SetMaxDepth

func SetMaxDepth(depth int)

Types

type Group

type Group struct {
	Id       int
	Name     string
	FullName string
	Created  string
	Updated  string

	GroupType iuser.GroupType `db:"backend"` // default is 0 for ssolib-mysql
}

func CreateGroup

func CreateGroup(ctx *models.Context, group *Group) (*Group, error)

func GetAllDateBaseGroup

func GetAllDateBaseGroup(ctx *models.Context) (*Group, error)

func GetGroup

func GetGroup(ctx *models.Context, id int) (*Group, error)

func GetGroupByName

func GetGroupByName(ctx *models.Context, name string) (*Group, error)

func GetGroupsOfUser

func GetGroupsOfUser(ctx *models.Context, user iuser.User) ([]Group, error)

must be recursive to find out all the groups

func ListGroupFathersById

func ListGroupFathersById(ctx *models.Context, gId int) ([]Group, error)

func ListGroups

func ListGroups(ctx *models.Context, ids ...int) ([]Group, error)

func (*Group) AddGroupMember

func (g *Group) AddGroupMember(ctx *models.Context, son *Group, role MemberRole) error

should be sure that the son is not a direct son for the father yet for all methods modify the groupdepth or groupdag's primary key, we must protect it by lock

func (*Group) AddGroupMemberWithoutLock

func (g *Group) AddGroupMemberWithoutLock(ctx *models.Context, son *Group, role MemberRole) error

func (*Group) AddMember

func (g *Group) AddMember(ctx *models.Context, user iuser.User, role MemberRole) error

func (*Group) GetGroupMembersID

func (g *Group) GetGroupMembersID(ctx *models.Context) ([]int, error)

func (*Group) GetMember

func (g *Group) GetMember(ctx *models.Context, u iuser.User) (ok bool, role MemberRole, err error)

Return (true, role, nil) if u is member of g, otherwise return (false, 0, nil). error will be non-nil if anything unexpected happens. Must considering recursive if valid

func (*Group) ListGroupMembers

func (g *Group) ListGroupMembers(ctx *models.Context) ([]GroupMember, error)

func (*Group) ListMembers

func (g *Group) ListMembers(ctx *models.Context) ([]Member, error)

not recursive for nested groups

func (*Group) RemoveGroupMember

func (g *Group) RemoveGroupMember(ctx *models.Context, son *Group) error

son must be a son of this group

func (*Group) RemoveGroupMemberWithoutLock

func (g *Group) RemoveGroupMemberWithoutLock(ctx *models.Context, son *Group) error

func (*Group) RemoveMember

func (g *Group) RemoveMember(ctx *models.Context, user iuser.User) error

func (*Group) UpdateGroupMemberRole

func (g *Group) UpdateGroupMemberRole(ctx *models.Context, son *Group, role MemberRole) error

son must be a son of this group

func (*Group) UpdateMember

func (g *Group) UpdateMember(ctx *models.Context, user iuser.User, role MemberRole) error

type GroupDepth

type GroupDepth struct {
	GroupId int `db:"group_id"`
	Depth   int
}

type GroupMember

type GroupMember struct {
	Group
	Role MemberRole // the role of this group which is a son for some group
}

type GroupRole

type GroupRole struct {
	Group
	Role MemberRole // some user's role in the group
}

func GetGroupRolesDirectlyOfUser

func GetGroupRolesDirectlyOfUser(ctx *models.Context, user iuser.User) ([]GroupRole, error)

func GetGroupRolesOfUser

func GetGroupRolesOfUser(ctx *models.Context, user iuser.User) ([]GroupRole, error)

should be recursive, but may be slow if we find recursive roles

type GroupUser

type GroupUser struct {
	GroupId int `db:"group_id"`
	UserId  int `db:"user_id"`
	Role    MemberRole
}

type Member

type Member struct {
	iuser.User
	Role MemberRole
}

type MemberRole

type MemberRole int8
const (
	NORMAL MemberRole = iota
	ADMIN
)

func GetGroupMemberRole

func GetGroupMemberRole(ctx *models.Context, fatherId int, sonId int) (role MemberRole, err error)

func GetRoleOfUser

func GetRoleOfUser(mctx *models.Context, uId int, gId int) (MemberRole, error)

Jump to

Keyboard shortcuts

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