More review stuff

pull/526/head
binwiederhier 2023-02-09 21:51:12 -05:00
parent d8dd4c92bf
commit 79f9e78c37
2 changed files with 7 additions and 7 deletions

View File

@ -20,7 +20,7 @@ const (
func (s *Server) handleAccountCreate(w http.ResponseWriter, r *http.Request, v *visitor) error { func (s *Server) handleAccountCreate(w http.ResponseWriter, r *http.Request, v *visitor) error {
u := v.User() u := v.User()
if !u.Admin() { // u may be nil, but that's fine if !u.IsAdmin() { // u may be nil, but that's fine
if !s.config.EnableSignup { if !s.config.EnableSignup {
return errHTTPBadRequestSignupNotEnabled return errHTTPBadRequestSignupNotEnabled
} else if u != nil { } else if u != nil {
@ -445,11 +445,11 @@ func (s *Server) handleAccountReservationAdd(w http.ResponseWriter, r *http.Requ
return errHTTPBadRequestPermissionInvalid return errHTTPBadRequestPermissionInvalid
} }
// Check if we are allowed to reserve this topic // Check if we are allowed to reserve this topic
if u.User() && u.Tier == nil { if u.IsUser() && u.Tier == nil {
return errHTTPUnauthorized return errHTTPUnauthorized
} else if err := s.userManager.CheckAllowAccess(u.Name, req.Topic); err != nil { } else if err := s.userManager.CheckAllowAccess(u.Name, req.Topic); err != nil {
return errHTTPConflictTopicReserved return errHTTPConflictTopicReserved
} else if u.User() { } else if u.IsUser() {
hasReservation, err := s.userManager.HasReservation(u.Name, req.Topic) hasReservation, err := s.userManager.HasReservation(u.Name, req.Topic)
if err != nil { if err != nil {
return err return err

View File

@ -32,13 +32,13 @@ func (u *User) TierID() string {
return u.Tier.ID return u.Tier.ID
} }
// Admin returns true if the user is an admin // IsAdmin returns true if the user is an admin
func (u *User) Admin() bool { func (u *User) IsAdmin() bool {
return u != nil && u.Role == RoleAdmin return u != nil && u.Role == RoleAdmin
} }
// User returns true if the user is a regular user, not an admin // IsUser returns true if the user is a regular user, not an admin
func (u *User) User() bool { func (u *User) IsUser() bool {
return u != nil && u.Role == RoleUser return u != nil && u.Role == RoleUser
} }