from urllib.error import URLError from django.conf import settings from django.http import HttpResponse, HttpResponseBadRequest from django.shortcuts import render from django.utils.decorators import method_decorator from django.views import View from pivot.utils import get_latest_term, get_file_data from uw_saml.decorators import group_required logger = getLogger(__name__) PIVOT_ACCESS_GROUP = settings.PIVOT_AUTHZ_GROUPS["access"] @method_decorator(group_required(PIVOT_ACCESS_GROUP), name="dispatch") class DataFileView(View): file_name = None def get(self, request): try: return HttpResponse(get_file_data(self.file_name)) except FileNotFoundError as err: logger.warning( "Error {}: {} not found.".format(err.errno, err.filename)) return HttpResponse("Data not available", status=416) @method_decorator(group_required(PIVOT_ACCESS_GROUP), name="dispatch") class DataFileByQuarterView(DataFileView): """ Base class for views that take a time period queries
import os import json from django.conf import settings from django.utils.decorators import method_decorator from uw_saml.decorators import group_required from retention_dashboard.views.api import RESTDispatch from retention_dashboard.dao.data import FilterDataDao from retention_dashboard.dao.auth import get_type_authorizations from retention_dashboard.models import Advisor, Week, Sport, DataPoint from logging import getLogger logger = getLogger(__name__) @method_decorator(group_required(settings.ALLOWED_USERS_GROUP), name='dispatch') class DataView(RESTDispatch): def get(self, request, week, file, *args, **kwargs): logger.info('load dataset, type: %s, week: %s' % (file, week)) file_path = os.path.join(settings.BASE_DIR, "retention_dashboard/data", week, file) with open(file_path, 'r') as content_file: content = content_file.read() return self.json_response(content={"data": content}) @method_decorator(group_required(settings.ALLOWED_USERS_GROUP), name='dispatch') class WeekView(RESTDispatch):
# SPDX-License-Identifier: Apache-2.0 from django.conf import settings from django.shortcuts import render, get_object_or_404 from django.utils.decorators import method_decorator from django.views.generic.list import ListView from uw_saml.decorators import group_required from .models import Code, Interview admin_group = settings.INTERVIEW_DB_AUTHZ_GROUPS['admin'] front_end_group = settings.INTERVIEW_DB_AUTHZ_GROUPS['front-end'] @method_decorator(group_required(front_end_group), name='dispatch') class IndexView(ListView): template_name = 'index.html' context_object_name = 'interview_list' def get_queryset(self): return Interview.objects.order_by('student') @method_decorator(group_required(front_end_group), name='dispatch') class InterviewsView(ListView): template_name = 'interviews.html' context_object_name = 'interview_list' def get_queryset(self): return Interview.objects.order_by('student')
import logging from django.conf import settings from django.utils.decorators import method_decorator from uw_saml.decorators import group_required from endorsement.dao.endorse import get_endorsement_records_for_endorsee_re from endorsement.util.time_helper import Timer from endorsement.util.log import log_resp_time, log_data_error_response from endorsement.views.rest_dispatch import RESTDispatch logger = logging.getLogger(__name__) @method_decorator( group_required(settings.PROVISION_ADMIN_GROUP), name='dispatch') class Endorsee(RESTDispatch): """ Show endorsements for endorsee """ def get(self, request, *args, **kwargs): timer = Timer() endorsee_regex = self.kwargs['endorsee'] endorsees = { 'endorsements': [] } try: for er in get_endorsement_records_for_endorsee_re(endorsee_regex): endorsees['endorsements'].append(er.json_data()) except Exception:
from sis_provisioner.dao.term import get_current_active_term from sis_provisioner.models.admin import Admin from restclients_core.exceptions import DataFailureException from uw_saml.decorators import group_required from uw_saml.utils import get_user, is_member_of_group from logging import getLogger import json logger = getLogger(__name__) def can_view_source_data(request, service=None, url=None): return is_member_of_group(request, settings.RESTCLIENTS_ADMIN_GROUP) @method_decorator(group_required(settings.CANVAS_MANAGER_ADMIN_GROUP), name='dispatch') class AdminView(View): def get(self, request, *args, **kwargs): return render(request, self.template_name, self._params(request)) def _params(self, request): try: term = get_current_active_term() curr_year = term.year curr_quarter = term.quarter except DataFailureException as ex: logger.info('GET active term failed: {}'.format(ex)) curr_year = '' curr_quarter = ''
from logging import getLogger from django.conf import settings from django.utils.decorators import method_decorator from scheduled_job_manager.models import Job from scheduled_job_manager.views.rest_dispatch import RESTDispatch from uw_saml.decorators import group_required logger = getLogger(__name__) def can_manage_jobs(): return False @method_decorator(group_required(settings.SCHEDULED_JOB_ADMIN_GROUP), name='dispatch') class JobManagerAPI(RESTDispatch): """ Retrieves a list of Jobs. """ def get(self, request, *args, **kwargs): jobs = [] for job in Job.objects.all(): # .order_by(''): data = job.json_data() jobs.append(data) return self.json_response({'jobs': jobs})
# Copyright 2022 UW-IT, University of Washington # SPDX-License-Identifier: Apache-2.0 from django.conf import settings from django.contrib.auth.models import AnonymousUser, User from django.contrib.sessions.middleware import SessionMiddleware from django.http import HttpResponse from django.test import TestCase, RequestFactory from django.utils.decorators import method_decorator from django.views.generic.base import View from uw_saml.decorators import group_required @method_decorator(group_required('u_test_group'), name='dispatch') class GroupRequiredView(View): def get(request, *args, **kwargs): return HttpResponse('OK') class DecoratorTest(TestCase): def setUp(self): self.request = RequestFactory().get('/') self.request.user = User() SessionMiddleware().process_request(self.request) self.request.session.save() def test_group_required_noauth(self): self.request.user = AnonymousUser() view_instance = GroupRequiredView.as_view() response = view_instance(self.request)
# SPDX-License-Identifier: Apache-2.0 import traceback from django.conf import settings from django.utils.decorators import method_decorator from django.views.decorators.csrf import csrf_exempt from django.core.management import call_command from uw_saml.decorators import group_required from userservice.user import get_original_user from retention_dashboard.models import Week, Upload from retention_dashboard.views.api import RESTDispatch from retention_dashboard.views.api.forms import StorageForm, LocalDataForm from retention_dashboard.dao.admin import StorageDao, UploadDataDao @method_decorator(group_required(settings.ADMIN_USERS_GROUP), name='dispatch') class WeekAdmin(RESTDispatch): def post(self, request): try: year = request.POST.get("year") quarter = request.POST.get("quarter") week = request.POST.get("week") week, created = Week.objects.get_or_create(year=year, quarter=quarter, number=week) except ValueError as ex: return self.error_response(status=400, message=ex) except Exception as ex: return self.error_response(status=500, message=ex) return self.json_response({"created": created})
from course_grader.views.rest_dispatch import RESTDispatch from course_grader.models import ( SubmittedGradeRoster as SubmittedGradeRosterModel) from course_grader.dao.person import person_from_regid, person_display_name from course_grader.dao.section import section_from_label from course_grader.dao.term import term_from_param from uw_sws_graderoster.models import GradeRoster from lxml import etree import logging import csv logger = logging.getLogger(__name__) @method_decorator(group_required(settings.GRADEPAGE_SUPPORT_GROUP), name='dispatch') @method_decorator(never_cache, name='dispatch') class SubmissionsByTerm(RESTDispatch): def get(self, request, *args, **kwargs): term_id = kwargs.get("term_id") try: selected_term = term_from_param(term_id) except Exception as ex: return self.error_response(400, "Invalid Term ID") graderosters = SubmittedGradeRosterModel.objects.get_status_by_term( selected_term) response = self.csv_response(filename=term_id)