Skip to content

Commit

Permalink
corregidos tests de metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
anddonram committed Jun 27, 2017
1 parent e380326 commit e430e67
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -418,10 +418,8 @@ def check_metrics_authorized_for_department(user, dpmt_id):

if logged.user_type == 'E':
# If it's not an admin, check that it has role EXECUTIVE (50) or higher for any project in the department
try:
ProjectDepartmentEmployeeRole.objects.get(employee_id=logged, role_id__tier__gte=30,
projectDepartment_id__department_id=department)
except ObjectDoesNotExist:
if not ProjectDepartmentEmployeeRole.objects.filter(employee_id=logged, role_id__tier__gte=20,
projectDepartment_id__department_id=department).exists():
raise PermissionDenied


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -804,13 +804,6 @@ def check_metrics_authorized_for_employee_in_project(user, employee_id, project_
"""
Raises 403 if the current actor is not allowed to obtain metrics for the department
Optional at the end:
if logged.user_type == 'E'
If it's not an admin, check that it has role EXECUTIVE (50) or higher for any project in the department
try
ProjectDepartmentEmployeeRole.objects.get(employee_id=logged, role_id__tier__gte=50, projectDepartment_id__project_id=project)
except ObjectDoesNotExist:
raise PermissionDenied
"""
if not user.is_authenticated():
raise PermissionDenied
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,10 +463,8 @@ def check_metrics_authorized_for_project(user, project_id):
res = is_executive.count() > 0

if not res:
try:
ProjectDepartmentEmployeeRole.objects.get(employee_id=logged, role_id__tier__gte=40,
projectDepartment_id__project_id=project)
except ObjectDoesNotExist:
if not ProjectDepartmentEmployeeRole.objects.filter(employee_id=logged, role_id__tier__gte=40,
projectDepartment_id__project_id=project).exists():
raise PermissionDenied


Expand Down
12 changes: 0 additions & 12 deletions Metronus-Project/metronus_app/controllers/roleController.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,18 +179,6 @@ def delete(request, role_id):
if not is_role_updatable_by_user(logged, role_id):
raise PermissionDenied

"""
elif logged.user_type == 'E':
# If it's an executive, check that the role they're trying to delete is lower than their role
try:
logged_role = ProjectDepartmentEmployeeRole.objects.get(employee_id=logged,
projectDepartment_id=role.projectDepartment_id)
if role.role_id.tier >= logged_role.role_id.tier:
raise PermissionDenied
except ObjectDoesNotExist:
raise PermissionDenied
"""

employee_username = role.employee_id.user.username
role.delete()
Expand Down
8 changes: 3 additions & 5 deletions Metronus-Project/metronus_app/controllers/taskController.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,9 +721,7 @@ def check_metrics_authorized_for_task(user, task_id):
raise PermissionDenied

if logged.user_type == 'E':
# If it's not an admin, check that it has role EXECUTIVE (50) or higher for the projdept tuple
try:
ProjectDepartmentEmployeeRole.objects.get(employee_id=logged, role_id__tier__gte=20,
projectDepartment_id=task.projectDepartment_id)
except ObjectDoesNotExist:
# If it's not an admin, check that it has role coordinator (20) or higher for the projdept tuple
if not ProjectDepartmentEmployeeRole.objects.filter(employee_id=logged, role_id__tier__gte=20,
projectDepartment_id=task.projectDepartment_id).exists():
raise PermissionDenied
31 changes: 24 additions & 7 deletions Metronus-Project/metronus_app/test/testDepartmentMetrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,13 @@ def setUp(self):
first_name="Alberto",
last_name="Berto"
)

employee3_user = User.objects.create_user(
username="emp3",
password="123456",
email="emp3@metronus.es",
first_name="Alberta",
last_name="Berta"
)
employee1 = Employee.objects.create(
user=employee1_user,
user_type="E",
Expand All @@ -86,7 +92,13 @@ def setUp(self):
phone="666555444",
company_id=company1
)

employee3 = Employee.objects.create(
user=employee3_user,
user_type="E",
identifier="emp03",
phone="666555445",
company_id=company1
)
# Department 1
Department.objects.create(
name="Departamento1",
Expand Down Expand Up @@ -132,7 +144,7 @@ def setUp(self):
role_tm = Role.objects.create(name="TEAM_MANAGER", tier=30)
# role_co
role_co = Role.objects.create(name="COORDINATOR", tier=20)
Role.objects.create(name="EMPLOYEE", tier=10)
role_emp=Role.objects.create(name="EMPLOYEE", tier=10)

pro1 = Project.objects.create(name="pro1", deleted=False, company_id=company1)
# pro2
Expand Down Expand Up @@ -166,7 +178,12 @@ def setUp(self):
role_id=role_ex,
employee_id=employee2
)

# pdrole4
ProjectDepartmentEmployeeRole.objects.create(
projectDepartment_id=pd,
role_id=role_emp,
employee_id=employee3
)
def test_access_denied_not_logged_emppertask(self):
"""
Without authentication, try getting the emppertask JSON
Expand All @@ -182,7 +199,7 @@ def test_access_denied_low_role_emppertask(self):
Without proper roles, try getting the emppertask JSON
"""
c = Client()
c.login(username="emp1", password="123456")
c.login(username="emp3", password="123456")

response = c.get("/department/ajaxEmployeesPerTask?department_id={0}" .format(
Department.objects.get(name="Departamento2").id))
Expand Down Expand Up @@ -278,7 +295,7 @@ def test_access_denied_low_role_timepertask(self):
Try getting the timepertask JSON without proper roles
"""
c = Client()
c.login(username="emp1", password="123456")
c.login(username="emp3", password="123456")

response = c.get("/department/ajaxTimePerTask?department_id={0}" .format(
Department.objects.get(name="Departamento2").id))
Expand Down Expand Up @@ -384,7 +401,7 @@ def test_access_denied_low_role_profit(self):
Without proper roles, try getting the profit JSON
"""
c = Client()
c.login(username="emp1", password="123456")
c.login(username="emp3", password="123456")

response = c.get("/department/ajaxProfit/{0}/" .format(Department.objects.get(name="Departamento2").id))
self.assertEquals(response.status_code, 403)
Expand Down
2 changes: 1 addition & 1 deletion Metronus-Project/populate_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def populate_roles():
# El jefe de proyecto
Role.objects.create(name="PROJECT_MANAGER", tier=40)
# El jefe de equipo
Role.objects.create(name="TEAM_MANAGER", tier=30)
Role.objects.create(name="TEAM_MANAGER", tier=15)
# El coordinador del departamento
Role.objects.create(name="COORDINATOR", tier=20)
# El empleado
Expand Down
2 changes: 1 addition & 1 deletion Metronus-Project/populate_database2.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def populate_roles():
# El jefe de proyecto
Role.objects.create(name="PROJECT_MANAGER", tier=40)
# El jefe de equipo
Role.objects.create(name="TEAM_MANAGER", tier=30)
Role.objects.create(name="TEAM_MANAGER", tier=15)
# El coordinador del departamento
Role.objects.create(name="COORDINATOR", tier=20)
# El empleado
Expand Down

0 comments on commit e430e67

Please sign in to comment.