41 lines
1.2 KiB
Go
41 lines
1.2 KiB
Go
package permission
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"online-back/internal/appresult"
|
|
"online-back/internal/handlers"
|
|
"online-back/internal/identity/rbac"
|
|
"online-back/internal/identity/rbac/perm"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
const baseURL = "/permissions"
|
|
|
|
// handler serves the permission catalog. Permissions are defined in code
|
|
// (rbac/perm) - one per module - so there is nothing to create or edit here;
|
|
// roles pick from this list via POST/PUT /roles.
|
|
type handler struct{}
|
|
|
|
func NewHandler() handlers.Handler {
|
|
return &handler{}
|
|
}
|
|
|
|
func (h *handler) Register(router *gin.RouterGroup) {
|
|
group := rbac.Group(router, baseURL, rbac.RequireStaff(perm.Roles))
|
|
group.GET("", h.list)
|
|
}
|
|
|
|
// list godoc
|
|
// @Summary List permissions
|
|
// @Description Returns the permission catalog: one code per module, in display order. Holding a code grants read and write in that module; the role's scope decides which records.
|
|
// @Tags permission
|
|
// @Produce json
|
|
// @Security BearerAuth
|
|
// @Success 200 {object} appresult.AppSuccess
|
|
// @Router /permissions [get]
|
|
func (h *handler) list(c *gin.Context) {
|
|
c.JSON(http.StatusOK, appresult.SuccessWithData(perm.All))
|
|
}
|