service

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2023 License: MIT Imports: 8 Imported by: 8

Documentation

Index

Constants

View Source
const (
	UserServiceContextKey domain.ContextKey = "user_service"

	SystemAdminLoginID = "__system_admin"
	SystemOwnerLoginID = "__system_owner"

	SystemOwnerGroupKey = "__system_owner"
	OwnerGroupKey       = "__owner"

	SystemOwnerGroupName = "System Owner"
	OwnerGroupName       = "Owner"
)

Variables

View Source
var ErrAppUserAlreadyExists = errors.New("AppUser already exists")
View Source
var ErrAppUserNotFound = errors.New("AppUser not found")
View Source
var ErrOrganizationAlreadyExists = errors.New("organization already exists")
View Source
var ErrOrganizationNotFound = errors.New("organization not found")
View Source
var ErrSystemOwnerNotFound = errors.New("SystemOwner not found")
View Source
var RBACAllowEffect = domain.NewRBACEffect("allow")
View Source
var RBACDenyEffect = domain.NewRBACEffect("deny")
View Source
var RBACSetAction = domain.NewRBACAction("Set")
View Source
var RBACUnsetAction = domain.NewRBACAction("Unset")

Functions

func NewRBACAllUserRolesObject

func NewRBACAllUserRolesObject(organizationID domain.OrganizationID) domain.RBACObject

func NewRBACAppUser

func NewRBACAppUser(organizationID domain.OrganizationID, appUserID domain.AppUserID) domain.RBACUser

func NewRBACOrganization

func NewRBACOrganization(organizationID domain.OrganizationID) domain.RBACDomain

func NewRBACUserRole

func NewRBACUserRole(organizationID domain.OrganizationID, userGroupID domain.UserGroupID) domain.RBACRole
func NewRBACUserRole(userRoleID domain.UserGroupID) domain.RBACRole {
	return domain.NewRBACRole(fmt.Sprintf("role_%d", userRoleID.Int()))
}

func NewRBACUserRoleObject

func NewRBACUserRoleObject(organizationID domain.OrganizationID, userRoleID domain.UserGroupID) domain.RBACObject

Types

type AppUser

type AppUser interface {
	domain.AppUserModel
}

func NewAppUser

func NewAppUser(ctx context.Context, rf RepositoryFactory, appUserModel domain.AppUserModel) (AppUser, error)

type AppUserAddParameter

type AppUserAddParameter interface {
	GetLoginID() string
	GetUsername() string
	GetPassword() string
}

func NewAppUserAddParameter

func NewAppUserAddParameter(loginID, username, password string,

) (AppUserAddParameter, error)

type AppUserRepository

type AppUserRepository interface {
	FindSystemOwnerByOrganizationID(ctx context.Context, operator domain.SystemAdminModel, organizationID domain.OrganizationID) (SystemOwner, error)

	FindSystemOwnerByOrganizationName(ctx context.Context, operator domain.SystemAdminModel, organizationName string, options ...Option) (SystemOwner, error)

	FindAppUserByID(ctx context.Context, operator domain.AppUserModel, id domain.AppUserID, options ...Option) (AppUser, error)

	FindAppUserByLoginID(ctx context.Context, operator domain.AppUserModel, loginID string) (AppUser, error)

	FindOwnerByLoginID(ctx context.Context, operator domain.SystemOwnerModel, loginID string) (Owner, error)

	AddAppUser(ctx context.Context, operator domain.OwnerModel, param AppUserAddParameter) (domain.AppUserID, error)

	AddSystemOwner(ctx context.Context, operator domain.SystemAdminModel, organizationID domain.OrganizationID) (domain.AppUserID, error)
}

type AuthorizationManager

