def override(request): logger = logging.getLogger(__name__) user_service = UserService() user_service.get_user() override_error_username = None override_error_msg = None # Do the group auth here. if not hasattr(settings, "USERSERVICE_ADMIN_GROUP"): print "You must have a group defined as your admin group." print 'Configure that using USERSERVICE_ADMIN_GROUP="foo_group"' raise Exception("Missing USERSERVICE_ADMIN_GROUP in settings") actual_user = user_service.get_original_user() if not actual_user: raise Exception("No user in session") g = Group() group_name = settings.USERSERVICE_ADMIN_GROUP is_admin = g.is_member_of_group(actual_user, group_name) if is_admin is False: return render_to_response('no_access.html', {}) context = {} if request.method == "POST": _handle_post(request, context) try: extra_template = "userservice/user_override_extra_info.html" template.loader.get_template(extra_template) context['has_extra_template'] = True context['extra_template'] = 'userservice/user_override_extra_info.html' except template.TemplateDoesNotExist: # This is a fine exception - there doesn't need to be an extra info # template pass try: template.loader.get_template("userservice/user_override_wrapper.html") context['wrapper_template'] = 'userservice/user_override_wrapper.html' except template.TemplateDoesNotExist: context['wrapper_template'] = 'support_wrapper.html' # This is a fine exception - there doesn't need to be an extra info # template pass add_session_context(request, context) add_date_term_info(request, context) add_seen_registration_context(request, context) return render_to_response("display_dates/override.html", context, context_instance=RequestContext(request))
def override(request): logger = logging.getLogger(__name__) user_service = UserService() user_service.get_user() override_error_username = None override_error_msg = None # Do the group auth here. if not hasattr(settings, "USERSERVICE_ADMIN_GROUP"): print "You must have a group defined as your admin group." print 'Configure that using USERSERVICE_ADMIN_GROUP="foo_group"' raise Exception("Missing USERSERVICE_ADMIN_GROUP in settings") actual_user = user_service.get_original_user() if not actual_user: raise Exception("No user in session") g = Group() group_name = settings.USERSERVICE_ADMIN_GROUP is_admin = g.is_member_of_group(actual_user, group_name) if is_admin is False: return render(request, 'no_access.html', {}) context = {} if request.method == "POST": _handle_post(request, context) try: extra_template = "userservice/user_override_extra_info.html" template.loader.get_template(extra_template) context['has_extra_template'] = True context['extra_template'] = 'userservice/user_override_extra_info.html' except template.TemplateDoesNotExist: # This is a fine exception - there doesn't need to be an extra info # template pass try: template.loader.get_template("userservice/user_override_wrapper.html") context['wrapper_template'] = 'userservice/user_override_wrapper.html' except template.TemplateDoesNotExist: context['wrapper_template'] = 'support_wrapper.html' # This is a fine exception - there doesn't need to be an extra info # template pass add_session_context(request, context) add_date_term_info(request, context) add_seen_registration_context(request, context) return render(request, "display_dates/override.html", context)
def user(request): user_service = UserService() try: user = person_from_username(user_service.get_user()) user_fullname = display_name(user.first_name, user.surname) except Exception as ex: user_fullname = None return { "user_login": user_service.get_user(), "user_fullname": user_fullname, "override_user": user_service.get_override_user(), }
def run(self, *args, **named_args): request = args[0] user_service = UserService() netid = user_service.get_user() if not netid: return invalid_session() if "GET" == request.META['REQUEST_METHOD']: if hasattr(self, "GET"): return self.GET(*args, **named_args) else: return invalid_method() elif "POST" == request.META['REQUEST_METHOD']: if hasattr(self, "POST"): return self.POST(*args, **named_args) else: return invalid_method() elif "PUT" == request.META['REQUEST_METHOD']: if hasattr(self, "PUT"): return self.PUT(*args, **named_args) else: return invalid_method() elif "DELETE" == request.META['REQUEST_METHOD']: if hasattr(self, "DELETE"): return self.DELETE(*args, **named_args) else: return invalid_method() else: return invalid_method()
def filter(self, record): from userservice.user import UserService user_service = UserService() try: record.user = user_service.get_original_user() or "-" record.actas = (user_service.get_user() or "-").lower() except Exception as ex: record.user = "******" record.actas = "-" return True
def user(request): try: user_fullname = person_display_name(person_from_user()) except Exception as ex: user_fullname = None user_service = UserService() return { "user_login": user_service.get_user(), "user_fullname": user_fullname, "override_user": user_service.get_override_user(), }
def post(self, request, *args, **kwargs): timer = Timer() try: accept = json.loads(request.read()) accept_id = accept['accept_id'] except KeyError: return invalid_session(logger, timer) user_service = UserService() netid = user_service.get_user() if not netid: return invalid_session(logger, timer) original_user = user_service.get_original_user() acted_as = None if (netid == original_user) else original_user records = EndorsementRecord.objects.get_accept_endorsement(accept_id) if len(records) != 1: return invalid_session(logger, timer) record = records[0] is_o365 = ( record.category_code == EndorsementRecord.OFFICE_365_ENDORSEE) is_google = ( record.category_code == EndorsementRecord.GOOGLE_SUITE_ENDORSEE) if is_o365: json_data = store_office365_endorsement( record.endorser, record.endorsee, acted_as, record.reason).json_data() elif is_google: json_data = store_google_endorsement( record.endorser, record.endorsee, acted_as, record.reason).json_data() json_data['is_o365'] = is_o365 json_data['is_google'] = is_google return self.json_response(json_data)
def support(request): #timer = Timer() logger = logging.getLogger(__name__) user_service = UserService() user_service.get_user() override_error_username = None override_error_msg = None # Do the group auth here. if not hasattr(settings, "USERSERVICE_ADMIN_GROUP"): print "You must have a group defined as your admin group." print 'Configure that using USERSERVICE_ADMIN_GROUP="foo_group"' raise Exception("Missing USERSERVICE_ADMIN_GROUP in settings") actual_user = user_service.get_original_user() if not actual_user: raise Exception("No user in session") g = Group() group_name = settings.USERSERVICE_ADMIN_GROUP is_admin = g.is_member_of_group(actual_user, group_name) if is_admin == False: return render_to_response('no_access.html', {}) if "override_as" in request.POST: new_user = request.POST["override_as"].strip() validation_module = _get_validation_module() validation_error = validation_module(new_user) if validation_error is None: logger.info("%s is impersonating %s", user_service.get_original_user(), new_user) user_service.set_override_user(new_user) else: override_error_username = new_user override_error_msg = validation_error if "clear_override" in request.POST: logger.info("%s is ending impersonation of %s", user_service.get_original_user(), user_service.get_override_user()) user_service.clear_override() context = { 'original_user': user_service.get_original_user(), 'override_user': user_service.get_override_user(), 'override_error_username': override_error_username, 'override_error_msg': override_error_msg, } try: template.loader.get_template("userservice/user_override_extra_info.html") context['has_extra_template'] = True except template.TemplateDoesNotExist: # This is a fine exception - there doesn't need to be an extra info # template pass return render_to_response('support.html', context, context_instance=RequestContext(request))
def filter(self, record): user_service = UserService() record.user = user_service.get_original_user() or "-" record.actas = (user_service.get_user() or "-").lower() return True