コード例 #1
0
ファイル: log.py プロジェクト: uw-it-aca/service-endorsement
def _get_user():
    user_svc = UserService()
    override_userid = user_svc.get_override_user()
    actual_userid = user_svc.get_original_user()
    log_userid = {'user': actual_userid}
    if override_userid:
        log_userid['override-as'] = override_userid
    return log_userid
コード例 #2
0
ファイル: log.py プロジェクト: uw-it-aca/gradepage
    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
コード例 #3
0
ファイル: log.py プロジェクト: uw-it-aca/retention-dashboard
    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
コード例 #4
0
ファイル: display_dates.py プロジェクト: fanglinfang/myuw
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))
コード例 #5
0
ファイル: display_dates.py プロジェクト: kroberts-uw/myuw
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)
コード例 #6
0
ファイル: views.py プロジェクト: uw-it-cte/uw-restclients
    def wrapper(*args, **kwargs):
        if not hasattr(settings, "RESTCLIENTS_ADMIN_GROUP"):
            print "You must have a group defined as your admin group."
            print 'Configure that using RESTCLIENTS_ADMIN_GROUP="u_foo_bar"'
            raise Exception("Missing RESTCLIENTS_ADMIN_GROUP in settings")

        user_service = UserService()
        actual_user = user_service.get_original_user()
        g = Group()

        is_admin = g.is_member_of_group(actual_user,
                                        settings.RESTCLIENTS_ADMIN_GROUP)

        if not is_admin:
            return HttpResponseRedirect("/")

        return view_func(*args, **kwargs)
コード例 #7
0
ファイル: logback.py プロジェクト: fanglinfang/myuw
def get_logging_userid():
    """
    Return <actual user netid> acting_as: <override user netid> if
    the user is acting as someone else, otherwise
    <actual user netid> no_override: <actual user netid>
    """
    user_svc = UserService()
    override_userid = user_svc.get_override_user()
    actual_userid = user_svc.get_original_user()
    log_format = 'base_user: %s acting_user: %s is_override: %s'
    try:
        if override_userid:
            log_userid = log_format % (actual_userid, override_userid, 'true')
        else:
            log_userid = log_format % (actual_userid, actual_userid, 'false')
    except TypeError:
        return None
    return log_userid
コード例 #8
0
ファイル: logback.py プロジェクト: kroberts-uw/myuw
def get_logging_userid():
    """
    Return <actual user netid> acting_as: <override user netid> if
    the user is acting as someone else, otherwise
    <actual user netid> no_override: <actual user netid>
    """
    user_svc = UserService()
    override_userid = user_svc.get_override_user()
    actual_userid = user_svc.get_original_user()
    log_format = 'base_user: %s acting_user: %s is_override: %s'
    try:
        if override_userid:
            log_userid = log_format % (actual_userid, override_userid, 'true')
        else:
            log_userid = log_format % (actual_userid, actual_userid, 'false')
    except TypeError:
        return None
    return log_userid
コード例 #9
0
    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)