type AuthorizationManager interface {
	AddUserToGroup(ctx context.Context, operator domain.AppUserModel, appUserID domain.AppUserID, userGroupID domain.UserGroupID) error

	AddUserToGroupBySystemAdmin(ctx context.Context, operator domain.SystemAdminModel, organizationID domain.OrganizationID, appUserID domain.AppUserID, userGroupID domain.UserGroupID) error

	AddPolicyToUser(ctx context.Context, operator domain.AppUserModel, subject domain.RBACSubject, action domain.RBACAction, object domain.RBACObject, effect domain.RBACEffect) error

	AddPolicyToUserBySystemAdmin(ctx context.Context, operator domain.SystemAdminModel, organizationID domain.OrganizationID, subject domain.RBACSubject, action domain.RBACAction, object domain.RBACObject, effect domain.RBACEffect) error

	AddPolicyToGroup(ctx context.Context, operator domain.AppUserModel, subject domain.RBACSubject, action domain.RBACAction, object domain.RBACObject, effect domain.RBACEffect) error

	AddPolicyToGroupBySystemAdmin(ctx context.Context, operator domain.SystemAdminModel, organizationID domain.OrganizationID, subject domain.RBACSubject, action domain.RBACAction, object domain.RBACObject, effect domain.RBACEffect) error

	Authorize(ctx context.Context, operator domain.AppUserModel, rbacAction domain.RBACAction, rbacObject domain.RBACObject) (bool, error)
}

type FirstOwnerAddParameter

type FirstOwnerAddParameter interface {
	GetLoginID() string
	GetUsername() string
	GetPassword() string
}

func NewFirstOwnerAddParameter

func NewFirstOwnerAddParameter(loginID, username, password string) (FirstOwnerAddParameter, error)

type Option

type Option string
var IncludeGroups Option = "IncludeGroups"

type Organization

type Organization interface {
	domain.OrganizationModel
}

func NewOrganization

func NewOrganization(organizationModel domain.OrganizationModel) (Organization, error)

type OrganizationAddParameter

type OrganizationAddParameter interface {
	GetName() string
	GetFirstOwner() FirstOwnerAddParameter
}

func NewOrganizationAddParameter

func NewOrganizationAddParameter(name string, firstOwner FirstOwnerAddParameter) (OrganizationAddParameter, error)

type OrganizationRepository

type OrganizationRepository interface {
	GetOrganization(ctx context.Context, operator domain.AppUserModel) (Organization, error)

	FindOrganizationByName(ctx context.Context, operator domain.SystemAdminModel, name string) (Organization, error)

	FindOrganizationByID(ctx context.Context, operator domain.SystemAdminModel, id domain.OrganizationID) (Organization, error)

	AddOrganization(ctx context.Context, operator domain.SystemAdminModel, param OrganizationAddParameter) (domain.OrganizationID, error)
}

type Owner

type Owner interface {
	domain.OwnerModel
}

func NewOwner

func NewOwner(rf RepositoryFactory, ownerModel domain.OwnerModel) Owner

type PairOfUserAndGroupRepository

type PairOfUserAndGroupRepository interface {
	AddPairOfUserAndGroupBySystemAdmin(ctx context.Context, operator domain.SystemAdminModel, organizationID domain.OrganizationID, appUserID domain.AppUserID, userGroupID domain.UserGroupID) error

	AddPairOfUserAndGroup(ctx context.Context, operator domain.AppUserModel, appUserID domain.AppUserID, userGroupID domain.UserGroupID) error

	RemovePairOfUserAndGroup(ctx context.Context, operator domain.AppUserModel, appUserID domain.AppUserID, userGroupID domain.UserGroupID) error

	FindUserGroupsByUserID(ctx context.Context, operator domain.AppUserModel, appUserID domain.AppUserID) ([]domain.UserGroupModel, error)
}

type RBACRepository

