mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
Feat(BE-304): add permission in report and closing
This commit is contained in:
@@ -1,44 +0,0 @@
|
||||
package capabilities
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
permission "gitlab.com/mbugroup/lti-api.git/internal/middleware"
|
||||
)
|
||||
|
||||
// FromPermissions returns a filtered map of capabilities that the frontend can use
|
||||
// to toggle features. Only permissions recognized by the application are exposed.
|
||||
func FromPermissions(perms []string) map[string]bool {
|
||||
if len(perms) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
out := make(map[string]bool)
|
||||
for _, perm := range perms {
|
||||
if key, ok := normalizeAndAllow(perm); ok {
|
||||
out[key] = true
|
||||
}
|
||||
}
|
||||
if len(out) == 0 {
|
||||
return nil
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func normalizeAndAllow(perm string) (string, bool) {
|
||||
perm = strings.ToLower(strings.TrimSpace(perm))
|
||||
if perm == "" {
|
||||
return "", false
|
||||
}
|
||||
if _, ok := allowed[perm]; !ok {
|
||||
return "", false
|
||||
}
|
||||
return perm, true
|
||||
}
|
||||
|
||||
var allowed = map[string]struct{}{
|
||||
permission.PermissionRecordingRead: {},
|
||||
permission.PermissionRecordingCreate: {},
|
||||
permission.PermissionRecordingUpdate: {},
|
||||
permission.PermissionRecordingDelete: {},
|
||||
}
|
||||
@@ -39,16 +39,31 @@ const(
|
||||
const (
|
||||
P_ApprovalGetAll = "lti.approval.list"
|
||||
)
|
||||
const (
|
||||
P_ReportExpenseGetAll = "lti.repport.expense.list"
|
||||
P_ReportDeliveryGetAll = "lti.repport.delivery.list"
|
||||
)
|
||||
|
||||
|
||||
const (
|
||||
P_ClosingGetAll = "lti.closing.list"
|
||||
P_ClosingPenjualan = "lti.closing.penjualan"
|
||||
P_ClosingGetSummary = "lti.closing.getsummary"
|
||||
P_ProductStockGetAll = "lti.inventory.product_stock.list"
|
||||
P_ProductStockGetOne = "lti.inventory.product_stock.detail"
|
||||
P_ProductWarehousekGetAll = "lti.inventory.product_warehouses.list"
|
||||
P_ProductWarehouseGetOne = "lti.inventory.product_warehouses.detail"
|
||||
)
|
||||
const (
|
||||
P_ClosingGetAll = "lti.closing.list"
|
||||
P_ClosingPenjualan = "lti.closing.penjualan"
|
||||
P_ClosingGetSummary = "lti.closing.getsummary"
|
||||
|
||||
|
||||
//?baru
|
||||
P_ClosingGetOverhead = "lti.closing.getoverhead"
|
||||
P_ClosingCountSapronakKandang = "lti.closing.getsapronakcountbykandang"
|
||||
P_ClosingCountSapronak = "lti.closing.getsapronakcount"
|
||||
P_ClosingSapronak = "lti.closing.getsapronak"
|
||||
|
||||
)
|
||||
|
||||
const (
|
||||
P_TransferGetAll = "lti.inventory.transfer.list"
|
||||
@@ -145,15 +160,14 @@ const(
|
||||
P_WarehousesCreateOne = "lti.master.warehouses.create"
|
||||
P_WarehousesUpdateOne = "lti.master.warehouses.update"
|
||||
P_WarehousesDeleteOne = "lti.master.warehouses.delete"
|
||||
|
||||
)
|
||||
|
||||
|
||||
const (
|
||||
P_ChickinsCreateOne = "lti.production.chickins.create"
|
||||
P_ChickinsGetOne = "lti.production.chickins.detail"
|
||||
P_ChickinsApproval = "lti.production.chickins.approve"
|
||||
)
|
||||
|
||||
// recording
|
||||
const (
|
||||
P_RecordingGetAll = "lti.production.recording.list"
|
||||
|
||||
@@ -24,11 +24,8 @@ func ClosingRoutes(v1 fiber.Router, u user.UserService, s closing.ClosingService
|
||||
route.Get("/",m.RequirePermissions(m.P_ClosingGetAll), ctrl.GetAll)
|
||||
route.Get("/:project_flock_id/penjualan",m.RequirePermissions(m.P_ClosingPenjualan), ctrl.GetPenjualan)
|
||||
route.Get("/:projectFlockId",m.RequirePermissions(m.P_ClosingGetSummary), ctrl.GetClosingSummary)
|
||||
route.Get("/", ctrl.GetAll)
|
||||
route.Get("/:project_flock_id/penjualan", ctrl.GetPenjualan)
|
||||
route.Get("/:project_flock_id/overhead", ctrl.GetOverhead)
|
||||
route.Get("/:project_flock_id/:project_flock_kandang_id/perhitungan_sapronak", ctrl.GetSapronakByKandang)
|
||||
route.Get("/:project_flock_id/perhitungan_sapronak", ctrl.GetSapronakByProject)
|
||||
route.Get("/:projectFlockId", ctrl.GetClosingSummary)
|
||||
route.Get("/:projectFlockId/sapronak", ctrl.GetClosingSapronak)
|
||||
route.Get("/:project_flock_id/overhead",m.RequirePermissions(m.P_ClosingGetOverhead), ctrl.GetOverhead)
|
||||
route.Get("/:project_flock_id/:project_flock_kandang_id/perhitungan_sapronak",m.RequirePermissions(m.P_ClosingCountSapronakKandang) ,ctrl.GetSapronakByKandang)
|
||||
route.Get("/:project_flock_id/perhitungan_sapronak",m.RequirePermissions(m.P_ClosingCountSapronak) ,ctrl.GetSapronakByProject)
|
||||
route.Get("/:projectFlockId/sapronak",m.RequirePermissions(m.P_ClosingSapronak), ctrl.GetClosingSapronak)
|
||||
}
|
||||
|
||||
@@ -11,6 +11,9 @@ import (
|
||||
|
||||
expenseRepo "gitlab.com/mbugroup/lti-api.git/internal/modules/expenses/repositories"
|
||||
marketingRepo "gitlab.com/mbugroup/lti-api.git/internal/modules/marketing/repositories"
|
||||
|
||||
rUser "gitlab.com/mbugroup/lti-api.git/internal/modules/users/repositories"
|
||||
sUser "gitlab.com/mbugroup/lti-api.git/internal/modules/users/services"
|
||||
)
|
||||
|
||||
type RepportModule struct{}
|
||||
@@ -20,9 +23,11 @@ func (RepportModule) RegisterRoutes(router fiber.Router, db *gorm.DB, validate *
|
||||
expenseRealizationRepository := expenseRepo.NewExpenseRealizationRepository(db)
|
||||
marketingDeliveryProductRepository := marketingRepo.NewMarketingDeliveryProductRepository(db)
|
||||
approvalRepository := commonRepo.NewApprovalRepository(db)
|
||||
userRepository := rUser.NewUserRepository(db)
|
||||
|
||||
approvalSvc := approvalService.NewApprovalService(approvalRepository)
|
||||
repportService := sRepport.NewRepportService(validate, expenseRealizationRepository, marketingDeliveryProductRepository, approvalSvc)
|
||||
userService := sUser.NewUserService(userRepository, validate)
|
||||
|
||||
RepportRoutes(router, repportService)
|
||||
RepportRoutes(router, userService, repportService)
|
||||
}
|
||||
|
||||
@@ -1,17 +1,20 @@
|
||||
package repports
|
||||
|
||||
import (
|
||||
m "gitlab.com/mbugroup/lti-api.git/internal/middleware"
|
||||
controller "gitlab.com/mbugroup/lti-api.git/internal/modules/repports/controllers"
|
||||
repport "gitlab.com/mbugroup/lti-api.git/internal/modules/repports/services"
|
||||
user "gitlab.com/mbugroup/lti-api.git/internal/modules/users/services"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
func RepportRoutes(v1 fiber.Router, s repport.RepportService) {
|
||||
func RepportRoutes(v1 fiber.Router, u user.UserService, s repport.RepportService) {
|
||||
ctrl := controller.NewRepportController(s)
|
||||
|
||||
route := v1.Group("/reports")
|
||||
route.Use(m.Auth(u))
|
||||
|
||||
route.Get("/expense", ctrl.GetExpense)
|
||||
route.Get("/marketing", ctrl.GetMarketing)
|
||||
route.Get("/expense", m.RequirePermissions(m.P_ReportExpenseGetAll), ctrl.GetExpense)
|
||||
route.Get("/marketing", m.RequirePermissions(m.P_ReportDeliveryGetAll), ctrl.GetMarketing)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user