team

package module
v0.0.32 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2024 License: MIT Imports: 11 Imported by: 1

README

Team Package

The 'Team' package empowers administrators to create specialized teams with diverse users and roles tailored for distinct domains. Specific roles, assigned with precise permissions, ensure efficient collaboration and task assignment within each team. With our Teams package, administrators can effortlessly create and manage specialized teams within Golang projects, fostering efficient collaboration and task delegation across various domains.

Features

  • Team package provides functionalities to list, create, update, and delete user accounts and team members.
  • These functions ensure data integrity by validating user information such as email addresses, phone numbers, and usernames.
  • Users can securely change their passwords, while administrators can check if specific roles are already assigned.
  • Detailed user information is retrievable, and users have the autonomy to update their own profiles.

Installation

go get github.com/spurtcms/team

Usage Example

func main(){
	
	//authsetup automatically migrate auth related tables in your databases=.
	Auth := auth.AuthSetup(auth.Config{
		UserId:     1,
		ExpiryTime: 2,
		SecretKey:  "SecretKey@123",
		RoleId: 1,
		DB: &gorm.DB{},
	})

	token, _ := Auth.CreateToken()

	Auth.VerifyToken(token, SecretKey)

	permisison, _ := Auth.IsGranted("Team", auth.CRUD, 1)

	//Teamsetup automatically migrate team related tables in your database.
	team := teams.TeamSetup(teams.Config{
		DB:               &gorm.DB{},
		AuthEnable:       true,
		PermissionEnable: true,
		Auth:             Auth,
	})
	
	if permisison {

		teamuser, count, err := team.ListUser(10, 0, teams.Filters{},1)
		//handle error
		fmt.Println(teamuser,count,err)
		
		//create user- TeamCreate struct we have multiple fields for creating user
		user,cerr:=team.CreateUser(teams.TeamCreate{FirstName: "demo", RoleId: 1, Email: "mailto:demo@gmail.com",TenantId: 1})
		//handle error
		fmt.Println(user,cerr)

		//update user- TeamCreate struct we have multiple fields for update user
		user1,uerr:=team.UpdateUser(teams.TeamCreate{FirstName: "demo1", RoleId: 2, Email: "mailto:demo1@gmail.com"}, 1,1)
		//handle error
		fmt.Println(user1,uerr)

		//delete user
		err1:=team.DeleteUser([]int{},1,1,1)
		//handle error
		fmt.Println(err1)

		
	}else{
	
		fmt.Println("unauthroized")
	}
	
}

Getting help

