Skip to content

Commit 0c762a2

Browse files
committed
Added two new routes with some primal access control and 'dynamic' placeholder elements
1 parent f7fdf48 commit 0c762a2

File tree

7 files changed

+173
-6
lines changed

7 files changed

+173
-6
lines changed

project/auth.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,32 @@ def callback():
8787
active_groups = [
8888
{
8989
"prettyName": group.get("prettyName", {}),
90-
"name": group.get("name", {}),
90+
"name": group.get("superGroup", {}).get("name"),
9191
"post": group.get("post", {}).get("enName"),
9292
}
9393
for group in groups_response
9494
if group.get("superGroup", {}).get("type") != "alumni"
9595
]
96+
# {
97+
# "id": "ab44f720-8ed9-48b4-ba2a-6fb2a03db8f6",
98+
# "name": "digit25",
99+
# "prettyName": "digIT 25",
100+
# "superGroup": {
101+
# "id": "dea3493e-66e4-44b2-a657-cb57a6840dab",
102+
# "name": "digit",
103+
# "prettyName": "digIT",
104+
# "type": "committee",
105+
# "svDescription": "Digitala system",
106+
# "enDescription": "Digital systems"
107+
# },
108+
# "post": {
109+
# "id": "2cf9773d-da45-4532-8203-b085baaaf413",
110+
# "version": 30,
111+
# "svName": "Vice Ordförande",
112+
# "enName": "Vice Chairman"
113+
# }
114+
# }
115+
96116
except Exception as e:
97117
print(f"Failed to get api information: {e}")
98118
active_groups = "N/A"
@@ -121,8 +141,8 @@ def callback():
121141
"email": user_info.get("email"),
122142
"cid": user_info.get("cid"),
123143
"groups": active_groups + extra_groups,
124-
"active_groups": active_groups,
125-
"extra_groups": extra_groups,
144+
# "active_groups": active_groups,
145+
# "extra_groups": extra_groups,
126146
}
127147

128148
# Store user info in session

project/main.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
main = Blueprint("main", __name__)
66

7+
meetings = ["2024 LP4", "2025 LP1", "2025 LP2", "2025 LP3"]
8+
79

810
@main.route("/")
911
def index():
@@ -14,3 +16,32 @@ def index():
1416
@login_required
1517
def profile():
1618
return render_template("profile.html", user=g.get("user"))
19+
20+
21+
@main.route("/documents")
22+
@login_required
23+
def doc():
24+
user = g.get("user")
25+
user_roles = [
26+
(group.get("name", ""), group.get("post", ""))
27+
for group in user.get("groups", [])
28+
if group.get("post", "") in ["Chairman", "Treasurer"]
29+
]
30+
return render_template("doc.html",
31+
user=user,
32+
user_roles=user_roles,
33+
meetings=meetings)
34+
35+
36+
@main.route("/admin")
37+
@login_required
38+
def admin():
39+
user = g.get("user")
40+
user_groups = [
41+
group.get("name", "")
42+
for group in user.get("groups", [])
43+
]
44+
if any(group in user_groups for group in ["motespresidit", "styrit"]):
45+
return render_template("admin.html", user=g.get("user"))
46+
else:
47+
return render_template("denied.html")

project/templates/admin.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{% extends "base.html" %}
2+
3+
{% block content %}
4+
<h1 class="title">
5+
This is the admin page!
6+
</h1>
7+
{% endblock %}

project/templates/base.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<meta charset="utf-8">
66
<meta http-equiv="X-UA-Compatible" content="IE=edge">
77
<meta name="viewport" content="width=device-width, initial-scale=1">
8-
<title>Flask Auth Example</title>
8+
<title>SummIT</title>
99
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.2/css/bulma.min.css" />
1010
</head>
1111

@@ -20,6 +20,12 @@
2020
<a href="{{ url_for('main.index') }}" class="navbar-item">
2121
Home
2222
</a>
23+
<a href="{{ url_for('main.doc') }}" class="navbar-item">
24+
Documents
25+
</a>
26+
<a href="{{ url_for('main.admin') }}" class="navbar-item">
27+
Admin
28+
</a>
2329
<a href="{{ url_for('main.profile') }}" class="navbar-item">
2430
Profile
2531
</a>

