routing

package
v0.0.0-...-07a32c6 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2021 License: GPL-3.0 Imports: 9 Imported by: 4

Documentation

Index

Constants

View Source
const DELETE int = 4

DELETE for delete level permissions

View Source
const READ int = 1

READ for read level pemissions

View Source
const WRITE int = 2

WRITE for write level permissions

Variables

View Source
var AppRouter *mux.Router

AppRouter - used to control routing throughout the app

Config - used for access to config properties

Functions

func AddGenericRoute

func AddGenericRoute(path string, handler func(writer http.ResponseWriter, request *http.Request))

AddGenericRoute - Adds a route that listens for any requst method

func AddRouteWithMethod

func AddRouteWithMethod(path string, method string, handler func(writer http.ResponseWriter, request *http.Request))

AddRouteWithMethod - Adds a route where you can specify the HTTP request method the route listens on

func AddUserResourceLevel

func AddUserResourceLevel(perm Permission) error

AddUserResourceLevel creates a user permission level for a resource

func AddValidatedRouteWithMethod

func AddValidatedRouteWithMethod(path string, method string, handler http.HandlerFunc)

AddValidatedRouteWithMethod - Adds a middleware-validated route where you can specify the HTTP request method the route listens on

func DeletePermissionByRole

func DeletePermissionByRole(roleID int) error

DeletePermissionByRole deletes all user permisisons for a specific role

func DeleteResourceLevel

func DeleteResourceLevel(userID int, resourceID int, roleID int) error

DeleteResourceLevel deletes the user resource level

func DeleteResourceLevelByRole

func DeleteResourceLevelByRole(resourceID int, roleID int) error

DeleteResourceLevelByRole deletes all of a single resource's permissions for a role

func FetchResourceIDByName

func FetchResourceIDByName(name string) (int, error)

FetchResourceIDByName returns a resource record's id associated with the given name

func PermissionLevel

func PermissionLevel(resourceName string, userID int) (int, error)

PermissionLevel will tell you what permission level the users has for a given resource 1 - Read 2 - Write 4 - Delete

eg 3 = Read and Write, 5 = Read and Delete, 6 = Write and Delete (weird), 7 = Full permissions

func UpdateResourceLevelByRole

func UpdateResourceLevelByRole(roleID int, resourceID int, level int) error

UpdateResourceLevelByRole updates user permissions for a role

func ValidateAdmin

func ValidateAdmin(next http.HandlerFunc) http.HandlerFunc

ValidateAdmin is middleware for validating whether or not the user is an admin user

func ValidateLevel

func ValidateLevel(next http.HandlerFunc, levelRequired int) http.HandlerFunc

ValidateLevel confirms that the user has read-access to the resource defined by the first element of the path. i.e. "user" in /user/do/stuff

Types

type Claims

type Claims struct {
	IsAdmin bool `json:"isAdmin"`
	UserID  int  `json:"userID"`
	jwt.StandardClaims
}

Claims contains infomation to embed in the token

type Permission

type Permission struct {
	UserID     int `json:"userID"`
	ResourceID int `json:"resourceID"`
	Level      int `json:"level"`
	RoleID     int `json:"roleID"`
}

Permission tells you the user's level of access to a resource

func FetchAllUserPermissions

func FetchAllUserPermissions(userID int) ([]Permission, error)

FetchAllUserPermissions returns all resource levels for a given user

func FetchUserResourcePermission

func FetchUserResourcePermission(userID int, resourceID int) (Permission, error)

FetchUserResourcePermission returns the highest level for a given user and resource

func UpdateResourceLevel

func UpdateResourceLevel(perm Permission) (Permission, error)

UpdateResourceLevel updates a user permission level for a resource

Jump to

Keyboard shortcuts

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