memberaccess

package module
v0.0.9 Latest Latest
Warning

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

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

README

Member-access Package

The 'Member-access' package grants website admin the authority to provide access to the members.This streamlined process enables effortless audience management and curation, ensuring a personalized experience for each member within the website.

Features

Installation

go get github.com/spurtcms/Member-access

Usage example

import (
	"github.com/spurtcms/auth"
	"github.com/spurtcms/member-access"
)

func main() {

	Auth := auth.AuthSetup(auth.Config{
		UserId:     1,
		ExpiryTime: 2,
		SecretKey:  "SecretKey@123",
		DB: &gorm.DB{},
		RoleId: 1,
	})

	token, _ := Auth.CreateToken()

	Auth.VerifyToken(token, SecretKey)

	permisison, _ := Auth.IsGranted("Member Restrict", auth.CRUD)

	accesscontroller := access.AccessSetup(access.Config{
		DB:               &gorm.DB{},
		AuthEnable:       true,
		PermissionEnable: true,
		Auth:             Auth,
	})

	//contentaccess
	if permisison {

		//list contentaccess
         contentaccesslist, count, err := accesscontroller.ContentAccessList(10, 0, Filter{}, 1)

		if err != nil {

			panic(err)
		}		fmt.Println(contentaccesslist, count, err)

		//create contentaccess
		_,err := accesscontroller.CreateAccessControl("Demo Entries Access",1,1)

		if err != nil {

			panic(err)
		}

		// update contentaccess
	err := accesscontroller.UpdateAccessControl(1,"sports",1,1)

		if err != nil {

			panic(err)
		}

		// delete contentaccess
			err := accesscontroller.DeleteMemberAccessControl(2,1,1)

		if err != nil {

			panic(err)
		}


		// create restrictgroup
		err := accesscontroller.CreateRestrictGroup(1, []int{1, 2}, []int{1, 2, 3}, 1, 1)

	if err != nil {

		panic(err)
	}
	}

}

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/member-access/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")
	CurrentTime, _  = time.Parse("2006-01-02 15:04:05", time.Now().UTC().Format("2006-01-02 15:04:05"))
	Empty           string
	TenantId, _     = strconv.Atoi(os.Getenv("TENANT_ID"))
)

Functions

func AuthandPermission

func AuthandPermission(accessControl *AccessControl) error

func Migration

func Migration(db *gorm.DB)

func TruncateDescription

func TruncateDescription(description string, limit int) string

Types

type AccessControl

type AccessControl struct {
	DB               *gorm.DB
	AuthEnable       bool
	PermissionEnable bool
	Auth             *auth.Auth
	UserId           int
	DataAccess       int
}

func AccessSetup

func AccessSetup(config Config) *AccessControl

func (*AccessControl) ContentAccessList

func (access *AccessControl) ContentAccessList(limit int, offset int, filter Filter, tenantid int) (accesslist []Tblaccesscontrol, totalCount int64, err error)

List

func (*AccessControl) CreateAccessControl

func (access *AccessControl) CreateAccessControl(title string, ModifiedBy int, tenantid int) (accessdata TblAccessControl, aerr error)

Create Accesscontrol

func (*AccessControl) CreateRestrictEntries

func (access *AccessControl) CreateRestrictEntries(accessid int, membergroups []int, entryids []Entry, createdBy int, tenantid int) error

func (*AccessControl) CreateRestrictGroup

func (access *AccessControl) CreateRestrictGroup(accessid int, membergroups []int, ids []int, createdBy int, tenantid int) error

func (*AccessControl) CreateRestrictPage

func (access *AccessControl) CreateRestrictPage(accessid int, membergroups []int, ids []int, createdBy int) error

func (*AccessControl) CreateRestrictSubPage

func (access *AccessControl) CreateRestrictSubPage(accessid int, membergroups []int, ids []int, createdBy int) error

func (*AccessControl) DeleteMemberAccessControl

func (access *AccessControl) DeleteMemberAccessControl(accessid int, ModifiedBy int, tenantid int) error

Delete Accesscontrol

func (*AccessControl) DeleteSelectedSpaces

func (access *AccessControl) DeleteSelectedSpaces(accessid int, ids []int, DeletedBy int, tenantid int) error

func (*AccessControl) DeleteSeletedGroup

func (access *AccessControl) DeleteSeletedGroup(accessid int, ids []int, DeletedBy int, tenantid int) error

func (*AccessControl) DeleteSeletedPage

func (access *AccessControl) DeleteSeletedPage(accessid int, ids []int, DeletedBy int, tenantid int) error

