feat: add salary privilege to privilege management system

Add support for the salary privilege in the privilege handler. 
Implement associated logic to process and validate the 
salary privilege in the test cases. Update the data 
structures to include the new privilege and ensure 
correct functionality in the privilege processing flow.
This commit is contained in:
2025-09-06 14:49:56 +02:00
parent a1c9ace5ec
commit b6ec9feeae
3 changed files with 21 additions and 2 deletions
+3
View File
@@ -20,6 +20,7 @@ type CompanyPrivileges struct {
Invoicing bool `json:"invoicing"` Invoicing bool `json:"invoicing"`
Accounting bool `json:"accounting"` Accounting bool `json:"accounting"`
Supplier bool `json:"supplier"` Supplier bool `json:"supplier"`
Salary bool `json:"salary"`
} }
// PrivilegeHandler processes PrivilegeAdded-events and fetches the initial set of privileges from an authz-service // PrivilegeHandler processes PrivilegeAdded-events and fetches the initial set of privileges from an authz-service
@@ -139,6 +140,8 @@ func (h *PrivilegeHandler) setPrivileges(email, companyId string, privilege Priv
c.Accounting = set c.Accounting = set
case PrivilegeSupplier: case PrivilegeSupplier:
c.Supplier = set c.Supplier = set
case PrivilegeSalary:
c.Salary = set
} }
} else { } else {
priv[companyId] = &CompanyPrivileges{} priv[companyId] = &CompanyPrivileges{}
+15 -1
View File
@@ -236,6 +236,18 @@ func TestPrivilegeHandler_IsAllowed_Return_True_If_Privilege_Exists(t *testing.T
}) })
assert.True(t, result) assert.True(t, result)
_, _ = handler.Process(&PrivilegeAdded{
Email: "jim@example.org",
CompanyID: "abc-123",
Privilege: PrivilegeSalary,
}, goamqp.Headers{})
result = handler.IsAllowed("jim@example.org", "abc-123", func(privileges CompanyPrivileges) bool {
return privileges.Salary
})
assert.True(t, result)
} }
func TestPrivilegeHandler_Fetch_Error_Response(t *testing.T) { func TestPrivilegeHandler_Fetch_Error_Response(t *testing.T) {
@@ -289,7 +301,8 @@ func TestPrivilegeHandler_Fetch_Valid(t *testing.T) {
"time": true, "time": true,
"invoicing": true, "invoicing": true,
"accounting": false, "accounting": false,
"supplier": false "supplier": false,
"salary": true
} }
} }
}` }`
@@ -313,6 +326,7 @@ func TestPrivilegeHandler_Fetch_Valid(t *testing.T) {
Invoicing: true, Invoicing: true,
Accounting: false, Accounting: false,
Supplier: false, Supplier: false,
Salary: true,
}, },
}, },
} }
+3 -1
View File
@@ -23,6 +23,7 @@ const (
PrivilegeInvoicing = "INVOICING" PrivilegeInvoicing = "INVOICING"
PrivilegeAccounting = "ACCOUNTING" PrivilegeAccounting = "ACCOUNTING"
PrivilegeSupplier = "SUPPLIER" PrivilegeSupplier = "SUPPLIER"
PrivilegeSalary = "SALARY"
) )
var AllPrivilege = []Privilege{ var AllPrivilege = []Privilege{
@@ -33,11 +34,12 @@ var AllPrivilege = []Privilege{
PrivilegeInvoicing, PrivilegeInvoicing,
PrivilegeAccounting, PrivilegeAccounting,
PrivilegeSupplier, PrivilegeSupplier,
PrivilegeSalary,
} }
func (e Privilege) IsValid() bool { func (e Privilege) IsValid() bool {
switch e { switch e {
case PrivilegeAdmin, PrivilegeCompany, PrivilegeConsumer, PrivilegeTime, PrivilegeInvoicing, PrivilegeAccounting, PrivilegeSupplier: case PrivilegeAdmin, PrivilegeCompany, PrivilegeConsumer, PrivilegeTime, PrivilegeInvoicing, PrivilegeAccounting, PrivilegeSupplier, PrivilegeSalary:
return true return true
} }
return false return false