If you encounter a problem with the package,please refer [Please refer [(https://www.spurtcms.com/documentation/cms-admin)] or you can create a new Issue in this repo[https://github.com/spurtcms/team/issues].

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorAuth       = errors.New("auth enabled not initialised")
	ErrorPermission = errors.New("permissions enabled not initialised")
	ErrorValidation = errors.New("given some values is empty")
	TenantId, _     = strconv.Atoi(os.Getenv("Tenant_ID"))
)

error variables

Functions

func AuthandPermission

func AuthandPermission(team *Teams) error

Types

type Config

type Config struct {
	DB               *gorm.DB
	AuthEnable       bool
	PermissionEnable bool
	DataBaseType     Type
	Auth             *auth.Auth
}

type Filters

type Filters struct {
	Keyword   string
	Category  string
	Status    string
	FromDate  string
	ToDate    string
	FirstName string
}

type TblMstrTenant added in v0.0.11

type TblMstrTenant struct {
	Id            int       `gorm:"primaryKey;auto_increment;type:serial"`
	TenantId      int       `gorm:"type:integer"`
	S3StoragePath string    `gorm:"type:character varying"`
	DeletedOn     time.Time `gorm:"type:timestamp without time zone;DEFAULT:NULL"`
	DeletedBy     int       `gorm:"type:integer;DEFAULT:NULL"`
	IsDeleted     int       `gorm:"type:integer;DEFAULT:0"`
}

type TblUser

type TblUser struct {
	Id                   int       `gorm:"column:id"`
	Uuid                 string    `gorm:"column:uuid"`
	FirstName            string    `gorm:"column:first_name"`
	LastName             string    `gorm:"column:last_name"`
	RoleId               int       `gorm:"column:role_id"`
	Email                string    `gorm:"column:email"`
	Username             string    `gorm:"column:username"`
	Password             string    `gorm:"column:password"`
	MobileNo             string    `gorm:"column:mobile_no"`
	IsActive             int       `gorm:"column:is_active"`
	ProfileImage         string    `gorm:"column:profile_image"`
	ProfileImagePath     string    `gorm:"column:profile_image_path"`
	StorageType          string    `gorm:"column:storage_type"`
	DataAccess           int       `gorm:"column:data_access"`
	CreatedOn            time.Time `gorm:"column:created_on"`
	CreatedBy            int       `gorm:"column:created_by"`
	ModifiedOn           time.Time `gorm:"column:modified_on;DEFAULT:NULL"`
	ModifiedBy           int       `gorm:"column:modified_by;DEFAULT:NULL"`
	LastLogin            time.Time `gorm:"column:last_login;DEFAULT:NULL"`
	IsDeleted            int       `gorm:"column:is_deleted"`
	DeletedOn            time.Time `gorm:"column:deleted_on;DEFAULT:NULL"`
	DeletedBy            int       `gorm:"column:deleted_by;DEFAULT:NULL"`
	ModuleName           string    `gorm:"-"`
	RouteName            string    `gorm:"-:migration;<-:false"`
	DisplayName          string    `gorm:"-:migration;<-:false"`
	Description          string    `gorm:"-"`
	ModuleId             int       `gorm:"-:migration;<-:false"`
	PermissionId         int       `gorm:"-"`
	FullAccessPermission int       `gorm:"-:migration;<-:false"`
	RoleName             string    `gorm:"-:migration;<-:false"`
	DefaultLanguageId    int       `gorm:"column:default_language_id"`
	NameString           string    `gorm:"-"`
	TenantId             int
	Otp                  int       `gorm:"column:otp"`
	OtpExpiry            time.Time `gorm:"column:otp_expiry;DEFAULT:NULL"`
	NameLength           int       `gorm:"-:migration;<-:false"`
	LimitedLengthName    string    `gorm:"-:migration;<-:false"`
	S3FolderName         string    `gorm:"column:s3_folder_name"`
}

type Team added in v0.0.10

type Team struct {
	Id         int
	Limit      int
	Offset     int
	Keyword    string
	FirstName  string
	TenantId   int
	IsActive   bool
	CreateOnly bool
	Count      bool
	Role       bool
	EmailId    string
}

type TeamCreate

type TeamCreate struct {
	FirstName         string
	LastName          string
	RoleId            int
	Email             string
	Username          string
	Password          string
	IsActive          int
	DataAccess        int
	MobileNo          string
	ProfileImage      string
	ProfileImagePath  string
	CreatedBy         int
	StorageType       string
	TenantId          int
	S3FolderPath      string
	DefaultLanguageId int
}

type TeamModel

type TeamModel struct {
	Dataaccess int
	Userid     int
}

func (TeamModel) ChangeAccess

func (t TeamModel) ChangeAccess(user *TblUser, userIds []int, DB *gorm.DB, tenantid int) error

change selected user access

func (TeamModel) ChangeActiveUser

func (t TeamModel) ChangeActiveUser(user *TblUser, userId int, DB *gorm.DB, tenantid int) error

change active status

func (TeamModel) ChangePasswordById added in v0.0.4

func (t TeamModel) ChangePasswordById(user *TblUser, DB *gorm.DB, tenantid int) error

func (TeamModel) ChangeStatusForTenants added in v0.0.28

func (t TeamModel) ChangeStatusForTenants(userStatus *TblUser, userIds []int, DB *gorm.DB) error

func (TeamModel) CheckEmail

func (t TeamModel) CheckEmail(user *TblUser, email string, userid int, DB *gorm.DB, tenantid int) error

func (TeamModel) CheckNumber

func (t TeamModel) CheckNumber(user *TblUser, mobile string, userid int, DB *gorm.DB, tenantid int) error

func (TeamModel) CheckRoleUsed

func (t TeamModel) CheckRoleUsed(user *TblUser, roleid int, DB *gorm.DB, tenantid int) error

Rolechekc

func (TeamModel) CheckUsername

func (t TeamModel) CheckUsername(user *TblUser, username string, userid int, DB *gorm.DB, tenantid int) error

check username

func (TeamModel) CheckValidation

func (t TeamModel) CheckValidation(user *TblUser, email, username, mobile string, userid int, DB *gorm.DB, tenantid int) error

func (TeamModel) CreateTenantid added in v0.0.11

func (t TeamModel) CreateTenantid(user *TblMstrTenant, DB *gorm.DB) (int, error)

func (TeamModel) CreateUser

func (t TeamModel) CreateUser(user *TblUser, DB *gorm.DB) (team TblUser, terr error)

This func will help to create a user in your database

func (TeamModel) DeleteMultipleUser

func (t TeamModel) DeleteMultipleUser(user *TblUser, usersIds []int, userid int, DB *gorm.DB, tenantid int) error

func (TeamModel) DeleteTenantusers added in v0.0.28

func (t TeamModel) DeleteTenantusers(user *TblUser, usersIds []int, userid int, DB *gorm.DB) error

delete only tenant users

func (TeamModel) DeleteUser

func (t TeamModel) DeleteUser(user *TblUser, DB *gorm.DB, tenantid int) error

delete team user

func (TeamModel) GetAdminRoleUsers added in v0.0.4

func (t TeamModel) GetAdminRoleUsers(roleid []int, DB *gorm.DB, tenantid int) (userlist []TblUser, err error)

func (TeamModel) GetTenantDetails added in v0.0.25

func (t TeamModel) GetTenantDetails(tenantId int, DB *gorm.DB) (tenantDetails TblUser, err error)

func (TeamModel) GetUserById

func (t TeamModel) GetUserById(id int, ids []int, DB *gorm.DB) (user TblUser, users []TblUser, err error)

getuserbyid

func (TeamModel) GetUserByRole added in v0.0.11

func (t TeamModel) GetUserByRole(RoleId int, MobileNo string, DB *gorm.DB) (id int, err error)

function to get user id by role id,mobile number from db

func (TeamModel) GetUserDetails added in v0.0.10

func (team TeamModel) GetUserDetails(DB *gorm.DB, inputs Team, user *TblUser) error

func (TeamModel) GetUserDetailsTeam

func (t TeamModel) GetUserDetailsTeam(user *TblUser, id int, DB *gorm.DB, tenantid int) error

func (TeamModel) GetUsersList

func (t TeamModel) GetUsersList(offset, limit int, filter Filters, flag bool, createonly bool, DB *gorm.DB, tenantid int) (users []TblUser, count int64, err error)

get the list of users

func (TeamModel) Lastlogin

func (t TeamModel) Lastlogin(id int, log_time time.Time, DB *gorm.DB, tenantid int) error

user last login update

func (TeamModel) NewuserCount added in v0.0.3

func (t TeamModel) NewuserCount(DB *gorm.DB, tenantid int) (count int64, err error)

func (TeamModel) SelectedUserStatusChange

func (t TeamModel) SelectedUserStatusChange(userStatus *TblUser, userIds []int, DB *gorm.DB, tenantid int) error

func (TeamModel) UpdateImageDetails added in v0.0.25

func (t TeamModel) UpdateImageDetails(userId int, imageName, imagePath string, DB *gorm.DB) error

func (TeamModel) UpdateMyuser added in v0.0.5

func (t TeamModel) UpdateMyuser(user *TblUser, DB *gorm.DB, tenantid int) error

func (TeamModel) UpdateS3FolderName added in v0.0.25

func (t TeamModel) UpdateS3FolderName(tenantId, userId int, s3FolderPath string, DB *gorm.DB) error

func (TeamModel) UpdateTenantId added in v0.0.11

func (t TeamModel) UpdateTenantId(UserId int, Tenantid int, DB *gorm.DB) error

func (TeamModel) UpdateUser

func (t TeamModel) UpdateUser(user *TblUser, DB *gorm.DB, tenantid int) (team TblUser, terr error)

update user

func (TeamModel) UserCount added in v0.0.3

func (t TeamModel) UserCount(DB *gorm.DB, tenantid int) (count int64, err error)

type Teams

type Teams struct {
	DB               *gorm.DB
	AuthEnable       bool
	PermissionEnable bool
	Authenticate     auth.Authentication
	Auth             *auth.Auth
	Userid           int
	Dataaccess       int
}

func TeamSetup

func TeamSetup(config Config) *Teams

Channelsetup used to initialie channel configuration

func (*Teams) ChangeAccess

func (team *Teams) ChangeAccess(userIds []int, modifiedby int, status int, tenantid int) error

change user Access for multiple user

func (*Teams) ChangeActiveStatus

func (team *Teams) ChangeActiveStatus(userId int, activeStatus int, modifiedby int, tenantid int) (bool, error)

change active status

func (*Teams) ChangeStatusForTenants added in v0.0.28

func (team *Teams) ChangeStatusForTenants(userIds []int, activeStatus int, modifiedby int) error

change active Status for multiple users

func (*Teams) ChangeYourPassword added in v0.0.4

func (team *Teams) ChangeYourPassword(password string, userid int, tenantid int) (success bool, err error)

func (*Teams) CheckEmail

func (team *Teams) CheckEmail(Email string, userid int, tenantid int) (users TblUser, checl bool, errr error)

check email is already exists in your database

func (*Teams) CheckNumber

func (team *Teams) CheckNumber(mobile string, userid int, tenantid int) (bool, error)

check mobile

func (*Teams) CheckPasswordwithOld

func (team *Teams) CheckPasswordwithOld(userid int, password string, tenantid int) (bool, error)

check new password with old password if it's return false it does not match to the old password or return true it does match to the old password

func (*Teams) CheckRoleUsed

func (team *Teams) CheckRoleUsed(roleid int, tenantid int) (bool, error)

Check role already used or not

func (*Teams) CheckUserValidation

func (team *Teams) CheckUserValidation(mobile string, email string, username string, userid int, tenantid int) (emaill bool, users bool, mobiles bool, err error)

Check username,email,number exsits or not validation

func (*Teams) CheckUsername

func (team *Teams) CheckUsername(username string, userid int, tenantid int) (bool, error)

check username

func (*Teams) CreateTenantid added in v0.0.11

func (team *Teams) CreateTenantid(user TblMstrTenant) (int, error)

func (*Teams) CreateUser

func (team *Teams) CreateUser(teamcreate TeamCreate) (createuser TblUser, UserId int, terr error)

CreateUser create for your admin login.

func (*Teams) DashboardUserCount added in v0.0.3

func (team *Teams) DashboardUserCount(tenantid int) (totalcount int, lasttendayscount int, err error)

Dashboard usercount function

func (*Teams) DeleteTenantusers added in v0.0.28

func (team *Teams) DeleteTenantusers(usersIds []int, userid int, deletedby int) error

delete only tenant users

func (*Teams) DeleteUser

func (team *Teams) DeleteUser(usersIds []int, userid int, deletedby int, tenantid int) error

delete user.

func (*Teams) GetAdminRoleUsers added in v0.0.4

func (team *Teams) GetAdminRoleUsers(roleid []int, tenantid int) (userlist []TblUser, err error)

function to get the admin roles users list

func (*Teams) GetTenantDetails added in v0.0.25

func (team *Teams) GetTenantDetails(tenantId int) (tenantDetails TblUser, err error)

func (*Teams) GetUserById

func (team *Teams) GetUserById(Userid int, Userids []int) (tbluser TblUser, users []TblUser, err error)

get team by id

func (*Teams) LastLoginActivity

func (team *Teams) LastLoginActivity(userid int, tenantid int) (err error)

Logout Last Active

func (*Teams) ListUser

func (team *Teams) ListUser(limit, offset int, filter Filters, Tenantid int) (tbluserr []TblUser, totoaluser int64, err error)

get the all list users

func (*Teams) SelectedUserStatusChange

func (team *Teams) SelectedUserStatusChange(userIds []int, activeStatus int, modifiedby int, tenantid int) error

change active Status for multiple users

func (*Teams) UpdateImageDetails added in v0.0.25

func (team *Teams) UpdateImageDetails(userId int, imageName, imagepath string) (err error)

func (*Teams) UpdateMyUser added in v0.0.5

func (team *Teams) UpdateMyUser(userupdate TeamCreate, userid int, tenantid int) error

func (*Teams) UpdateS3FolderName added in v0.0.25

func (team *Teams) UpdateS3FolderName(tenantId, userId int, s3FolderPath string) error

func (*Teams) UpdateTenantId added in v0.0.11

func (team *Teams) UpdateTenantId(UserId int, Tenantid int)

func (*Teams) UpdateUser

func (team *Teams) UpdateUser(teamcreate TeamCreate, userid int, tenantid int) (createuser TblUser, terr error)

update user.

func (*Teams) UserDetails added in v0.0.10

func (team *Teams) UserDetails(inputs Team) (UserDetails TblUser, err error)

type Type

type Type string
const (
	Postgres Type = "postgres"
	Mysql    Type = "mysql"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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