• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

gcivil-nyu-org / team4-wed-fall25 / 112

07 Dec 2025 03:22AM UTC coverage: 91.325% (+0.5%) from 90.869%
112

push

travis-pro

web-flow
Merge pull request #111 from gcivil-nyu-org/fix/imp_issues

fixed all the issues

42 of 68 new or added lines in 4 files covered. (61.76%)

1 existing line in 1 file now uncovered.

2095 of 2294 relevant lines covered (91.33%)

0.91 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.89
/note2webapp/decorators.py
1
from functools import wraps
1✔
2

3
from django.contrib import messages
1✔
4
from django.contrib.auth.decorators import login_required
1✔
5
from django.shortcuts import redirect
1✔
6

7

8
def role_required(*allowed_roles):
1✔
9
    """
10
    Decorator that:
11
    - requires the user to be logged in
12
    - checks that user.profile.role is in allowed_roles
13
    - otherwise redirects them to the main dashboard
14
    """
15
    allowed_roles = set(allowed_roles)
1✔
16

17
    def decorator(view_func):
1✔
18
        @wraps(view_func)
1✔
19
        @login_required
1✔
20
        def _wrapped_view(request, *args, **kwargs):
1✔
21
            profile = getattr(request.user, "profile", None)
1✔
22
            role = getattr(profile, "role", None)
1✔
23

24
            if role not in allowed_roles:
1✔
NEW
25
                messages.error(
×
26
                    request,
27
                    "You do not have permission to access that page.",
28
                )
NEW
29
                return redirect("dashboard")  # send them to their own dashboard
×
30

31
            return view_func(request, *args, **kwargs)
1✔
32

33
        return _wrapped_view
1✔
34

35
    return decorator
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc