User repository (#3795)
* It builds with the new user repository * fix(test): fix broken test * fix(api): fix registration endpoint that was broken after the change * fix(test): update test to reflect new user repository * fix: use interface type instead of concrete type * fix: restore commented out code
This commit is contained in:
11
models/auth.go
Normal file
11
models/auth.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package models
|
||||
|
||||
// Type represents a form of authentication.
|
||||
type AuthType string
|
||||
|
||||
// The different auth types we support.
|
||||
const (
|
||||
// IndieAuth https://indieauth.spec.indieweb.org/.
|
||||
IndieAuth AuthType = "indieauth"
|
||||
Fediverse AuthType = "fediverse"
|
||||
)
|
||||
12
models/chatAccessScopes.go
Normal file
12
models/chatAccessScopes.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package models
|
||||
|
||||
const (
|
||||
// ScopeCanSendChatMessages will allow sending chat messages as itself.
|
||||
ScopeCanSendChatMessages = "CAN_SEND_MESSAGES"
|
||||
// ScopeCanSendSystemMessages will allow sending chat messages as the system.
|
||||
ScopeCanSendSystemMessages = "CAN_SEND_SYSTEM_MESSAGES"
|
||||
// ScopeHasAdminAccess will allow performing administrative actions on the server.
|
||||
ScopeHasAdminAccess = "HAS_ADMIN_ACCESS"
|
||||
|
||||
ModeratorScopeKey = "MODERATOR"
|
||||
)
|
||||
19
models/externalAPIUser.go
Normal file
19
models/externalAPIUser.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// ExternalAPIUser represents a single 3rd party integration that uses an access token.
|
||||
// This struct mostly matches the User struct so they can be used interchangeably.
|
||||
type ExternalAPIUser struct {
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
LastUsedAt *time.Time `json:"lastUsedAt,omitempty"`
|
||||
ID string `json:"id"`
|
||||
AccessToken string `json:"accessToken"`
|
||||
DisplayName string `json:"displayName"`
|
||||
Type string `json:"type,omitempty"` // Should be API
|
||||
Scopes []string `json:"scopes"`
|
||||
DisplayColor int `json:"displayColor"`
|
||||
IsBot bool `json:"isBot"`
|
||||
}
|
||||
36
models/user.go
Normal file
36
models/user.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/owncast/owncast/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
moderatorScopeKey = "MODERATOR"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
DisabledAt *time.Time `json:"disabledAt,omitempty"`
|
||||
NameChangedAt *time.Time `json:"nameChangedAt,omitempty"`
|
||||
AuthenticatedAt *time.Time `json:"-"`
|
||||
ID string `json:"id"`
|
||||
DisplayName string `json:"displayName"`
|
||||
PreviousNames []string `json:"previousNames"`
|
||||
Scopes []string `json:"scopes,omitempty"`
|
||||
DisplayColor int `json:"displayColor"`
|
||||
IsBot bool `json:"isBot"`
|
||||
Authenticated bool `json:"authenticated"`
|
||||
}
|
||||
|
||||
// IsEnabled will return if this single user is enabled.
|
||||
func (u *User) IsEnabled() bool {
|
||||
return u.DisabledAt == nil
|
||||
}
|
||||
|
||||
// IsModerator will return if the user has moderation privileges.
|
||||
func (u *User) IsModerator() bool {
|
||||
_, hasModerationScope := utils.FindInSlice(u.Scopes, moderatorScopeKey)
|
||||
return hasModerationScope
|
||||
}
|
||||
Reference in New Issue
Block a user