def _check_geni_federation_status(request): """ Checks if a user who authenticated view GENI/OpenID is on the Chameleon Federation project on the GENI side. If so, then checks if the user is on the corresponding project on the Chameleon side. Returns a tuple of boolean values for (on_geni_project, on_chameleon_project) """ geni_project_key = '%s|%s' % ( settings.GENI_FEDERATION_PROJECTS['geni']['id'], settings.GENI_FEDERATION_PROJECTS['geni']['name']) on_geni_project = geni_project_key in request.session['openid']['ax'][ 'projects'] if on_geni_project: try: fed_proj = Project( settings.GENI_FEDERATION_PROJECTS['chameleon']['id']) on_chameleon_project = any(u.username == request.user.username \ for u in fed_proj.get_users()) except: logger.warn('Could not locate Chameleon federation project: %s' % \ settings.GENI_FEDERATION_PROJECTS['chameleon']) on_chameleon_project = False else: on_chameleon_project = False return on_geni_project, on_chameleon_project
def _check_geni_federation_status(request): """ Checks if a user who authenticated view GENI/OpenID is on the Chameleon Federation project on the GENI side. If so, then checks if the user is on the corresponding project on the Chameleon side. Returns a tuple of boolean values for (on_geni_project, on_chameleon_project) """ geni_project_key = '%s|%s' % (settings.GENI_FEDERATION_PROJECTS['geni']['id'], settings.GENI_FEDERATION_PROJECTS['geni']['name']) on_geni_project = geni_project_key in request.session['openid']['ax']['projects'] if on_geni_project: try: fed_proj = Project(settings.GENI_FEDERATION_PROJECTS['chameleon']['id']) on_chameleon_project = any(u.username == request.user.username \ for u in fed_proj.get_users()) except: logger.warn('Could not locate Chameleon federation project: %s' % \ settings.GENI_FEDERATION_PROJECTS['chameleon']) on_chameleon_project = False else: on_chameleon_project = False return on_geni_project, on_chameleon_project
def activate_geni(request): fed_proj = Project(settings.GENI_FEDERATION_PROJECTS["chameleon"]["id"]) on_chameleon_project = any(u.username == request.user for u in fed_proj.get_users()) if on_chameleon_project: messages.info("Your access to the Chameleon-GENI Federation Project is active.") return HttpResponseRedirect(reverse("dashboard")) if request.method == "POST": if request.POST.get("accept_user_terms") == "on": fed_proj.add_user(request.user) messages.success(request, "Your access to the Chameleon-GENI Federation Project is active.") return HttpResponseRedirect(reverse("dashboard")) else: messages.error(request, "Please agree to Chameleon Acceptable Use Policy before proceeding.") context = { "geni": settings.GENI_FEDERATION_PROJECTS["geni"], "chameleon": settings.GENI_FEDERATION_PROJECTS["chameleon"], } return render(request, "chameleon_openid/activate_geni.html", context)
def view_project(request, project_id): try: project = Project(project_id) if project.source != 'Chameleon': raise Http404('The requested project does not exist!') except Exception as e: logger.error(e) raise Http404('The requested project does not exist!') if request.POST: if 'add_user' in request.POST: form = ProjectAddUserForm(request.POST) if form.is_valid(): # try to add user try: add_username = form.cleaned_data['username'] if project.add_user(add_username): messages.success(request, 'User "%s" added to project!' % add_username) form = ProjectAddUserForm() except: logger.exception('Failed adding user') form.add_error('username', '') form.add_error('__all__', 'Unable to add user. Confirm that the ' 'username is correct.') else: form.add_error('__all__', 'There were errors processing your request. ' 'Please see below for details.') else: form = ProjectAddUserForm() if 'del_user' in request.POST: # try to remove user try: del_username = request.POST['username'] if project.remove_user(del_username): messages.success(request, 'User "%s" removed from project' % del_username) except: logger.exception('Failed removing user') messages.error(request, 'An unexpected error occurred while attempting ' 'to remove this user. Please try again') else: form = ProjectAddUserForm() users = project.get_users() if not project_member_or_admin_or_superuser(request.user, project, users): raise PermissionDenied project.active_allocations = [] project.pending_allocations = [] project.rejected_allocations = [] project.inactive_allocations = [] for a in project.allocations: if a.status == 'Active' and a.resource == 'Chameleon': project.active_allocations.append(a) project.has_active_allocations = True if a.status == 'Pending' and a.resource == 'Chameleon': project.pending_allocations.append(a) project.has_pending_allocations = True if a.status == 'Inactive' and a.resource == 'Chameleon': project.inactive_allocations.append(a) project.has_inactive_allocations = True if a.status == 'Rejected' and a.resource == 'Chameleon': project.rejected_allocations.append(a) project.has_rejected_allocations = True if a.start and isinstance(a.start, basestring): a.start = datetime.strptime(a.start, '%Y-%m-%dT%H:%M:%SZ') if a.dateRequested: if isinstance(a.dateRequested, basestring): a.dateRequested = datetime.strptime(a.dateRequested, '%Y-%m-%dT%H:%M:%SZ') if a.dateReviewed: if isinstance(a.dateReviewed, basestring): a.dateReviewed = datetime.strptime(a.dateReviewed, '%Y-%m-%dT%H:%M:%SZ') if a.end: if isinstance(a.end, basestring): a.end = datetime.strptime(a.end, '%Y-%m-%dT%H:%M:%SZ') days_left = (a.end - datetime.today()).days if days_left >= 0 and days_left <= 90: a.up_for_renewal = True a.renewal_days = days_left return render(request, 'projects/view_project.html', { 'project': project, 'users': users, 'is_pi': request.user.username == project.pi.username, 'form': form, })
def view_project(request, project_id): try: project = Project(project_id) if project.source != 'Chameleon': raise Http404('The requested project does not exist!') except Exception as e: logger.error(e) raise Http404('The requested project does not exist!') if request.POST: if 'add_user' in request.POST: form = ProjectAddUserForm(request.POST) if form.is_valid(): # try to add user try: add_username = form.cleaned_data['username'] if project.add_user(add_username): messages.success( request, 'User "%s" added to project!' % add_username) form = ProjectAddUserForm() except: logger.exception('Failed adding user') form.add_error('username', '') form.add_error( '__all__', 'Unable to add user. Confirm that the ' 'username is correct.') else: form.add_error( '__all__', 'There were errors processing your request. ' 'Please see below for details.') else: form = ProjectAddUserForm() if 'del_user' in request.POST: # try to remove user try: del_username = request.POST['username'] if project.remove_user(del_username): messages.success( request, 'User "%s" removed from project' % del_username) except: logger.exception('Failed removing user') messages.error( request, 'An unexpected error occurred while attempting ' 'to remove this user. Please try again') else: form = ProjectAddUserForm() users = project.get_users() if not project_member_or_admin_or_superuser(request.user, project, users): raise PermissionDenied project.active_allocations = [] project.approved_allocations = [] project.pending_allocations = [] project.rejected_allocations = [] project.inactive_allocations = [] for a in project.allocations: if a.status == 'Active' and a.resource == 'Chameleon': project.active_allocations.append(a) project.has_active_allocations = True if a.status == 'Approved' and a.resource == 'Chameleon': project.approved_allocations.append(a) project.has_approved_allocations = True if a.status == 'Pending' and a.resource == 'Chameleon': project.pending_allocations.append(a) project.has_pending_allocations = True if a.status == 'Inactive' and a.resource == 'Chameleon': project.inactive_allocations.append(a) project.has_inactive_allocations = True if a.status == 'Rejected' and a.resource == 'Chameleon': project.rejected_allocations.append(a) project.has_rejected_allocations = True if a.start and isinstance(a.start, basestring): a.start = datetime.strptime(a.start, '%Y-%m-%dT%H:%M:%SZ') if a.dateRequested: if isinstance(a.dateRequested, basestring): a.dateRequested = datetime.strptime(a.dateRequested, '%Y-%m-%dT%H:%M:%SZ') if a.dateReviewed: if isinstance(a.dateReviewed, basestring): a.dateReviewed = datetime.strptime(a.dateReviewed, '%Y-%m-%dT%H:%M:%SZ') if a.end: if isinstance(a.end, basestring): a.end = datetime.strptime(a.end, '%Y-%m-%dT%H:%M:%SZ') days_left = (a.end - datetime.today()).days if days_left >= 0 and days_left <= 90: a.up_for_renewal = True a.renewal_days = days_left return render( request, 'projects/view_project.html', { 'project': project, 'users': users, 'is_pi': request.user.username == project.pi.username, 'form': form, })
def view_project(request, project_id): try: project = Project(project_id) if project.source != 'Chameleon': raise Http404('The requested project does not exist!') except Exception as e: logger.error(e) raise Http404('The requested project does not exist!') form = ProjectAddUserForm() nickname_form = EditNicknameForm() if request.POST: if 'add_user' in request.POST: form = ProjectAddUserForm(request.POST) if form.is_valid(): # try to add user try: add_username = form.cleaned_data['username'] if project.add_user(add_username): messages.success(request, 'User "%s" added to project!' % add_username) form = ProjectAddUserForm() except: logger.exception('Failed adding user') form.add_error('username', '') form.add_error('__all__', 'Unable to add user. Confirm that the ' 'username is correct.') else: form.add_error('__all__', 'There were errors processing your request. ' 'Please see below for details.') elif 'nickname' in request.POST: nickname_form = edit_nickname(request, project_id) else: form = ProjectAddUserForm() if 'del_user' in request.POST: # try to remove user try: del_username = request.POST['username'] if project.remove_user(del_username): messages.success(request, 'User "%s" removed from project' % del_username) except: logger.exception('Failed removing user') messages.error(request, 'An unexpected error occurred while attempting ' 'to remove this user. Please try again') users = project.get_users() if not project_member_or_admin_or_superuser(request.user, project, users): raise PermissionDenied project.active_allocations = [] project.approved_allocations = [] project.pending_allocations = [] project.rejected_allocations = [] project.inactive_allocations = [] for a in project.allocations: if a.status == 'Active' and a.resource == 'Chameleon': project.active_allocations.append(a) project.has_active_allocations = True if a.status == 'Approved' and a.resource == 'Chameleon': project.approved_allocations.append(a) project.has_approved_allocations = True if a.status == 'Pending' and a.resource == 'Chameleon': project.pending_allocations.append(a) project.has_pending_allocations = True if a.status == 'Inactive' and a.resource == 'Chameleon': project.inactive_allocations.append(a) project.has_inactive_allocations = True if a.status == 'Rejected' and a.resource == 'Chameleon': project.rejected_allocations.append(a) project.has_rejected_allocations = True if a.start and isinstance(a.start, basestring): a.start = datetime.strptime(a.start, '%Y-%m-%dT%H:%M:%SZ') if a.dateRequested: if isinstance(a.dateRequested, basestring): a.dateRequested = datetime.strptime(a.dateRequested, '%Y-%m-%dT%H:%M:%SZ') if a.dateReviewed: if isinstance(a.dateReviewed, basestring): a.dateReviewed = datetime.strptime(a.dateReviewed, '%Y-%m-%dT%H:%M:%SZ') if a.end: if isinstance(a.end, basestring): a.end = datetime.strptime(a.end, '%Y-%m-%dT%H:%M:%SZ') days_left = (a.end - datetime.today()).days if days_left >= 0 and days_left <= 90: a.up_for_renewal = True a.renewal_days = days_left try: extras = ProjectExtras.objects.get(tas_project_id=project_id) project_nickname = extras.nickname except ProjectExtras.DoesNotExist: project_nickname = None user_mashup = [] for u in users: if u.role == 'PI': # Exclude PI from member list continue user = {} user['username'] = u.username user['role'] = u.role try: portal_user = User.objects.get(username=u.username) user['email'] = portal_user.email user['first_name'] = portal_user.first_name user['last_name'] = portal_user.last_name except User.DoesNotExist: logger.info('user: '******' not found') user_mashup.append(user) return render(request, 'projects/view_project.html', { 'project': project, 'project_nickname': project_nickname, 'users': user_mashup, 'is_pi': request.user.username == project.pi.username, 'form': form, 'nickname_form': nickname_form, })