authority

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: May 8, 2024 License: MIT Imports: 7 Imported by: 0

README

An Example For A Goravel Extend Package

Directory Structure

This is a directory standard, but you can change it if you like.

Directory Action
commands Store the command files
config Store the config files
contracts Store the contract files
facades Store the facade files
root Store the service provider and package source code

Install

  1. Add package
go get -u github.com/agomezguru/authority
  1. Register service provider
// config/app.go
import authority "github.com/agomezguru/authority"

"providers": []foundation.ServiceProvider{
    ...
    &authority.ServiceProvider{},
}
  1. Publish Configuration
go run . artisan vendor:publish --package=github.com/agomezguru/authority
  1. Testing
// main.go
import authorityfacades "github.com/agomezguru/authority/facades"

fmt.Println(authorityfacades.Authority().World())

The console will print Welcome To Goravel Package.

Documentation

Index

Constants

View Source
const Binding = "agomezguru.authority"

Variables

Functions

This section is empty.

Types

type Authority

type Authority struct {
	// contains filtered or unexported fields
}

func NewAuthority

func NewAuthority(config config.Config) (*Authority, error)

func (*Authority) AssignPermissionsToRole added in v0.0.2

func (a *Authority) AssignPermissionsToRole(
	roleSlug string, permSlugs []string) error

Assigns a group of permissions to a given role it accepts the role slug as the first parameter, the second parameter is a slice of permission slugs (strings) to be assigned to the role. It returns an error in case of any. It returns an error in case the role does not exists. It returns an error in case any of the permissions does not exists. It returns an error in case any of the permissions is already assigned

func (*Authority) AssignRoleToUser added in v0.0.2

func (a *Authority) AssignRoleToUser(
	userID interface{}, roleSlug string) error

Assigns a role to a given user it accepts the user id as the first parameter the second parameter the role slug. It returns an error in case of any. It returns an error in case the role does not exists. It returns an error in case the role is already assigned

func (*Authority) CheckRolePermission added in v0.0.2

func (a *Authority) CheckRolePermission(
	roleSlug, permSlug string) (bool, error)

Checks if a permission is assigned to a role, it accepts in the role slug as the first parameter. The second parameter, the permission slug. It returns two parameters: the first parameter of the return is a boolean represents whether the permission is assigned or not; the second is an error in case of any. In case the role does not exists, an error is returned. in case the permission does not exists, an error is returned

func (*Authority) CheckUserPermission added in v0.0.2

func (a *Authority) CheckUserPermission(
	userID interface{}, roleSlug string) (bool, error)

Checks if a permission is assigned to a user it accepts in the user id as the first parameter, the second parameter the role slug. It returns two parameters: the first parameter of the return is a boolean represents whether the role is assigned or not, the second is an error in case of any In case the role does not exists, an error is returned

func (*Authority) CheckUserRole added in v0.0.2

func (a *Authority) CheckUserRole(
	userID interface{}, roleSlug string) (bool, error)

Checks if a role is assigned to a user it accepts the user id as the first parameter the second parameter the role slug. It returns two parameters the first parameter of the return is a boolean represents whether the role is assigned or not. The second is an error in case of any. In case the role does not exists, an error is returned

func (*Authority) CreatePermission added in v0.0.2

func (a *Authority) CreatePermission(p authority.Permission) error

Add a new permission to the database it accepts the Permission struct as a parameter it returns an error in case of any it returns an error if the permission is already exists

func (*Authority) CreateRole added in v0.0.2

func (a *Authority) CreateRole(r authority.Role) error

Add a new role to the database it accepts the Role struct as a parameter it returns an error in case of any it returns an error if the role is already exists

type ServiceProvider

type ServiceProvider struct {
}

func (*ServiceProvider) Boot

func (receiver *ServiceProvider) Boot(app foundation.Application)

func (*ServiceProvider) Register

func (receiver *ServiceProvider) Register(app foundation.Application)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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