1
0
Fork 0
mirror of https://github.com/binwiederhier/ntfy.git synced 2024-12-15 17:50:55 +00:00

More review stuff

This commit is contained in:
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 {
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 {
return errHTTPBadRequestSignupNotEnabled
} else if u != nil {
@ -445,11 +445,11 @@ func (s *Server) handleAccountReservationAdd(w http.ResponseWriter, r *http.Requ
return errHTTPBadRequestPermissionInvalid
}
// Check if we are allowed to reserve this topic
if u.User() && u.Tier == nil {
if u.IsUser() && u.Tier == nil {
return errHTTPUnauthorized
} else if err := s.userManager.CheckAllowAccess(u.Name, req.Topic); err != nil {
return errHTTPConflictTopicReserved
} else if u.User() {
} else if u.IsUser() {
hasReservation, err := s.userManager.HasReservation(u.Name, req.Topic)
if err != nil {
return err

View file

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