func (*AccessControl) GetControlAccessById

func (access *AccessControl) GetControlAccessById(accessid int, tenantid int) (accesslist Tblaccesscontrol, err error)

Get Access by id

func (*AccessControl) GetaccessMemberGroup

func (access *AccessControl) GetaccessMemberGroup(accessid int, tenantid int) (group []int, err error)

function used to retrieve the access granted member group list

func (*AccessControl) GetselectedEntiresByAccessControlId

func (access *AccessControl) GetselectedEntiresByAccessControlId(accessid int, tenantid int) ([]int, []Entry, error)

func (*AccessControl) UpdateAccessControl

func (access *AccessControl) UpdateAccessControl(accessid int, title string, ModifiedBy int, tenantid int) error

func (*AccessControl) UpdateRestrictEntries

func (access *AccessControl) UpdateRestrictEntries(accessid int, membergroups []int, entryids []Entry, userid int, tenantid int) error

type AccessModel

type AccessModel struct {
	DataAccess int
	UserId     int
}
var Accessmodel AccessModel

func (AccessModel) CheckPresenceOfAccessGrantedMemberGroups

func (AccessModel) CheckPresenceOfAccessGrantedMemberGroups(count *int64, mem_id, accessId int, DB *gorm.DB, tenantid int) error

check membergroup access

func (AccessModel) CheckPresenceOfChannelEntriesInContentAccess

func (AccessModel) CheckPresenceOfChannelEntriesInContentAccess(count *int64, accessGroupId, chanId, entryId int, DB *gorm.DB, tenantid int) error

check access for enteries

func (AccessModel) CreateMemberGroupRestrict

func (AccessModel) CreateMemberGroupRestrict(access TblAccessControlUserGroup, DB *gorm.DB) (TblAccessControlUserGroup, error)

func (AccessModel) CreatePage

func (AccessModel) CreatePage(access *TblAccessControlPages, DB *gorm.DB) error

func (AccessModel) DeleteAccessControlPages

func (AccessModel) DeleteAccessControlPages(pg_access *TblAccessControlPages, Id []int, DB *gorm.DB, tenantid int) error

Delete Access Control Pages tbl

func (AccessModel) DeleteControlAccess

func (AccessModel) DeleteControlAccess(accesscontrol *TblAccessControl, id int, DB *gorm.DB, tenantid int) error

Delete Access Control tbl

func (AccessModel) DeleteGroup

func (AccessModel) DeleteGroup(pg_access *TblAccessControlPages, id []int, grpid []int, DB *gorm.DB, tenantid int) error

func (AccessModel) DeleteInAccessUserGroup

func (AccessModel) DeleteInAccessUserGroup(accessusergrp *TblAccessControlUserGroup, Id int, DB *gorm.DB, tenantid int) error

Delete Access Control User Group tbl

func (AccessModel) DeletePage

func (AccessModel) DeletePage(pg_access *TblAccessControlPages, id []int, pgids []int, DB *gorm.DB, tenantid int) error

func (AccessModel) DeleteSubPage

func (AccessModel) DeleteSubPage(pg_access *TblAccessControlPages, id []int, spacesid []int, DB *gorm.DB, tenantid int) error

func (AccessModel) GetAccessGrantedEntries

func (AccessModel) GetAccessGrantedEntries(AccessEntries *[]TblAccessControlPages, accessId int, DB *gorm.DB, tenantid int) error

func (AccessModel) GetAccessGrantedMemberGroups

func (AccessModel) GetAccessGrantedMemberGroups(memberGroups *[]TblAccessControlUserGroup, accessId int, DB *gorm.DB, tenantid int) error

func (AccessModel) GetAccessGrantedMemberGroupsList

func (AccessModel) GetAccessGrantedMemberGroupsList(memgrps *[]int, accessId int, DB *gorm.DB, tenantid int) error

get access membergroup

func (AccessModel) GetContentAccessByAccessId

func (AccessModel) GetContentAccessByAccessId(id int, DB *gorm.DB, tenantid int) (accesscontrol *Tblaccesscontrol, err error)

func (AccessModel) GetContentAccessList

func (AccessM AccessModel) GetContentAccessList(limit, offset int, filter Filter, DB *gorm.DB, tenantid int) (contentAccessList []Tblaccesscontrol, count int64, err error)

Get all content access list

func (AccessModel) GetDeleteIdInAccessUserGroup

func (AccessModel) GetDeleteIdInAccessUserGroup(controlaccessgrp *[]TblAccessControlUserGroup, Id int, DB *gorm.DB, tenantid int) (*[]TblAccessControlUserGroup, error)