コード例 #10
0
def proxy(request, service, url):

    if not hasattr(settings, "RESTCLIENTS_ADMIN_GROUP"):
        print "You must have a group defined as your admin group."
        print 'Configure that using RESTCLIENTS_ADMIN_GROUP="u_foo_bar"'
        raise Exception("Missing RESTCLIENTS_ADMIN_GROUP in settings")

    user_service = UserService()
    actual_user = user_service.get_original_user()
    g = Group()
    is_admin = g.is_member_of_group(actual_user,
                                    settings.RESTCLIENTS_ADMIN_GROUP)

    if not is_admin:
        return HttpResponseRedirect("/")

    use_pre = False
    headers = {}
    if service == "sws":
        dao = SWS_DAO()
        headers["X-UW-Act-as"] = actual_user
    elif service == "pws":
        dao = PWS_DAO()
    elif service == "gws":
        dao = GWS_DAO()
    elif service == "nws":
        dao = NWS_DAO()
    elif service == "hfs":
        dao = Hfs_DAO()
    elif service == "book":
        dao = Book_DAO()
    elif service == "canvas":
        dao = Canvas_DAO()
    elif service == "grad":
        dao = Grad_DAO()
    elif service == "uwnetid":
        dao = Uwnetid_DAO()
    elif service == "libraries":
        dao = MyLibInfo_DAO()
    elif service == "libcurrics":
        dao = LibCurrics_DAO()
    elif service == "myplan":
        dao = MyPlan_DAO()
    elif service == "iasystem":
        dao = IASYSTEM_DAO()
        headers = {"Accept": "application/vnd.collection+json"}
        subdomain = None
        if url.endswith('/evaluation'):
            if url.startswith('uwb/') or url.startswith('uwt/'):
                subdomain = url[:3]
                url = url[4:]
            else:
                subdomain = url[:2]
                url = url[3:]
    elif service == "calendar":
        dao = TrumbaCalendar_DAO()
        use_pre = True
    else:
        return HttpResponseNotFound("Unknown service: %s" % service)

    url = "/%s" % quote(url)

    if request.GET:
        try:
            url = "%s?%s" % (url, urlencode(request.GET))
        except UnicodeEncodeError:
            err = "Bad URL param given to the restclients browser"
            return HttpResponse(err)

    start = time()
    try:
        if service == "iasystem" and subdomain is not None:
            response = dao.getURL(url, headers, subdomain)
        else:
            response = dao.getURL(url, headers)
    except Exception as ex:
        response = MockHTTP()
        response.status = 500
        response.data = str(ex)

    end = time()

    # Assume json, and try to format it.
    try:
        if not use_pre:
            content = format_json(service, response.data)
            json_data = response.data
        else:
            content = response.data
            json_data = None
    except Exception as e:
        content = format_html(service, response.data)
        json_data = None

    context = {
        "url": unquote(url),
        "content": content,
        "json_data": json_data,
        "response_code": response.status,
        "time_taken": "%f seconds" % (end - start),
        "headers": response.headers,
        "override_user": user_service.get_override_user(),
        "use_pre": use_pre,
    }

    try:
        loader.get_template("restclients/extra_info.html")
        context["has_extra_template"] = True
        context["extra_template"] = "restclients/extra_info.html"
    except TemplateDoesNotExist:
        pass

    try:
        loader.get_template("restclients/proxy_wrapper.html")
        context["wrapper_template"] = "restclients/proxy_wrapper.html"
    except TemplateDoesNotExist:
        context["wrapper_template"] = "proxy_wrapper.html"

    try:
        search_template_path = re.sub(r"\..*$", "", url)
        search_template = "proxy/%s%s.html" % (service, search_template_path)
        loader.get_template(search_template)
        context["search_template"] = search_template
        context["search"] = format_search_params(url)
    except TemplateDoesNotExist:
        context["search_template"] = None

    return render_to_response("proxy.html",
                              context,
                              context_instance=RequestContext(request))
コード例 #11
0
ファイル: views.py プロジェクト: jeffFranklin/uw-restclients
def proxy(request, service, url):

    if not hasattr(settings, "RESTCLIENTS_ADMIN_GROUP"):
        print "You must have a group defined as your admin group."
        print 'Configure that using RESTCLIENTS_ADMIN_GROUP="u_foo_bar"'
        raise Exception("Missing RESTCLIENTS_ADMIN_GROUP in settings")

    user_service = UserService()
    actual_user = user_service.get_original_user()
    g = Group()
    is_admin = g.is_member_of_group(actual_user, settings.RESTCLIENTS_ADMIN_GROUP)

    if not is_admin:
        return HttpResponseRedirect("/")

    use_pre = False
    headers = {}
    if service == "sws":
        dao = SWS_DAO()
        headers["X-UW-Act-as"] = actual_user
    elif service == "pws":
        dao = PWS_DAO()
    elif service == "gws":
        dao = GWS_DAO()
    elif service == "nws":
        dao = NWS_DAO()
    elif service == "hfs":
        dao = Hfs_DAO()
    elif service == "book":
        dao = Book_DAO()
    elif service == "canvas":
        dao = Canvas_DAO()
    elif service == "uwnetid":
        dao = Uwnetid_DAO()
    elif service == "libraries":
        dao = Libraries_DAO()
    elif service == "myplan":
        dao = MyPlan_DAO()
    elif service == "calendar":
        dao = TrumbaCalendar_DAO()
        use_pre = True
    else:
        return HttpResponseNotFound("Unknown service: %s" % service)

    url = "/%s" % quote(url)

    if request.GET:
        url = "%s?%s" % (url, urlencode(request.GET))

    start = time()
    try:
        response = dao.getURL(url, headers)
    except Exception as ex:
        response = MockHTTP()
        response.status = 500
        response.data = str(ex)

    end = time()

    # Assume json, and try to format it.
    try:
        if not use_pre:
            content = format_json(service, response.data)
            json_data = response.data;
        else:
            content = response.data
            json_data = None
    except Exception as e:
        content = format_html(service, response.data)
        json_data = None;

    context = {
        "url": unquote(url),
        "content": content,
        "json_data": json_data,
        "response_code": response.status,
        "time_taken": "%f seconds" % (end - start),
        "headers": response.headers,
        "override_user": user_service.get_override_user(),
        "use_pre": use_pre,
    }

    try:
        loader.get_template("restclients/extra_info.html")
        context["has_extra_template"] = True
        context["extra_template"] = "restclients/extra_info.html"
    except TemplateDoesNotExist:
        pass

    try:
        loader.get_template("restclients/proxy_wrapper.html")
        context["wrapper_template"] = "restclients/proxy_wrapper.html"
    except TemplateDoesNotExist:
        context["wrapper_template"] = "proxy_wrapper.html"

    try:
        search_template_path = re.sub(r"\..*$", "", url)
        search_template = "proxy/%s%s.html" % (service, search_template_path)
        loader.get_template(search_template)
        context["search_template"] = search_template
        context["search"] = format_search_params(url)
    except TemplateDoesNotExist:
        context["search_template"] = None

    return render_to_response("proxy.html",
                              context,
                              context_instance=RequestContext(request))