project/templates/denied.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{% extends "base.html" %}
2+
3+
{% block content %}
4+
<h1 class="title">
5+
You cannot access this page >:(
6+
</h1>
7+
{% endblock %}

project/templates/doc.html

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
{% extends "base.html" %}
2+
3+
{% block content %}
4+
<h1 class="title">
5+
This is the documents page!
6+
</h1>
7+
<div style="text-align: center;">
8+
<h2 style="display: inline;">Choose meeting:</h2>
9+
<select id="meetingSelect" onchange="updateContent()" style="margin-left: 10px;">
10+
<option value="">Select a meeting...</option>
11+
{% for meeting in meetings %}
12+
<option value="{{ meeting }}">{{ meeting }}</option>
13+
{% endfor %}
14+
</select>
15+
</div>
16+
17+
<div class="content" id="documentsContent" style="display: none;">
18+
<div id="selectedMeeting" class="notification is-info" style="margin-bottom: 2rem;">
19+
<strong>Selected Meeting: </strong><span id="meetingDisplay"></span>
20+
</div>
21+
22+
{% if user_roles %}
23+
{% for group_name, post in user_roles %}
24+
<div class="box" style="margin-bottom: 2rem;">
25+
<h2>
26+
<strong>{{ group_name.title() }}</strong>
27+
</h2>
28+
29+
<div class="columns">
30+
<div class="column is-half">
31+
<div class="card">
32+
<div class="card-content">
33+
<h2>This is a Plan for <span class="meeting-text"></span></h2>
34+
</div>
35+
</div>
36+
</div>
37+
38+
<div class="column is-half">
39+
<div class="card">
40+
<div class="card-content">
41+
<h2>This is a budget for <span class="meeting-text"></span></h2>
42+
</div>
43+
</div>
44+
</div>
45+
</div>
46+
</div>
47+
{% endfor %}
48+
{% endif %}
49+
<div class="box" style="margin-bottom: 2rem;">
50+
<h2>
51+
<strong>General Documents</strong>
52+
</h2>
53+
<div class="columns">
54+
<div class="card">
55+
<div class="card-content">
56+
<h2>This is the agenda for <span class="meeting-text"></span></h2>
57+
</div>
58+
</div>
59+
<div class="card">
60+
<div class="card-content">
61+
<h2>This is motion #1 for <span class="meeting-text"></span></h2>
62+
</div>
63+
</div>
64+
<div class="card">
65+
<div class="card-content">
66+
<h2>This is motion #2 for <span class="meeting-text"></span></h2>
67+
</div>
68+
</div>
69+
<div class="card">
70+
<div class="card-content">
71+
<h2>This is motion #3 for <span class="meeting-text"></span></h2>
72+
</div>
73+
</div>
74+
</div>
75+
</div>
76+
</div>
77+
78+
<script>
79+
function updateContent() {
80+
const select = document.getElementById('meetingSelect');
81+
const content = document.getElementById('documentsContent');
82+
const meetingDisplay = document.getElementById('meetingDisplay');
83+
const meetingTexts = document.querySelectorAll('.meeting-text');
84+
85+
if (select.value) {
86+
content.style.display = 'block';
87+
meetingDisplay.textContent = select.value;
88+
meetingTexts.forEach(span => {
89+
span.textContent = select.value;
90+
});
91+
} else {
92+
content.style.display = 'none';
93+
}
94+
}
95+
</script>
96+
{% endblock %}

project/templates/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
{% block content %}
44
<h1 class="title">
5-
Flask Login Example
5+
Welcome to SummIT
66
</h1>
77
<h2 class="subtitle">
8-
Easy authentication and authorization in Flask.
8+
Easy handling of meeting related things and stuff.
99
</h2>
1010
{% endblock %}

0 commit comments

Comments
 (0)