Skip to content

Commit

Permalink
feat: handle superuser field in the API response
Browse files Browse the repository at this point in the history
  • Loading branch information
1995parham committed Nov 11, 2023
1 parent 6fed7b3 commit 4f0c72d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion internal/api/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,6 @@ func (a API) Authv2(c *fiber.Ctx) error {

return c.Status(http.StatusOK).JSON(authResponse{
Result: "allow",
IsSuperuser: false,
IsSuperuser: authenticator.IsSuperuser(),

Check warning on line 147 in internal/api/auth.go

View check run for this annotation

Codecov / codecov/patch

internal/api/auth.go#L147

Added line #L147 was not covered by tests
})
}
4 changes: 4 additions & 0 deletions internal/authenticator/admin_authenticator.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,7 @@ func (a AdminAuthenticator) ValidateAccessType(_ acl.AccessType) bool {
func (a AdminAuthenticator) GetCompany() string {
return a.Company

Check warning on line 59 in internal/authenticator/admin_authenticator.go

View check run for this annotation

Codecov / codecov/patch

internal/authenticator/admin_authenticator.go#L58-L59

Added lines #L58 - L59 were not covered by tests
}

func (a AdminAuthenticator) IsSuperuser() bool {
return true

Check warning on line 63 in internal/authenticator/admin_authenticator.go

View check run for this annotation

Codecov / codecov/patch

internal/authenticator/admin_authenticator.go#L62-L63

Added lines #L62 - L63 were not covered by tests
}
7 changes: 6 additions & 1 deletion internal/authenticator/authenticator.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import (
)

type Authenticator interface {
// Auth check user authentication by checking the user's token
// Auth check user authentication by checking the user's token.
// it retruns error in case of any issue with the user token.
Auth(tokenString string) error

// ACL check a user access to a topic.
Expand All @@ -20,4 +21,8 @@ type Authenticator interface {

// GetCompany Return the Company Field of The Inherited Objects
GetCompany() string

// IsSuperuser changes the Auth response in case of successful authentication
// and shows user as superuser which disables the ACL.
IsSuperuser() bool
}
4 changes: 4 additions & 0 deletions internal/authenticator/auto_authenticator.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,7 @@ func (a AutoAuthenticator) ValidateAccessType(accessType acl.AccessType) bool {
func (a AutoAuthenticator) GetCompany() string {
return a.Company
}

func (a AutoAuthenticator) IsSuperuser() bool {
return false

Check warning on line 104 in internal/authenticator/auto_authenticator.go

View check run for this annotation

Codecov / codecov/patch

internal/authenticator/auto_authenticator.go#L103-L104

Added lines #L103 - L104 were not covered by tests
}
4 changes: 4 additions & 0 deletions internal/authenticator/manual_authenticator.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,7 @@ func (a ManualAuthenticator) ValidateAccessType(accessType acl.AccessType) bool
func (a ManualAuthenticator) GetCompany() string {
return a.Company
}

func (a ManualAuthenticator) IsSuperuser() bool {
return false

Check warning on line 134 in internal/authenticator/manual_authenticator.go

View check run for this annotation

Codecov / codecov/patch

internal/authenticator/manual_authenticator.go#L133-L134

Added lines #L133 - L134 were not covered by tests
}

0 comments on commit 4f0c72d

Please sign in to comment.