コード例 #12
0
ファイル: views.py プロジェクト: devights/django-userservice
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))
コード例 #13
0
 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
コード例 #14
0
ファイル: log.py プロジェクト: btb/django-panopto-scheduler
 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
コード例 #15
0
ファイル: views.py プロジェクト: uw-it-cte/uw-restclients
def proxy(request, service, url):
    user_service = UserService()
    actual_user = user_service.get_original_user()

    use_pre = False
    headers = {}
    if service == "sws":
        dao = SWS_DAO()
        headers["X-UW-Act-as"] = actual_user
    elif service == "pws":
        dao = PWS_DAO()
    elif service == "gws":
        dao = GWS_DAO()
    elif service == "nws":
        dao = NWS_DAO()
    elif service == "hfs":
        dao = Hfs_DAO()
    elif service == "book":
        dao = Book_DAO()
    elif service == "canvas":
        dao = Canvas_DAO()
    elif service == "grad":
        dao = Grad_DAO()
    elif service == "uwnetid":
        dao = Uwnetid_DAO()
    elif service == "libraries":
        dao = MyLibInfo_DAO()
    elif service == "libcurrics":
        dao = LibCurrics_DAO()
    elif service == "myplan":
        dao = MyPlan_DAO()
    elif service == "iasystem":
        dao = IASYSTEM_DAO()
        headers = {"Accept": "application/vnd.collection+json"}
        subdomain = None
        if url.endswith('/evaluation'):
            if url.startswith('uwb/') or url.startswith('uwt/'):
                subdomain = url[:3]
                url = url[4:]
            else:
                subdomain = url[:2]
                url = url[3:]

    elif service == "calendar":
        dao = TrumbaCalendar_DAO()
        use_pre = True
    else:
        return HttpResponseNotFound("Unknown service: %s" % service)

    url = "/%s" % quote(url)

    if request.GET:
        try:
            url = "%s?%s" % (url, urlencode(request.GET))
        except UnicodeEncodeError:
            err = "Bad URL param given to the restclients browser"
            return HttpResponse(err)

    start = time()
    try:
        if service == "iasystem" and subdomain is not None:
            response = dao.getURL(url, headers, subdomain)
        else:
            if service == "libcurrics":
                if "?campus=" in url:
                    url = url.replace("?campus=", "/")
                elif "course?" in url:
                    url_prefix = re.sub(r'\?.*$', "", url)
                    url = "%s/%s/%s/%s/%s/%s" % (
                        url_prefix,
                        request.GET["year"],
                        request.GET["quarter"],
                        request.GET["curriculum_abbr"].replace(" ", "%20"),
                        request.GET["course_number"],
                        request.GET["section_id"])

            response = dao.getURL(url, headers)
    except Exception as ex:
        response = MockHTTP()
        response.status = 500
        response.data = str(ex)

    end = time()

    # Assume json, and try to format it.
    try:
        if not use_pre:
            content = format_json(service, response.data)
            json_data = response.data
        else:
            content = response.data
            json_data = None
    except Exception as e:
        content = format_html(service, response.data)
        json_data = None

    context = {
        "url": unquote(url),
        "content": content,
        "json_data": json_data,
        "response_code": response.status,
        "time_taken": "%f seconds" % (end - start),
        "headers": response.headers,
        "override_user": user_service.get_override_user(),
        "use_pre": use_pre,
    }

    try:
        loader.get_template("restclients/extra_info.html")
        context["has_extra_template"] = True
        context["extra_template"] = "restclients/extra_info.html"
    except TemplateDoesNotExist:
        pass

    set_wrapper_template(context)

    try:
        search_template_path = re.sub(r"\..*$", "", url)
        search_template = "proxy/%s%s.html" % (service, search_template_path)
        loader.get_template(search_template)
        context["search_template"] = search_template
        context["search"] = format_search_params(url)
    except TemplateDoesNotExist:
        context["search_template"] = None

    return render(request, "proxy.html", context)