template-monorepo/internal/logic/permission/revoke_user_role_logic.go

38 lines
956 B
Go
Raw Normal View History

package permission
import (
"context"
"gateway/internal/svc"
"gateway/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type RevokeUserRoleLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// NewRevokeUserRoleLogic returns the revoke-role logic.
func NewRevokeUserRoleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RevokeUserRoleLogic {
return &RevokeUserRoleLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
// RevokeUserRole removes a single role assignment.
func (l *RevokeUserRoleLogic) RevokeUserRole(req *types.RevokeUserRoleByIDReq) error {
if l.svcCtx.PermissionUserRole == nil {
return errb.SysNotImplemented("permission module not configured")
}
actor, err := ActorFromContext(l.ctx)
if err != nil {
return errb.AuthUnauthorized(err.Error()).WithCause(err)
}
return l.svcCtx.PermissionUserRole.Revoke(l.ctx, actor.TenantID, req.UID, req.RoleID)
}