To Get Deleted id in access control user group tbl

func (AccessModel) GetEntriesCountUnderChannel

func (AccessModel) GetEntriesCountUnderChannel(count *int64, channelId int, DB *gorm.DB, tenantid int) error

func (AccessModel) GetGroupsByAccessId

func (AccessModel) GetGroupsByAccessId(accessid int, DB *gorm.DB, tenantid int) (usergroups []TblAccessControlUserGroup, er error)

func (AccessModel) GetMemberGroupsByContentAccessMemId

func (AccessModel) GetMemberGroupsByContentAccessMemId(memgrp *member.TblMemberGroup, id int, DB *gorm.DB, tenantid int) error

func (AccessModel) GetMemberGrpByAccessControlId

func (AccessModel) GetMemberGrpByAccessControlId(memberGrpAccess *[]TblAccessControlUserGroup, content_access_id int, DB *gorm.DB, tenantid int) error

get member groupby acessid

func (AccessModel) GetSelectedEntries

func (AccessModel) GetSelectedEntries(accessId int, DB *gorm.DB, tenantid int) (contentAccessPages []Tblaccesscontrolpages, err error)

func (AccessModel) GetaccessGrantedEntriesCount

func (AccessModel) GetaccessGrantedEntriesCount(count *int64, accessId int, DB *gorm.DB, tenantid int) error

func (AccessModel) GetaccessGrantedPageCount

func (AccessModel) GetaccessGrantedPageCount(count *int64, accessId int, DB *gorm.DB, tenantid int) error

func (AccessModel) GrantAccessToMemberGroups

func (AccessModel) GrantAccessToMemberGroups(memberGrpAccess *TblAccessControlUserGroup, DB *gorm.DB, tenantid int) error

create member group access

func (AccessModel) NewContentAccessEntry

func (AccessModel) NewContentAccessEntry(contentAccess *TblAccessControl, DB *gorm.DB) error

Create Access

func (AccessModel) RemoveChannelEntriesNotUnderContentAccess

func (AccessModel) RemoveChannelEntriesNotUnderContentAccess(chanAccess *TblAccessControlPages, entryIds []int, DB *gorm.DB, tenantid int) error

remove access for entries

func (AccessModel) RemoveMemberGroupsNotUnderContentAccessRights

func (AccessModel) RemoveMemberGroupsNotUnderContentAccessRights(memgrp_access *TblAccessControlUserGroup, memgrp_array []int, access_id int, DB *gorm.DB) error

remove membergroup access

func (AccessModel) UpdateAccessPage

func (AccessModel) UpdateAccessPage(chanAccess *TblAccessControlPages, DB *gorm.DB, tenantid int) error

update accesspage

func (AccessModel) UpdateContentAccessId

func (AccessModel) UpdateContentAccessId(contentAccess *TblAccessControl, DB *gorm.DB, tenantid int) error

func (AccessModel) UpdateContentAccessMemberGroup

func (AccessModel) UpdateContentAccessMemberGroup(accessmemgrp *TblAccessControlUserGroup, DB *gorm.DB, tenantid int) error

update membergroup access

type Config

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

type Entry

type Entry struct {
	Id        string `json:"id"`
	ChannelId string `json:"channelId"`
	TenantId  int
}

type Filter

type Filter struct {
	Keyword string
}

type MemberAccessControlRequired

type MemberAccessControlRequired struct {
	Title          string
	Pages          []Page
	SubPage        []SubPage
	Group          []PageGroup
	SpacesIds      []int
	Channels       []int
	ChannelEntries []Entry
	MemberGroupIds []int
}

type Page

type Page struct {
	Id       string `json:"id"`
	GroupId  string `json:"groupId"`
	SpaceId  string `json:"spaceId"`
	TenantId int
}

type PageGroup

type PageGroup struct {
	Id       string `json:"id"`
	SpaceId  string `json:"spaceId"`
	TenantId int
}

type RestrictGroup

type RestrictGroup struct {
	AccessId  int
	GroupId   int
	GroupsIds []int
}

type RestrictPage

type RestrictPage struct {
	AccessId int
	PageId   int
	PageIds  []int
}

type RestrictSpace

type RestrictSpace struct {
	AccessId int
	SpaceId  int
	SpacesId []int
}

type SubPage

type SubPage struct {
	Id       string `json:"id"`
	GroupId  string `json:"groupId"`
	ParentId string `json:"parentId"`
	SpaceId  string `json:"spaceId"`
	TenantId int
}

type TblAccessControl

