You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
synctv/internal/model/relation.go

59 lines
1.1 KiB
Go

package model
import "time"
2 years ago
type RoomRole uint32
const (
2 years ago
RoomRoleBanned RoomRole = iota + 1
RoomRoleUser
RoomRoleCreator
)
type Permission uint32
const (
CanRenameRoom Permission = 1 << iota
CanSetAdmin
CanSetRoomPassword
CanSetRoomSetting
CanSetUserPermission
CanSetUserPassword
CanCreateUserPublishKey
CanEditUserMovies
CanDeleteUserMovies
CanCreateMovie
CanChangeCurrentMovie
CanChangeMovieStatus
CanDeleteRoom
AllPermissions Permission = 0xffffffff
)
const (
DefaultPermissions = CanCreateMovie | CanChangeCurrentMovie | CanChangeMovieStatus
)
func (p Permission) Has(permission Permission) bool {
return p&permission == permission
}
type RoomUserRelation struct {
CreatedAt time.Time
UpdatedAt time.Time
UserID string `gorm:"not null;primarykey"`
RoomID string `gorm:"not null;primarykey"`
2 years ago
Role RoomRole `gorm:"not null"`
Permissions Permission
}
func (r *RoomUserRelation) HasPermission(permission Permission) bool {
switch r.Role {
case RoomRoleCreator:
return true
case RoomRoleUser:
return r.Permissions.Has(permission)
default:
return false
}
}