Skip to content

Commit b9d6cfd

Browse files
tyklingpre-commit-ci[bot]zarya
authored
oidc support (#1802)
* oidc support part 1 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Added Custom OAuth2Validator * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * make claims discoverable, make oidc config view work for anonymous users * syntax * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add scope phonebook:admin to include the non-public phonebook info * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Removed unneeded var * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * return username instead of user pk in the sub claim * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * update scope descriptions a bit * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * remove old .travis.yml * add CI settings * make pre-commit happy * Added groups and permissions claim * use uuid as username in bootstrap * add permissions by group view in backoffice * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * add default team slug * Add tab targets to the url * add another back button * add even more back buttons * rework oidc claims and scopes, add profile fields for phonenumber and location * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Added form extras to profile form template * Switch to leaflet, add default locaton, add location field allow blank * add updated_at claim under the profile scope * add a bit of oidc readme * Remove default * add blank=True to Profile.phonenumber --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Rudy (zarya) <git@gigafreak.net>
1 parent d0c861b commit b9d6cfd

25 files changed

+399
-46
lines changed

.travis.yml

Lines changed: 0 additions & 29 deletions
This file was deleted.

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,22 @@ Otherwise start uwsgi or similar to serve the application.
160160

161161
Enjoy!
162162

163+
164+
## OIDC IDP
165+
166+
The BornHack website can act as an OIDC IDP. You are welcome to use it for your projects.
167+
168+
169+
### OIDC User Claims
170+
171+
The supported standard and custom OIDC user claims can be seen in `bornhack/oauth_validators.py` https://github.com/bornhack/bornhack-website/blob/master/src/bornhack/oauth_validators
172+
173+
174+
### OIDC Scopes
175+
176+
Supported oauth2 scopes are split between standard OIDC claim scopes, custom OIDC claim scopes, and API scopes. The current list of supported scopes can be seen in the `OAUTH2_PROVIDER["SCOPES"]` dict in `bornhack/settings.py` https://github.com/bornhack/bornhack-website/blob/master/src/bornhack/settings.py
177+
178+
163179
## Notes
164180

165181
### Running tests

src/backoffice/templates/includes/index_permissions.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ <h3>Permissions</h3>
44
<h4 class="list-group-item-heading">Show Permissions (by User)</h4>
55
<p class="list-group-item-text">Use this view to see permissions in a table with a row per user.</p>
66
</a>
7+
<a href="{% url 'backoffice:permission_list_by_group' camp_slug=camp.slug %}" class="list-group-item list-group-item-action">
8+
<h4 class="list-group-item-heading">Show Permissions (by Group)</h4>
9+
<p class="list-group-item-text">Use this view to see a list of groups and their permissions.</p>
10+
</a>
711
<a href="{% url 'backoffice:permission_list_by_permission' camp_slug=camp.slug %}" class="list-group-item list-group-item-action">
812
<h4 class="list-group-item-heading">Show Permissions (by Permission)</h4>
913
<p class="list-group-item-text">Use this view to see permissions in a table with a row per permission.</p>

src/backoffice/templates/includes/permissions_explainer.html

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@
22
<p>
33
<dl>
44
<dt>lead</dt>
5-
<dd>The team lead permission enables a user to manage team memberships and permissions. This permission is granted to and removed from team leads automatically when the team membership is updated. Codename <b>camps.{{ team.slug }}_team_lead</b>.</dd>
5+
<dd>The team lead permission enables a user to manage team memberships and permissions. This permission is granted to and removed from team leads automatically when the team membership is updated. Codename <b>camps.{{ team.slug | default:"TEAM" }}_team_lead</b>.</dd>
66
<dt>member</dt>
7-
<dd>The team member permission grants access to the team area with tasks and the team guide. It also grants access to handle facility feedback in backoffice. Some sections of backoffice and the main site are restricted to users with this permission. Codename <b>camps.{{ team.slug }}_team_member</b>.</dd>
7+
<dd>The team member permission grants access to the team area with tasks and the team guide. It also grants access to handle facility feedback in backoffice. Some sections of backoffice and the main site are restricted to users with this permission. Codename <b>camps.{{ team.slug | default:"TEAM" }}_team_member</b>.</dd>
88
<dt>mapper</dt>
9-
<dd>The team mapper permission grants access to gis/map layer management in backoffice. Codename <b>camps.{{ team.slug }}_team_mapper</b>.</dd>
9+
<dd>The team mapper permission grants access to gis/map layer management in backoffice. Codename <b>camps.{{ team.slug | default:"TEAM" }}_team_mapper</b>.</dd>
1010
<dt>facilitator</dt>
11-
<dd>The team facilitator permission grants access to manage facilities in backoffice. Codename <b>camps.{{ team.slug }}_team_facilitator</b>.</dd>
11+
<dd>The team facilitator permission grants access to manage facilities in backoffice. Codename <b>camps.{{ team.slug | default:"TEAM" }}_team_facilitator</b>.</dd>
1212
<dt>infopager</dt>
13-
<dd>The team infopager permission grants access to manage infopage sections for the team. Codename <b>camps.{{ team.slug }}_team_infopager</b>.</dd>
13+
<dd>The team infopager permission grants access to manage infopage sections for the team. Codename <b>camps.{{ team.slug | default:"TEAM" }}_team_infopager</b>.</dd>
1414
<dt>pos</dt>
15-
<dd>The team pos permission grants access to submit point-of-sale reports on behalf of the team. Codename <b>camps.{{ team.slug }}_team_pos</b>.</dd>
15+
<dd>The team pos permission grants access to submit point-of-sale reports on behalf of the team. Codename <b>camps.{{ team.slug | default:"TEAM" }}_team_pos</b>.</dd>
16+
</p>
17+
<p>
18+
<a href="{% url 'backoffice:index' camp_slug=camp.slug %}" class="btn btn-secondary"><i class="fas fa-undo"></i> Backoffice</a>
19+
<a href="{% url 'backoffice:index' camp_slug=camp.slug %}#permissions" class="btn btn-secondary"><i class="fas fa-undo"></i> Permissions</a>
1620
</p>
17-
<p><a href="{% url 'backoffice:index' camp_slug=camp.slug %}" class="btn btn-default"><i class="fas fa-undo"></i> Backoffice</a></p>

src/backoffice/templates/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ <h3 class="ms-3">{{ camp.title }} Backoffice</h3>
1616
<ul class="nav nav-tabs" role="tablist">
1717
{% for item, value in backoffice_tabs.items %}
1818
<li class="nav-item" role="presentation" class="active">
19-
<a class="nav-link{% if forloop.first %} active{% endif %}" href="#{{ item }}" aria-controls="one" aria-selected="true" role="tab" data-bs-toggle="tab">
19+
<a class="nav-link{% if forloop.first %} active{% endif %}" href="#{{ item }}" aria-controls="one" aria-selected="true" role="tab" data-bs-toggle="tab" data-bs-target="#{{ item }}">
2020
{{ value.name }}{% if value.count %} <span class="badge rounded-pill text-bg-danger">{{ value.count }}</span>{% endif %}
2121
</a>
2222
</li>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{% extends 'base.html' %}
2+
{% load bornhack %}
3+
4+
{% block title %}
5+
Permissions by Group | Backoffice | {{ block.super }}
6+
{% endblock %}
7+
8+
{% block content %}
9+
<div class="panel panel-default">
10+
<div class="panel-heading"><h3 class="panel-title">Permissions by Group - BackOffice</h3></div>
11+
<div class="panel-body">
12+
<p>A list of groups and their assigned custom bornhack permissions. Groups with no permissions are not included in this table. Ask orga to change group permissions if needed.</p>
13+
{% include "includes/permissions_explainer.html" %}
14+
<table class="table table-striped table-hover datatable">
15+
<thead>
16+
<tr>
17+
<th>Group Name</th>
18+
<th>Group Permissions</th>
19+
</tr>
20+
</thead>
21+
<tbody>
22+
{% for group in group_list %}
23+
<tr>
24+
<td>{{ group.name }}</td>
25+
<td>
26+
<ul>{% for perm in group.permissions.all %}
27+
<li><strong>camps.{{ perm.codename }}</strong> ({{ perm.name }})</li>
28+
{% endfor %}</ul>
29+
</td>
30+
</tr>
31+
{% endfor %}
32+
</tbody>
33+
</table>
34+
<p>
35+
<a class="btn btn-secondary" href="{% url 'backoffice:index' camp_slug=camp.slug %}"><i class="fas fa-undo"></i> Backoffice</a>
36+
<a href="{% url 'backoffice:index' camp_slug=camp.slug %}#permissions" class="btn btn-secondary"><i class="fas fa-undo"></i> Permissions</a>
37+
</p>
38+
</div>
39+
</div>
40+
{% endblock content %}

src/backoffice/templates/permissions_by_permission.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
</table>
4646
<p>
4747
<a class="btn btn-secondary" href="{% url 'backoffice:index' camp_slug=camp.slug %}"><i class="fas fa-undo"></i> Backoffice</a>
48+
<a href="{% url 'backoffice:index' camp_slug=camp.slug %}#permissions" class="btn btn-secondary"><i class="fas fa-undo"></i> Permissions</a>
4849
</p>
4950
</div>
5051
</div>

src/backoffice/templates/permissions_by_user.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
</table>
4040
<p>
4141
<a class="btn btn-secondary" href="{% url 'backoffice:index' camp_slug=camp.slug %}"><i class="fas fa-undo"></i> Backoffice</a>
42+
<a href="{% url 'backoffice:index' camp_slug=camp.slug %}#permissions" class="btn btn-secondary"><i class="fas fa-undo"></i> Permissions</a>
4243
</p>
4344
</div>
4445
</div>

src/backoffice/urls.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@
167167
from .views import ZettleDataImportView
168168
from .views import ZettleReceiptListView
169169
from .views import PermissionByUserView
170+
from .views import PermissionByGroupView
170171
from .views import PermissionByPermissionView
171172

172173
app_name = "backoffice"
@@ -1420,6 +1421,11 @@
14201421
"permissions/",
14211422
include(
14221423
[
1424+
path(
1425+
"by_group/",
1426+
PermissionByGroupView.as_view(),
1427+
name="permission_list_by_group",
1428+
),
14231429
path(
14241430
"by_user/",
14251431
PermissionByUserView.as_view(),

src/backoffice/views/permissions.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from teams.models import Team
1010
from django.views.generic import ListView, FormView
1111
from ..mixins import OrgaOrTeamLeadViewMixin
12-
from django.contrib.auth.models import User
12+
from django.contrib.auth.models import User, Group
1313
from ..forms import ManageTeamPermissionsForm
1414
from django.shortcuts import get_object_or_404
1515
from django.conf import settings
@@ -41,7 +41,11 @@ def get_context_data(self, **kwargs):
4141

4242

4343
class TeamPermissionManageView(CampViewMixin, FormView):
44-
"""This view is used to see and update team permissions."""
44+
"""This view is used to see and update team permissions.
45+
46+
This view does it's own permission checking in setup(),
47+
so it does not need to inherit from OrgaOrTeamLeadViewMixin.
48+
"""
4549

4650
template_name = "team_permissions_manage.html"
4751
form_class = ManageTeamPermissionsForm
@@ -185,3 +189,17 @@ def get_queryset(self, *args, **kwargs):
185189
),
186190
)
187191
return perms
192+
193+
194+
class PermissionByGroupView(OrgaOrTeamLeadViewMixin, ListView):
195+
model = Group
196+
template_name = "permissions_by_group.html"
197+
198+
def get_queryset(self, *args, **kwargs):
199+
qs = super().get_queryset(*args, **kwargs)
200+
permission_content_type = ContentType.objects.get_for_model(CampPermission)
201+
groups = qs.filter(
202+
permissions__isnull=False,
203+
permissions__content_type=permission_content_type,
204+
)
205+
return groups.distinct()

0 commit comments

Comments
 (0)