diff --git a/migrations/seed/permissions.sql b/migrations/seed/permissions.sql index e56a647ad..ccdff0ed5 100644 --- a/migrations/seed/permissions.sql +++ b/migrations/seed/permissions.sql @@ -1,6 +1,4 @@ INSERT INTO public.permissions (id, deleted_at, created_at, updated_at, name, code) VALUES - ('9be246ac-2e53-4268-814a-dc760afd3758', NULL, '2022-11-11 18:34:14.743263', '2022-11-11 18:34:14.743263', 'Employee Base Salary Read', 'employees.baseSalary.read'), - ('84aa4653-4bd8-428b-9521-618a67a6be6b', NULL, '2022-11-11 18:34:14.743263', '2022-11-11 18:34:14.743263', 'Employee Base Salary Edit', 'employees.baseSalary.edit'); ('495c96ae-60f9-4c57-bc96-9504d0fedde6', NULL, '2022-11-11 18:34:14.743263', '2022-11-11 18:34:14.743263', 'Auth Read', 'auth.read'), ('5820dd37-a9bd-455e-b49b-b54ad7df180e', NULL, '2022-11-11 18:34:14.743263', '2022-11-11 18:34:14.743263', 'Auth Create', 'auth.create'), ('01ed1076-4028-4fdf-9a92-cb57a8e041af', NULL, '2022-11-11 18:34:14.743263', '2022-11-11 18:34:14.743263', 'Employee Read', 'employees.read'), @@ -21,6 +19,7 @@ INSERT INTO public.permissions (id, deleted_at, created_at, updated_at, name, co ('09a5fa4c-ad07-4dec-a16d-34e0f567ef1d', NULL, '2022-11-11 18:34:14.743263', '2022-11-11 18:34:14.743263', 'Project Create', 'projects.create'), ('35bb795a-0b9f-428c-861d-48c1e8d4e73a', NULL, '2022-11-11 18:34:14.743263', '2022-11-11 18:34:14.743263', 'Project Read', 'projects.read'), ('a8299847-4d10-41e9-8327-42e13e0672ae', NULL, '2022-11-11 18:34:14.743263', '2022-11-11 18:34:14.743263', 'Project Read Full Access', 'projects.read.fullAccess'), +('7bd3d8e3-8b0b-4f3a-8ee7-0b6bec1c8913', NULL, '2022-11-11 18:34:14.743263', '2022-11-11 18:34:14.743263', 'Project Read Monthly Revenue', 'projects.read.monthlyRevenue'), ('3c26a977-f4b9-4bc4-8d31-a2dcf075d254', NULL, '2022-11-11 18:34:14.743263', '2022-11-11 18:34:14.743263', 'Project Read Active', 'projects.read.readActive'), ('80a2c800-02ea-4264-9289-57b92e911097', NULL, '2022-11-11 18:34:14.743263', '2022-11-11 18:34:14.743263', 'Project Edit', 'projects.edit'), ('6118a1da-aa9a-40eb-b664-87a6969c5759', NULL, '2022-11-11 18:34:14.743263', '2022-11-11 18:34:14.743263', 'Project Commission Rate Read', 'projects.commissionRate.read'), diff --git a/migrations/seed/role_permissions.sql b/migrations/seed/role_permissions.sql index da7a4b459..4fec97de4 100644 --- a/migrations/seed/role_permissions.sql +++ b/migrations/seed/role_permissions.sql @@ -239,7 +239,8 @@ INSERT INTO public.role_permissions (id, deleted_at, created_at, updated_at, rol ('13305903-965d-4174-962f-8799726e330f', NULL, '2022-11-11 18:35:27.069944', '2022-11-11 18:35:27.069944', 'c23c1c1c-bfaf-41e6-a4d7-6ef196fd2736', 'f75db77f-e299-4135-81b7-0784b452f7b7'), ('e0482950-8e09-4dd5-adac-7274a96cc9b2', NULL, '2022-11-11 18:35:27.069944', '2022-11-11 18:35:27.069944', 'c23c1c1c-bfaf-41e6-a4d7-6ef196fd2736', 'd500ea57-da9a-4b24-b147-59d009f0d7bc'), ('0f03ebae-15fe-4a0c-bb0b-c2fad0d9a9fb', NULL, '2022-11-11 18:35:27.069944', '2022-11-11 18:35:27.069944', 'c23c1c1c-bfaf-41e6-a4d7-6ef196fd2736', '9be246ac-2e53-4268-814a-dc760afd3758'), -('fab38772-1430-4a7d-996f-aacb5aa049b0', NULL, '2022-11-11 18:35:27.069944', '2022-11-11 18:35:27.069944', 'c23c1c1c-bfaf-41e6-a4d7-6ef196fd2736', '84aa4653-4bd8-428b-9521-618a67a6be6b'); +('fab38772-1430-4a7d-996f-aacb5aa049b0', NULL, '2022-11-11 18:35:27.069944', '2022-11-11 18:35:27.069944', 'c23c1c1c-bfaf-41e6-a4d7-6ef196fd2736', '84aa4653-4bd8-428b-9521-618a67a6be6b'), +('37e9c42e-d280-4b00-a395-2af8ecda6d5e', NULL, '2022-11-11 18:35:27.069944', '2022-11-11 18:35:27.069944', 'c23c1c1c-bfaf-41e6-a4d7-6ef196fd2736', '7bd3d8e3-8b0b-4f3a-8ee7-0b6bec1c8913'); diff --git a/pkg/handler/project/testdata/get_project/200.json b/pkg/handler/project/testdata/get_project/200.json index 25a4f05e2..61d290820 100644 --- a/pkg/handler/project/testdata/get_project/200.json +++ b/pkg/handler/project/testdata/get_project/200.json @@ -349,7 +349,7 @@ "name": "Dwarves Foundation", "avatar": "" }, - "monthlyChargeRate": "11000", + "monthlyChargeRate": "0", "currency": { "id": "06a699ed-618b-400b-ac8c-8739956fa8e7", "name": "GBP", diff --git a/pkg/handler/project/testdata/get_projects/200.json b/pkg/handler/project/testdata/get_projects/200.json index 75327e292..26351c047 100644 --- a/pkg/handler/project/testdata/get_projects/200.json +++ b/pkg/handler/project/testdata/get_projects/200.json @@ -273,7 +273,7 @@ "name": "Dwarves Foundation", "avatar": "" }, - "monthlyChargeRate": "11000", + "monthlyChargeRate": "0", "currency": { "id": "06a699ed-618b-400b-ac8c-8739956fa8e7", "name": "GBP", diff --git a/pkg/model/permissions.go b/pkg/model/permissions.go index 27bf2482b..2eb470fdf 100644 --- a/pkg/model/permissions.go +++ b/pkg/model/permissions.go @@ -39,6 +39,7 @@ const ( PermissionProjectsCreate PermissionCode = "projects.create" PermissionProjectsRead PermissionCode = "projects.read" PermissionProjectsReadFullAccess PermissionCode = "projects.read.fullAccess" + PermissionProjectsReadMonthlyRevenue PermissionCode = "projects.read.monthlyRevenue" PermissionProjectsReadReadActive PermissionCode = "projects.read.readActive" PermissionProjectsEdit PermissionCode = "projects.edit" PermissionProjectsCommissionRateRead PermissionCode = "projects.commissionRate.read" diff --git a/pkg/view/project.go b/pkg/view/project.go index bec64c0c3..d0851d387 100644 --- a/pkg/view/project.go +++ b/pkg/view/project.go @@ -174,7 +174,7 @@ func ToProjectData(project *model.Project, userInfo *model.CurrentLoggedUserInfo projectCurrency = toCurrency(project.BankAccount.Currency) } - monthlyChargeRate := decimal.Zero + monthlyRevenue := decimal.Zero var members = make([]ProjectMember, 0, len(project.ProjectMembers)) for _, m := range project.ProjectMembers { member := ProjectMember{ @@ -200,8 +200,8 @@ func ToProjectData(project *model.Project, userInfo *model.CurrentLoggedUserInfo member.Currency = projectCurrency } - if m.DeploymentType == model.MemberDeploymentTypeOfficial { - monthlyChargeRate = monthlyChargeRate.Add(m.Rate) + if m.DeploymentType == model.MemberDeploymentTypeOfficial && m.Status == model.ProjectMemberStatusActive { + monthlyRevenue = monthlyRevenue.Add(m.Rate) } members = append(members, member) @@ -222,7 +222,6 @@ func ToProjectData(project *model.Project, userInfo *model.CurrentLoggedUserInfo AccountManagers: accountManagers, SalePersons: salePersons, ProjectEmail: project.ProjectEmail, - MonthlyChargeRate: monthlyChargeRate, AllowsSendingSurvey: project.AllowsSendingSurvey, Code: project.Code, Function: project.Function.String(), @@ -243,6 +242,10 @@ func ToProjectData(project *model.Project, userInfo *model.CurrentLoggedUserInfo } } + if authutils.HasPermission(userInfo.Permissions, model.PermissionProjectsReadMonthlyRevenue) { + d.MonthlyChargeRate = monthlyRevenue + } + if authutils.HasPermission(userInfo.Permissions, model.PermissionProjectsReadFullAccess) { if project.ProjectNotion != nil && !project.ProjectNotion.AuditNotionID.IsZero() { d.AuditNotionID = project.ProjectNotion.AuditNotionID.String()