def template_roles_view(request, template_id): try: status, msg, tem = TemplateAPI.get(request.user, template_id) if not status: return HttpResponse(msg) users = tem.users users_with_roles = [] for user in users: status, msg, roles = UserAndTeamRoleAPI.get_user_roles_on_resource( request.user, user.id, RS_TEM, template_id) if status: users_with_roles.append([user, roles]) teams = tem.teams teams_with_roles = [] for team in teams: status, msg, roles = UserAndTeamRoleAPI.get_team_roles_on_resource( request.user, team.id, RS_TEM, template_id) if status: teams_with_roles.append([team, roles]) all_users = tem.organization.users context = { 'app': template_app, 'template': tem, 'pm': InternalAPI.get_user_permissions_on_resource( request.user, RS_TEM, tem.id), 'users_with_roles': users_with_roles, 'teams_with_roles': teams_with_roles, 'all_users': all_users, 'all_teams': tem.organization.team_set.all(), 'roles': tem.roles.filter(resource_type=RS_TEM), } return render(request, 'project/template_roles.html', context) except Exception as e: return HttpResponse(str(e))
def project_roles_view(request, project_id): try: status, errmsg, pro = ProjectAPI.get(request.user, project_id) if not status: return render(request, 'error.html', {ARK_ERRMSG: errmsg}) users = pro.users users_with_roles = list() for user in users: status, errmsg, roles = \ UserAndTeamRoleAPI.get_user_roles_on_resource( user=request.user, target_user_id=user.id, resource_type=RS_PROJECT, resource_id=project_id ) if status: users_with_roles.append([user, roles]) teams = pro.teams teams_with_roles = list() for team in teams: status, errmsg, roles = \ UserAndTeamRoleAPI.get_team_roles_on_resource( user=request.user, target_team_id=team.id, resource_type=RS_PROJECT, resource_id=project_id ) if status: teams_with_roles.append([team, roles]) all_users = pro.organization.users all_teams = pro.organization.team_set.all() pm_list = InternalAPI.get_user_permissions_on_resource( user=request.user, resource_type=RS_PROJECT, resource_id=pro.id) context = { 'app': project_app, 'project': pro, 'pm': pm_list, 'users_with_roles': users_with_roles, 'teams_with_roles': teams_with_roles, 'all_users': all_users, 'all_teams': all_teams, 'roles': pro.roles.filter(resource_type=RS_PROJECT), } return render(request, 'project/project_roles.html', context) except Exception as e: return render(request, 'error.html', {ARK_ERRMSG: str(e)})
def inventory_roles_view(request, inventory_id): try: status, msg, inv = InventoryAPI.get(request.user, inventory_id) if not status: return HttpResponse(msg) users = inv.users users_with_roles = [] for user in users: status, msg, roles = UserAndTeamRoleAPI.get_user_roles_on_resource( request.user, user.id, RS_INV, inventory_id ) if status: users_with_roles.append([user, roles]) teams = inv.teams teams_with_roles = [] for team in teams: status, msg, roles = UserAndTeamRoleAPI.get_team_roles_on_resource( request.user, team.id, RS_INV, inventory_id ) if status: teams_with_roles.append([team, roles]) all_users = inv.organization.users context = { 'app': app, 'inventory': inv, 'pm': InternalAPI.get_user_permissions_on_resource( request.user, RS_INV, inv.id ), 'users_with_roles': users_with_roles, 'teams_with_roles': teams_with_roles, 'all_users': all_users, 'all_teams': inv.organization.team_set.all(), 'roles': inv.roles.filter(resource_type=RS_INV), } return render(request, 'inventory/inventory_roles.html', context) except Exception as e: return HttpResponse(str(e))