Skip to content

Commit

Permalink
feat: restrcit monthly revenue read perm
Browse files Browse the repository at this point in the history
  • Loading branch information
namnhce committed Apr 25, 2023
1 parent f44f64a commit efd6649
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 9 deletions.
3 changes: 1 addition & 2 deletions migrations/seed/permissions.sql
Original file line number Diff line number Diff line change
@@ -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'),
Expand All @@ -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'),
Expand Down
3 changes: 2 additions & 1 deletion migrations/seed/role_permissions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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');



Expand Down
2 changes: 1 addition & 1 deletion pkg/handler/project/testdata/get_project/200.json
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@
"name": "Dwarves Foundation",
"avatar": ""
},
"monthlyChargeRate": "11000",
"monthlyChargeRate": "0",
"currency": {
"id": "06a699ed-618b-400b-ac8c-8739956fa8e7",
"name": "GBP",
Expand Down
2 changes: 1 addition & 1 deletion pkg/handler/project/testdata/get_projects/200.json
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@
"name": "Dwarves Foundation",
"avatar": ""
},
"monthlyChargeRate": "11000",
"monthlyChargeRate": "0",
"currency": {
"id": "06a699ed-618b-400b-ac8c-8739956fa8e7",
"name": "GBP",
Expand Down
1 change: 1 addition & 0 deletions pkg/model/permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 7 additions & 4 deletions pkg/view/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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)
Expand All @@ -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(),
Expand All @@ -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()
Expand Down

0 comments on commit efd6649

Please sign in to comment.