implement basic acl operations and tests
This commit is contained in:
30
internal/acl/models.go
Normal file
30
internal/acl/models.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package acl
|
||||
|
||||
type UserRole struct {
|
||||
UserID uint `gorm:"primaryKey" json:"userId"`
|
||||
RoleID uint `gorm:"primaryKey" json:"roleId"`
|
||||
|
||||
Role Role `gorm:"constraint:OnDelete:CASCADE;foreignKey:RoleID;references:ID" json:"role"`
|
||||
//User user.User `gorm:"constraint:OnDelete:CASCADE;foreignKey:UserID;references:ID"`
|
||||
}
|
||||
|
||||
type Resource struct {
|
||||
ID uint `gorm:"primaryKey;autoIncrement" json:"id"`
|
||||
Key string `gorm:"unique;not null" json:"key"`
|
||||
}
|
||||
|
||||
type Role struct {
|
||||
ID uint `gorm:"primaryKey;autoIncrement" json:"id"`
|
||||
Name string `gorm:"unique;not null" json:"name"`
|
||||
|
||||
Resources []Resource `gorm:"many2many:role_resources" json:"resources"`
|
||||
//Users []user.User `gorm:"many2many:user_roles"`
|
||||
}
|
||||
|
||||
type RoleResource struct {
|
||||
RoleID uint `gorm:"primaryKey" json:"roleId"`
|
||||
ResourceID uint `gorm:"primaryKey" json:"resourceId"`
|
||||
|
||||
Role Role `gorm:"constraint:OnDelete:CASCADE;foreignKey:RoleID;references:ID" json:"role"`
|
||||
Resource Resource `gorm:"constraint:OnDelete:CASCADE;foreignKey:ResourceID;references:ID" json:"resource"`
|
||||
}
|
||||
Reference in New Issue
Block a user