|
|
|
@ -5,6 +5,7 @@ import (
|
|
|
|
|
|
|
|
|
|
"github.com/synctv-org/synctv/internal/db"
|
|
|
|
|
"github.com/synctv-org/synctv/internal/model"
|
|
|
|
|
"github.com/synctv-org/synctv/internal/settings"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type User struct {
|
|
|
|
@ -12,6 +13,14 @@ type User struct {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (u *User) CreateRoom(name, password string, conf ...db.CreateRoomConfig) (*model.Room, error) {
|
|
|
|
|
if u.IsBanned() {
|
|
|
|
|
return nil, errors.New("user banned")
|
|
|
|
|
}
|
|
|
|
|
if !u.IsAdmin() && settings.CreateRoomNeedReview.Get() {
|
|
|
|
|
conf = append(conf, db.WithStatus(model.RoomStatusPending))
|
|
|
|
|
} else {
|
|
|
|
|
conf = append(conf, db.WithStatus(model.RoomStatusActive))
|
|
|
|
|
}
|
|
|
|
|
return db.CreateRoom(name, password, append(conf, db.WithCreator(&u.User))...)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -27,7 +36,7 @@ func (u *User) IsRoot() bool {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (u *User) IsAdmin() bool {
|
|
|
|
|
return u.Role >= model.RoleAdmin
|
|
|
|
|
return u.Role == model.RoleAdmin || u.IsRoot()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (u *User) IsBanned() bool {
|
|
|
|
|