type RBACRepository interface {
	Init() error

	AddPolicy(domain domain.RBACDomain, subject domain.RBACSubject, action domain.RBACAction, object domain.RBACObject, effect domain.RBACEffect) error

	AddSubjectGroupingPolicy(domain domain.RBACDomain, subject domain.RBACUser, object domain.RBACRole) error
	AddObjectGroupingPolicy(domain domain.RBACDomain, child domain.RBACObject, parent domain.RBACObject) error

	RemovePolicy(domain domain.RBACDomain, subject domain.RBACSubject, action domain.RBACAction, object domain.RBACObject, effect domain.RBACEffect) error

	RemoveSubjectGroupingPolicy(domain domain.RBACDomain, subject domain.RBACUser, object domain.RBACRole) error
	RemoveObjectGroupingPolicy(domain domain.RBACDomain, child domain.RBACObject, parent domain.RBACObject) error

	NewEnforcerWithGroupsAndUsers(roles []domain.RBACRole, users []domain.RBACUser) (*casbin.Enforcer, error)
}

type RepositoryFactory

type RepositoryFactory interface {
	NewOrganizationRepository(ctx context.Context) OrganizationRepository
	NewAppUserRepository(ctx context.Context) AppUserRepository
	NewUserGroupRepository(ctx context.Context) UserGroupRepository

	NewAuthorizationManager(ctx context.Context) AuthorizationManager
}

type SystemAdmin

type SystemAdmin interface {
	domain.SystemAdminModel

	FindSystemOwnerByOrganizationID(ctx context.Context, organizationID domain.OrganizationID) (SystemOwner, error)

	FindSystemOwnerByOrganizationName(ctx context.Context, organizationName string) (SystemOwner, error)

	FindOrganizationByName(ctx context.Context, name string) (Organization, error)

	AddOrganization(ctx context.Context, parma OrganizationAddParameter) (domain.OrganizationID, error)
}

func NewSystemAdmin

func NewSystemAdmin(ctx context.Context, rf RepositoryFactory) (SystemAdmin, error)

type SystemOwner

type SystemOwner interface {
	domain.SystemOwnerModel

	GetOrganization(ctxc context.Context) (Organization, error)

	FindAppUserByID(ctx context.Context, id domain.AppUserID) (AppUser, error)

	FindAppUserByLoginID(ctx context.Context, loginID string) (AppUser, error)

	AddFirstOwner(ctx context.Context, param FirstOwnerAddParameter) (domain.AppUserID, error)
}

func NewSystemOwner

func NewSystemOwner(ctx context.Context, rf RepositoryFactory, systemOwnerModel domain.SystemOwnerModel) (SystemOwner, error)

type TransactionManager

type TransactionManager interface {
	Do(ctx context.Context, fn func(rf RepositoryFactory) error) error
}

type UserGroup

type UserGroup interface {
	domain.UserGroupModel
}

func NewUserGroup

func NewUserGroup(userGroupModel domain.UserGroupModel) (UserGroup, error)

NewUserGroup returns a new UserGroup

type UserGroupAddParameter

type UserGroupAddParameter interface {
	GetKey() string
	GetName() string
	GetDescription() string
}

func NewUserGroupAddParameter

func NewUserGroupAddParameter(key, name, description string) (UserGroupAddParameter, error)

type UserGroupRepository

type UserGroupRepository interface {
	FindAllUserGroups(ctx context.Context, operator domain.AppUserModel) ([]domain.UserGroupModel, error)

	FindSystemOwnerGroup(ctx context.Context, operator domain.SystemAdminModel, organizationID domain.OrganizationID) (UserGroup, error)

	FindUserGroupByKey(ctx context.Context, operator domain.AppUserModel, key string) (UserGroup, error)
	FindUserGroupByID(ctx context.Context, operator domain.AppUserModel, userGroupID domain.UserGroupID) (UserGroup, error)
	AddOwnerGroup(ctx context.Context, operator domain.SystemAdminModel, organizationID domain.OrganizationID) (domain.UserGroupID, error)

	AddSystemOwnerGroup(ctx context.Context, operator domain.SystemAdminModel, organizationID domain.OrganizationID) (domain.UserGroupID, error)

	AddUserGroup(ctx context.Context, operator domain.OwnerModel, parameter UserGroupAddParameter) (domain.UserGroupID, error)
}

Jump to

Keyboard shortcuts

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