type TblAccessControl struct {
	Id                int       `gorm:"primaryKey;auto_increment;type:serial"`
	AccessControlName string    `gorm:"type:character varying"`
	AccessControlSlug string    `gorm:"type:character varying"`
	CreatedOn         time.Time `gorm:"type:timestamp without time zone"`
	CreatedBy         int       `gorm:"type:integer"`
	ModifiedOn        time.Time `gorm:"type:timestamp without time zone;DEFAULT:NULL"`
	ModifiedBy        int       `gorm:"DEFAULT:NULL"`
	IsDeleted         int       `gorm:"type:integer"`
	DeletedOn         time.Time `gorm:"type:timestamp without time zone;DEFAULT:NULL"`
	DeletedBy         int       `gorm:"DEFAULT:NULL"`
	TenantId          int       `gorm:"type:integer"`
}

type TblAccessControlPages

type TblAccessControlPages struct {
	Id                       int       `gorm:"primaryKey;auto_increment;type:serial"`
	AccessControlUserGroupId int       `gorm:"type:integer"`
	SpacesId                 int       `gorm:"type:integer"`
	PageGroupId              int       `gorm:"type:integer"`
	PageId                   int       `gorm:"type:integer"`
	CreatedOn                time.Time `gorm:"type:timestamp without time zone;DEFAULT:NULL"`
	CreatedBy                int       `gorm:"type:integer"`
	ModifiedOn               time.Time `gorm:"type:timestamp without time zone;DEFAULT:NULL"`
	ModifiedBy               int       `gorm:"DEFAULT:NULL"`
	IsDeleted                int       `gorm:"type:integer"`
	DeletedOn                time.Time `gorm:"type:timestamp without time zone;DEFAULT:NULL"`
	DeletedBy                int       `gorm:"DEFAULT:NULL"`
	ChannelId                int       `gorm:"type:integer"`
	EntryId                  int       `gorm:"type:integer"`
	TenantId                 int       `gorm:"type:integer"`
}

type TblAccessControlUserGroup

type TblAccessControlUserGroup struct {
	Id              int       `gorm:"primaryKey;auto_increment;type:serial"`
	AccessControlId int       `gorm:"type:integer"`
	MemberGroupId   int       `gorm:"type:integer"`
	CreatedOn       time.Time `gorm:"type:timestamp without time zone;DEFAULT:NULL"`
	CreatedBy       int       `gorm:"type:integer"`
	ModifiedOn      time.Time `gorm:"type:timestamp without time zone;DEFAULT:NULL"`
	ModifiedBy      int       `gorm:"DEFAULT:NULL"`
	IsDeleted       int       `gorm:"type:integer"`
	DeletedOn       time.Time `gorm:"type:timestamp without time zone;DEFAULT:NULL"`
	DeletedBy       int       `gorm:"DEFAULT:NULL"`
	TenantId        int       `gorm:"type:integer"`
}

type Tblaccesscontrol

type Tblaccesscontrol struct {
	Id                   int `gorm:"primaryKey;auto_increment"`
	AccessControlName    string
	AccessControlSlug    string
	CreatedOn            time.Time
	CreatedBy            int
	ModifiedOn           time.Time `gorm:"DEFAULT:NULL"`
	ModifiedBy           int       `gorm:"DEFAULT:NULL"`
	IsDeleted            int
	DeletedOn            time.Time               `gorm:"DEFAULT:NULL"`
	DeletedBy            int                     `gorm:"DEFAULT:NULL"`
	Username             string                  `gorm:"column:username;<-:false"`
	Rolename             string                  `gorm:"column:name;<-:false"`
	MemberGroups         []member.TblMemberGroup `gorm:"-"`
	DateString           string                  `gorm:"-"`
	AccessGrantedModules []string                `gorm:"-"`
	TenantId             int                     `gorm:"type:int"`
}

type Tblaccesscontrolpages

type Tblaccesscontrolpages struct {
	Id                       int `gorm:"primaryKey;auto_increment"`
	AccessControlUserGroupId int
	SpacesId                 int
	PageGroupId              int
	PageId                   int
	CreatedOn                time.Time
	CreatedBy                int
	ModifiedOn               time.Time `gorm:"DEFAULT:NULL"`
	ModifiedBy               int       `gorm:"DEFAULT:NULL"`
	IsDeleted                int
	DeletedOn                time.Time `gorm:"DEFAULT:NULL"`
	DeletedBy                int       `gorm:"DEFAULT:NULL"`
	ParentPageId             int       `gorm:"column:parent_id;<-:false"`
	ChannelId                int
	EntryId                  int
	TenantId                 int `gorm:"type:int"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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