Example #1
0
    def _decorator(request, *args, **kwargs):
        if user_is_group(request.session['ocf_user']):
            return function(request, *args, **kwargs)

        return render(request, 'group_accounts_only.html', {
            'user': request.session['ocf_user']
        }, status=403)
Example #2
0
    def _decorator(request, *args, **kwargs):
        if user_is_group(request.session['ocf_user']):
            return function(request, *args, **kwargs)

        return render(request,
                      'group_accounts_only.html',
                      {'user': request.session['ocf_user']},
                      status=403)
Example #3
0
    def _decorator(request, *args, **kwargs):
        try:
            user = logged_in_user(request)
        except KeyError:
            user = None

        if user and user_is_group(logged_in_user(request)):
            return function(request, *args, **kwargs)

        return render(request, 'group_accounts_only.html', {
            'user': user,
        }, status=403)
Example #4
0
    def _decorator(request: HttpRequest, *args: Any, **kwargs: Any) -> Any:
        try:
            user: Optional[str] = logged_in_user(request)
        except KeyError:
            user = None

        if user and user_is_group(logged_in_user(request)):
            return function(request, *args, **kwargs)

        return render(
            request, 'group_accounts_only.html', {
                'user': user,
            }, status=403,
        )
Example #5
0
def ocf_template_processor(request):
    hours = Day.from_date(date.today())
    real_ip = get_real_ip(request)
    user = logged_in_user(request)
    return {
        'base_css_classes': ' '.join(get_base_css_classes(request)),
        'current_lab_hours': hours,
        'is_ocf_ip': is_ocf_ip(ip_address(real_ip)) if real_ip else True,
        'join_staff_url': request.build_absolute_uri(reverse('about-staff')),
        'lab_is_open': hours.is_open(),
        'lab_status': get_lab_status(),
        'ocfweb_version': ocfweb_version(),
        'request_full_path': request.get_full_path(),
        'user': user,
        'user_is_group': user is not None and user_is_group(user),
    }
Example #6
0
def ocf_template_processor(request):
    hours = Day.from_date(date.today())
    real_ip = get_real_ip(request)
    user = logged_in_user(request)
    return {
        'base_css_classes': ' '.join(get_base_css_classes(request)),
        'current_lab_hours': hours,
        'is_ocf_ip': is_ocf_ip(ip_address(real_ip)) if real_ip else True,
        'join_staff_url': request.build_absolute_uri(reverse('about-staff')),
        'lab_is_open': hours.is_open(),
        'lab_status': get_lab_status(),
        'ocfweb_version': ocfweb_version(),
        'request_full_path': request.get_full_path(),
        'user': user,
        'user_is_group': user is not None and user_is_group(user),
    }
Example #7
0
def ocf_template_processor(request: HttpRequest) -> Dict[str, Any]:
    hours_listing = get_hours_listing()
    real_ip, _ = get_client_ip(request)
    user = logged_in_user(request)
    return {
        'base_css_classes': ' '.join(get_base_css_classes(request)),
        'current_lab_hours': hours_listing.hours_on_date(),
        'holidays': hours_listing.holidays,
        'is_ocf_ip': is_ocf_ip(ip_address(real_ip)) if real_ip else True,
        'join_staff_url': request.build_absolute_uri(reverse('about-staff')),
        'lab_is_open': hours_listing.is_open(),
        'lab_status': get_lab_status(),
        'ocfweb_version': ocfweb_version(),
        'request_full_path': request.get_full_path(),
        'user': user,
        'user_is_group': user is not None and user_is_group(user),
    }
Example #8
0
def get_quota(c, user):
    """Return a UserQuota representing the user's quota."""
    if is_in_group(user, 'opstaff'):
        return UserQuota(user, 500, 500)

    if not user_exists(user) or user_is_group(user):
        return UserQuota(user, 0, 0)

    c.execute('SELECT `today`, `semester` FROM `printed` WHERE `user` = %s',
              (user, ))

    row = c.fetchone()
    if not row:
        row = {'today': 0, 'semester': 0}
    semesterly = max(0, SEMESTERLY_QUOTA - int(row['semester']))
    return UserQuota(
        user=user,
        daily=max(0, min(semesterly,
                         daily_quota() - int(row['today']))),
        semesterly=semesterly,
    )
Example #9
0
def get_quota(c, user):
    """Return a UserQuota representing the user's quota."""
    if user == 'pubstaff':
        return UserQuota('pubstaff', 500, 500)

    if not user_exists(user) or user_is_group(user):
        return UserQuota(user, 0, 0)

    c.execute(
        'SELECT `today`, `semester` FROM `printed` WHERE `user` = %s',
        (user,)
    )

    row = c.fetchone()
    if not row:
        row = {'today': 0, 'semester': 0}
    semesterly = max(0, SEMESTERLY_QUOTA - int(row['semester']))
    return UserQuota(
        user=user,
        daily=max(0, min(semesterly, daily_quota() - int(row['today']))),
        semesterly=semesterly,
    )
Example #10
0
 def test_user_is_group(self, user, exists):
     assert user_is_group(user) == exists
Example #11
0
 def test_notexistent_user(self):
     with pytest.raises(Exception):
         user_is_group('doesnotexist')
Example #12
0
 def test_notexistent_user(self):
     with pytest.raises(Exception):
         user_is_group('doesnotexist')
Example #13
0
 def test_user_is_group(self, user, exists):
     assert user_is_group(user) == exists