Feat v0.9.9 surface access roles (#83)
All checks were successful
CI/CD / detect-changes (push) Successful in 3s
CI/CD / test-runners (push) Has been skipped
CI/CD / e2e-smoke (push) Has been skipped
CI/CD / test-frontend (push) Successful in 5s
CI/CD / test-go-pg (push) Successful in 2m49s
CI/CD / test-sqlite (push) Successful in 2m59s
CI/CD / build-and-deploy (push) Successful in 1m28s
All checks were successful
CI/CD / detect-changes (push) Successful in 3s
CI/CD / test-runners (push) Has been skipped
CI/CD / e2e-smoke (push) Has been skipped
CI/CD / test-frontend (push) Successful in 5s
CI/CD / test-go-pg (push) Successful in 2m49s
CI/CD / test-sqlite (push) Successful in 2m59s
CI/CD / build-and-deploy (push) Successful in 1m28s
Co-authored-by: Jeffrey Smith <jasafpro@gmail.com> Co-committed-by: Jeffrey Smith <jasafpro@gmail.com>
This commit was merged in pull request #83.
This commit is contained in:
@@ -522,7 +522,7 @@ func (e *Engine) RenderExtensionSurface() gin.HandlerFunc {
|
||||
}
|
||||
|
||||
// ── Access check ─────────────────────────────────────────
|
||||
if !evaluateAccess(c, surfaceAccess) {
|
||||
if !e.evaluateAccess(c, surfaceAccess) {
|
||||
// Redirect unauthenticated users to login; deny others with 403
|
||||
if c.GetString("user_id") == "" {
|
||||
c.Redirect(http.StatusTemporaryRedirect, e.cfg.BasePath+"/login")
|
||||
@@ -651,7 +651,7 @@ func aggregateAccess(surfaces []any) string {
|
||||
}
|
||||
|
||||
// evaluateAccess checks whether the current request meets an access requirement.
|
||||
func evaluateAccess(c *gin.Context, access string) bool {
|
||||
func (e *Engine) evaluateAccess(c *gin.Context, access string) bool {
|
||||
switch {
|
||||
case access == "public":
|
||||
return true
|
||||
@@ -672,6 +672,20 @@ func evaluateAccess(c *gin.Context, access string) bool {
|
||||
}
|
||||
}
|
||||
return false
|
||||
case strings.HasPrefix(access, "role:"):
|
||||
role := strings.TrimPrefix(access, "role:")
|
||||
userID := c.GetString("user_id")
|
||||
if userID == "" {
|
||||
return false
|
||||
}
|
||||
if c.GetBool("is_admin") {
|
||||
return true
|
||||
}
|
||||
if e.stores.Teams == nil {
|
||||
return false
|
||||
}
|
||||
has, err := e.stores.Teams.HasRoleInAnyTeam(c.Request.Context(), userID, role)
|
||||
return err == nil && has
|
||||
default:
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user