Skip to content

Commit 0bdd5c2

Browse files
joni-toivonenJimmy Ihalainen
authored andcommittedMay 11, 2023
Improve access denied messages and 403 page
Fixes apluslms#858 Co-authored-by: Jimmy Ihalainen <jimmy.ihalainen@aalto.fi>
1 parent 2a339fc commit 0bdd5c2

File tree

6 files changed

+84
-88
lines changed

6 files changed

+84
-88
lines changed
 

‎authorization/permissions.py

+1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ def has_permission(self, request, view):
114114
if access_mode == ACCESS.ANONYMOUS:
115115
return True
116116
if not request.user.is_authenticated:
117+
self.error_msg(_('ACCESS_ERROR_ONLY_AUTHENTICATED'))
117118
return False
118119

119120
if access_mode >= ACCESS.SUPERUSER:

‎locale/en/LC_MESSAGES/django.po

+27-21
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ msgid ""
66
msgstr ""
77
"Project-Id-Version: PACKAGE VERSION\n"
88
"Report-Msgid-Bugs-To: \n"
9-
"POT-Creation-Date: 2023-02-07 16:41+0200\n"
9+
"POT-Creation-Date: 2023-05-10 14:22+0300\n"
1010
"PO-Revision-Date: 2021-05-27 14:47+0300\n"
1111
"Last-Translator: Jimmy Ihalainen <jimmy.ihalainen@aalto.fi>\n"
1212
"Language-Team: English<>\n"
@@ -200,6 +200,10 @@ msgstr "A superuser of the service"
200200
msgid "ACCESS_PERMISSION_DENIED_MSG"
201201
msgstr "Unfortunately you are not permitted to see this content."
202202

203+
#: authorization/permissions.py
204+
msgid "ACCESS_ERROR_ONLY_AUTHENTICATED"
205+
msgstr "Please login."
206+
203207
#: authorization/permissions.py
204208
msgid "ACCESS_ERROR_ONLY_TEACHERS"
205209
msgstr "Only course teachers shall pass."
@@ -372,7 +376,8 @@ msgstr "anonymized ID"
372376
msgid "LABEL_ROLE"
373377
msgstr "role"
374378

375-
#: course/models.py exercise/exercise_models.py exercise/submission_models.py
379+
#: course/models.py exercise/admin.py exercise/exercise_models.py
380+
#: exercise/submission_models.py
376381
msgid "LABEL_STATUS"
377382
msgstr "status"
378383

@@ -2922,6 +2927,10 @@ msgstr "Submitters"
29222927
msgid "LABEL_SUBMITTERS"
29232928
msgstr "Submitters"
29242929

2930+
#: exercise/admin.py exercise/submission_models.py notification/models.py
2931+
msgid "LABEL_SUBMISSION"
2932+
msgstr "submission"
2933+
29252934
#: exercise/api/views.py exercise/views.py
29262935
msgid "ERROR_SUBMISSION_SAVING_FAILED"
29272936
msgstr ""
@@ -3718,10 +3727,6 @@ msgstr "submission draft"
37183727
msgid "MODEL_NAME_SUBMISSION_DRAFT_PLURAL"
37193728
msgstr "submission drafts"
37203729

3721-
#: exercise/submission_models.py notification/models.py
3722-
msgid "LABEL_SUBMISSION"
3723-
msgstr "submission"
3724-
37253730
#: exercise/submission_models.py
37263731
msgid "LABEL_PARAM_NAME"
37273732
msgstr "parameter name"
@@ -5037,8 +5042,8 @@ msgstr ""
50375042
msgid "EXTERNAL_SERVICE_SENT_ACCESS_TOKEN_COURSE_STAFF -- %(brand)s"
50385043
msgstr ""
50395044
"Moreover, we send this service a so-called <a href=\"https://en.wikipedia."
5040-
"org/wiki/Access_token\" rel=\"noopener nofollow\" target=\"_blank\" class="
5041-
"\"alert-link\">access token</a>, which gives the service access to the "
5045+
"org/wiki/Access_token\" rel=\"noopener nofollow\" target=\"_blank\" "
5046+
"class=\"alert-link\">access token</a>, which gives the service access to the "
50425047
"%(brand)s API at your privilege level. If you don't want that to happen, "
50435048
"please contact %(brand)s administration."
50445049

@@ -5047,8 +5052,8 @@ msgstr ""
50475052
msgid "EXTERNAL_SERVICE_SENT_ACCESS_TOKEN_STUDENT -- %(brand)s"
50485053
msgstr ""
50495054
"Moreover, we send this service a so-called <a href=\"https://en.wikipedia."
5050-
"org/wiki/Access_token\" rel=\"noopener nofollow\" target=\"_blank\" class="
5051-
"\"alert-link\">access token</a>, which gives the service access to the "
5055+
"org/wiki/Access_token\" rel=\"noopener nofollow\" target=\"_blank\" "
5056+
"class=\"alert-link\">access token</a>, which gives the service access to the "
50525057
"%(brand)s API at your privilege level. This means that the service can, for "
50535058
"example, access your student ID number and your progress in the course, and "
50545059
"submit solutions to assignments. The course staff has enabled this feature "
@@ -5058,8 +5063,8 @@ msgstr ""
50585063
#, python-format
50595064
msgid "EXTERNAL_SERVICE_PRIVACY_HOSTED_INTERNALLY -- %(brand)s, %(url)s"
50605065
msgstr ""
5061-
"This service is hosted by us (%(brand)s administrators) and thus our <a href="
5062-
"\"%(url)s\" target=\"_blank\">privacy notice</a> covers it too."
5066+
"This service is hosted by us (%(brand)s administrators) and thus our <a "
5067+
"href=\"%(url)s\" target=\"_blank\">privacy notice</a> covers it too."
50635068

50645069
#: external_services/templates/external_services/_privacy.html
50655070
#, python-format
@@ -5073,21 +5078,22 @@ msgid "EXTERNAL_SERVICE_PRIVACY_HOSTED_IN_EEA"
50735078
msgstr ""
50745079
"This service is hosted within the European Economics Area and is thus "
50755080
"subject to <a href=\"https://ec.europa.eu/info/law/law-topic/data-protection/"
5076-
"reform_en\" rel=\"noopener nofollow\" target=\"_blank\" class=\"alert-link"
5077-
"\">the European Union's General Data Protection Regulation</a>."
5081+
"reform_en\" rel=\"noopener nofollow\" target=\"_blank\" class=\"alert-"
5082+
"link\">the European Union's General Data Protection Regulation</a>."
50785083

50795084
#: external_services/templates/external_services/_privacy.html
50805085
msgid "EXTERNAL_SERVICE_PRIVACY_PRIVACYSHIELD"
50815086
msgstr ""
50825087
"This service is hosted outside of the European Economics Area and is thus "
50835088
"not covered by <a href=\"https://ec.europa.eu/info/law/law-topic/data-"
5084-
"protection/reform_en\" rel=\"noopener nofollow\" target=\"_blank\" class="
5085-
"\"alert-link\">the European Union's General Data Protection Regulation</a> "
5086-
"(GDPR). The service used to be certified under <a href=\"https://www."
5087-
"privacyshield.gov/Individuals-in-Europe\" rel=\"noopener nofollow\" target="
5088-
"\"_blank\" class=\"alert-link\">the EU-U.S. Privacy Shield</a>, but the "
5089-
"European Court of Justice has declared the EU-U.S. Privacy Shield invalid. "
5090-
"We are investigating how this affects the use of the service."
5089+
"protection/reform_en\" rel=\"noopener nofollow\" target=\"_blank\" "
5090+
"class=\"alert-link\">the European Union's General Data Protection "
5091+
"Regulation</a> (GDPR). The service used to be certified under <a "
5092+
"href=\"https://www.privacyshield.gov/Individuals-in-Europe\" rel=\"noopener "
5093+
"nofollow\" target=\"_blank\" class=\"alert-link\">the EU-U.S. Privacy "
5094+
"Shield</a>, but the European Court of Justice has declared the EU-U.S. "
5095+
"Privacy Shield invalid. We are investigating how this affects the use of the "
5096+
"service."
50915097

50925098
#: external_services/templates/external_services/_privacy.html
50935099
msgid "EXTERNAL_SERVICE_PRIVACY_GLOBAL"

‎locale/fi/LC_MESSAGES/django.po

+41-34
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ msgid ""
66
msgstr ""
77
"Project-Id-Version: \n"
88
"Report-Msgid-Bugs-To: \n"
9-
"POT-Creation-Date: 2023-02-07 16:41+0200\n"
9+
"POT-Creation-Date: 2023-05-10 14:22+0300\n"
1010
"PO-Revision-Date: 2019-08-14 12:16+0200\n"
1111
"Last-Translator: Jimmy Ihalainen <jimmy.ihalainen@aalto.fi>\n"
1212
"Language-Team: Finnish <>\n"
@@ -201,6 +201,10 @@ msgstr "Palvelun hallintokäyttäjä"
201201
msgid "ACCESS_PERMISSION_DENIED_MSG"
202202
msgstr "Valitettavasti sinulla ei ole oikeutta nähdä tätä sisältöä."
203203

204+
#: authorization/permissions.py
205+
msgid "ACCESS_ERROR_ONLY_AUTHENTICATED"
206+
msgstr "Kirjaudu sisään."
207+
204208
#: authorization/permissions.py
205209
msgid "ACCESS_ERROR_ONLY_TEACHERS"
206210
msgstr "Vain opettajille."
@@ -373,7 +377,8 @@ msgstr "anonymisoitu ID"
373377
msgid "LABEL_ROLE"
374378
msgstr "rooli"
375379

376-
#: course/models.py exercise/exercise_models.py exercise/submission_models.py
380+
#: course/models.py exercise/admin.py exercise/exercise_models.py
381+
#: exercise/submission_models.py
377382
msgid "LABEL_STATUS"
378383
msgstr "tila"
379384

@@ -1174,8 +1179,8 @@ msgstr "[henkilökunnalla ei ole]"
11741179
#, python-format
11751180
msgid "GROUP_PERSONAL_JOIN_CODE -- %(code)s"
11761181
msgstr ""
1177-
"Henkilökohtainen ryhmään <strong>liittymiskoodisi</strong> on <strong>"
1178-
"%(code)s</strong>. "
1182+
"Henkilökohtainen ryhmään <strong>liittymiskoodisi</strong> on "
1183+
"<strong>%(code)s</strong>. "
11791184

11801185
#: course/templates/course/groups.html
11811186
msgid "GROUP_CREATION_INSTRUCTIONS"
@@ -2532,7 +2537,8 @@ msgstr "Tuo sisältöasetukset URL-osoitteesta"
25322537
#: edit_course/templates/edit_course/edit_content.html
25332538
msgid "APPLY_CHANGES_TOOLTIP"
25342539
msgstr ""
2535-
"Vertaa uusia sisältöasetuksia aikaisempiin, ja päivittää vain muuttuneet osat."
2540+
"Vertaa uusia sisältöasetuksia aikaisempiin, ja päivittää vain muuttuneet "
2541+
"osat."
25362542

25372543
#: edit_course/templates/edit_course/edit_content.html
25382544
msgid "APPLY_CHANGES"
@@ -2935,6 +2941,10 @@ msgstr "Opiskelijat"
29352941
msgid "LABEL_SUBMITTERS"
29362942
msgstr "Palauttajat"
29372943

2944+
#: exercise/admin.py exercise/submission_models.py notification/models.py
2945+
msgid "LABEL_SUBMISSION"
2946+
msgstr "palautus"
2947+
29382948
#: exercise/api/views.py exercise/views.py
29392949
msgid "ERROR_SUBMISSION_SAVING_FAILED"
29402950
msgstr "Palautuksen tallentaminen epäonnistui. Palautusta ei ole huomioitu."
@@ -3725,10 +3735,6 @@ msgstr "palautusluonnos"
37253735
msgid "MODEL_NAME_SUBMISSION_DRAFT_PLURAL"
37263736
msgstr "palautusluonnokset"
37273737

3728-
#: exercise/submission_models.py notification/models.py
3729-
msgid "LABEL_SUBMISSION"
3730-
msgstr "palautus"
3731-
37323738
#: exercise/submission_models.py
37333739
msgid "LABEL_PARAM_NAME"
37343740
msgstr "parametrin nimi"
@@ -3985,8 +3991,8 @@ msgstr "Palauttajia: %(number)s <small>%(percentage)s%%</small>"
39853991
#, python-format
39863992
msgid "USER_LAST_VISITED -- %(name)s, %(link)s"
39873993
msgstr ""
3988-
"Olet ollut oppimateriaalissa viimeksi kohdassa <a href=\"%(link)s\">"
3989-
"%(name)s</a>"
3994+
"Olet ollut oppimateriaalissa viimeksi kohdassa <a "
3995+
"href=\"%(link)s\">%(name)s</a>"
39903996

39913997
#: exercise/templates/exercise/_user_last.html
39923998
#, python-format
@@ -5056,29 +5062,30 @@ msgstr ""
50565062
msgid "EXTERNAL_SERVICE_SENT_ACCESS_TOKEN_COURSE_STAFF -- %(brand)s"
50575063
msgstr ""
50585064
"Lisäksi palvelulle lähetetään <a href=\"https://en.wikipedia.org/wiki/"
5059-
"Access_token\" rel=\"noopener nofollow\" target=\"_blank\" class=\"alert-link"
5060-
"\">käyttöoikeustietue</a>, joka mahdollistaa palvelun pääsyn %(brand)s:n API:"
5061-
"in sinun oikeuksillasi. Mikäli näin ei pitäisi tapahtua, niin ota yhteyttä "
5062-
"%(brand)s:n ylläpitoon."
5065+
"Access_token\" rel=\"noopener nofollow\" target=\"_blank\" class=\"alert-"
5066+
"link\">käyttöoikeustietue</a>, joka mahdollistaa palvelun pääsyn %(brand)s:n "
5067+
"API:in sinun oikeuksillasi. Mikäli näin ei pitäisi tapahtua, niin ota "
5068+
"yhteyttä %(brand)s:n ylläpitoon."
50635069

50645070
#: external_services/templates/external_services/_privacy.html
50655071
#, python-format
50665072
msgid "EXTERNAL_SERVICE_SENT_ACCESS_TOKEN_STUDENT -- %(brand)s"
50675073
msgstr ""
50685074
"Lisäksi palvelulle lähetetään <a href=\"https://en.wikipedia.org/wiki/"
5069-
"Access_token\" rel=\"noopener nofollow\" target=\"_blank\" class=\"alert-link"
5070-
"\">käyttöoikeustietue</a>, joka mahdollistaa palvelun pääsyn %(brand)s:n API:"
5071-
"in sinun oikeuksillasi. Tämä tarkoittaa sitä, että palvelu voi mm. selvittää "
5072-
"opiskelijanumerosi, nähdä kurssisuorituksiasi ja palauttaa tehtäviä "
5073-
"puolestasi. Kurssin henkilökunta on mahdollistanut tämän ja luottaa palvelun "
5074-
"toimivan etujesi mukaisesti."
5075+
"Access_token\" rel=\"noopener nofollow\" target=\"_blank\" class=\"alert-"
5076+
"link\">käyttöoikeustietue</a>, joka mahdollistaa palvelun pääsyn %(brand)s:n "
5077+
"API:in sinun oikeuksillasi. Tämä tarkoittaa sitä, että palvelu voi mm. "
5078+
"selvittää opiskelijanumerosi, nähdä kurssisuorituksiasi ja palauttaa "
5079+
"tehtäviä puolestasi. Kurssin henkilökunta on mahdollistanut tämän ja luottaa "
5080+
"palvelun toimivan etujesi mukaisesti."
50755081

50765082
#: external_services/templates/external_services/_privacy.html
50775083
#, python-format
50785084
msgid "EXTERNAL_SERVICE_PRIVACY_HOSTED_INTERNALLY -- %(brand)s, %(url)s"
50795085
msgstr ""
5080-
"Tämä palvelu on meidän ylläpitämämme (%(brand)s), joten meidän <a href="
5081-
"\"%(url)s\" target=\"_blank\">tietosuojailmoituksemme</a> kattaa myös sen. "
5086+
"Tämä palvelu on meidän ylläpitämämme (%(brand)s), joten meidän <a "
5087+
"href=\"%(url)s\" target=\"_blank\">tietosuojailmoituksemme</a> kattaa myös "
5088+
"sen. "
50825089

50835090
#: external_services/templates/external_services/_privacy.html
50845091
#, python-format
@@ -5090,22 +5097,22 @@ msgstr ""
50905097
#: external_services/templates/external_services/_privacy.html
50915098
msgid "EXTERNAL_SERVICE_PRIVACY_HOSTED_IN_EEA"
50925099
msgstr ""
5093-
"Tämä palvelu sijaitsee Euroopan talousalueella, joten sitä koskee <a href="
5094-
"\"https://ec.europa.eu/info/law/law-topic/data-protection/reform_fi\" rel="
5095-
"\"noopener nofollow\" target=\"_blank\" class=\"alert-link\">Euroopan "
5100+
"Tämä palvelu sijaitsee Euroopan talousalueella, joten sitä koskee <a "
5101+
"href=\"https://ec.europa.eu/info/law/law-topic/data-protection/reform_fi\" "
5102+
"rel=\"noopener nofollow\" target=\"_blank\" class=\"alert-link\">Euroopan "
50965103
"unionin yleinen tietosuoja-asetus</a>."
50975104

50985105
#: external_services/templates/external_services/_privacy.html
50995106
msgid "EXTERNAL_SERVICE_PRIVACY_PRIVACYSHIELD"
51005107
msgstr ""
51015108
"Tämä palvelu sijaitsee Euroopan talousalueen ulkopuolella, joten sitä ei "
51025109
"koske <a href=\"https://ec.europa.eu/info/law/law-topic/data-protection/"
5103-
"reform_fi\" rel=\"noopener nofollow\" target=\"_blank\" class=\"alert-link"
5104-
"\">Euroopan unionin yleinen tietosuoja-asetus</a> (GDPR). Palvelu oli "
5105-
"aiemmin <a href=\"https://www.privacyshield.gov/Individuals-in-Europe\" rel="
5106-
"\"noopener nofollow\" target=\"_blank\" class=\"alert-link\">EU-U.S. Privacy "
5107-
"Shield</a> -sertifioitu, mutta Euroopan unionin tuomioistuin on kumonnut "
5108-
"päätöksen EU-U.S. Privacy Shield -järjestelyn tietosuojan tason "
5110+
"reform_fi\" rel=\"noopener nofollow\" target=\"_blank\" class=\"alert-"
5111+
"link\">Euroopan unionin yleinen tietosuoja-asetus</a> (GDPR). Palvelu oli "
5112+
"aiemmin <a href=\"https://www.privacyshield.gov/Individuals-in-Europe\" "
5113+
"rel=\"noopener nofollow\" target=\"_blank\" class=\"alert-link\">EU-U.S. "
5114+
"Privacy Shield</a> -sertifioitu, mutta Euroopan unionin tuomioistuin on "
5115+
"kumonnut päätöksen EU-U.S. Privacy Shield -järjestelyn tietosuojan tason "
51095116
"riittävyydestä. Selvitämme edelleen, kuinka uusi päätös vaikuttaa palvelun "
51105117
"käyttöön. "
51115118

@@ -5127,8 +5134,8 @@ msgstr ""
51275134
#, python-format
51285135
msgid "EXTERNAL_SERVICE_LOOK_WITHOUT_SENDING_DATA -- %(url)s"
51295136
msgstr ""
5130-
"Voit vierailla palvelussa lähettämättä tietoja: <a href=\"%(url)s\" rel="
5131-
"\"noopener nofollow\" target=\"_blank\">palvelun etusivu</a>."
5137+
"Voit vierailla palvelussa lähettämättä tietoja: <a href=\"%(url)s\" "
5138+
"rel=\"noopener nofollow\" target=\"_blank\">palvelun etusivu</a>."
51325139

51335140
#: external_services/templates/external_services/edit_menu.html
51345141
msgid "ADD_MENU_ITEM"

‎selenium_test/test/locators.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
from selenium.webdriver.common.by import By
22

33
class CommonLocators:
4-
FORBIDDEN_PAGE = (By.XPATH, "//div[@class='page-header']/h1[contains(text(), '403 Forbidden')]")
4+
FORBIDDEN_PAGE = (
5+
By.XPATH,
6+
"//div[@class='message'][contains(text(), "
7+
"'Unfortunately you are not permitted to see this content')]"
8+
)
59
PERMISSION_DENIED_ACCESS_MODE = (
610
By.XPATH,
711
"//main[@id='content']//div[@class='message'][contains(text(), "

‎selenium_test/test/teacher_list_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def __init__(
2626
query.append("end_date=" + end_date.isoformat())
2727
query.append("with_assistants=" + ("true" if with_assistants else "false"))
2828

29-
self.load("/accounts/teachers/?" + "&".join(query), (By.CSS_SELECTOR, '.page-header'))
29+
self.load("/accounts/teachers/?" + "&".join(query), (By.CSS_SELECTOR, '.container-fluid'))
3030

3131
def get_table_data(self) -> List[List[str]]:
3232
rows = self.getElements((By.CSS_SELECTOR, "table tbody tr"))

‎templates/403.html

+9-31
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,12 @@
1+
{% extends "base.html" %}
12
{% load i18n %}
23
{% load static %}
34
{% load base %}
4-
<!DOCTYPE html>
5-
<html>
6-
<head>
7-
<meta charset="utf-8" />
8-
<meta name="viewport" content="width=device-width, initial-scale=1">
9-
<title>403 Forbidden</title>
10-
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
11-
<link rel="stylesheet" href="{% static 'css/main.css' %}" />
12-
</head>
13-
<body>
14-
<div class="container-fluid">
15-
<div class="row">
16-
<div class="col-md-8">
17-
<div class="page-header">
18-
<h1>403 Forbidden</h1>
19-
</div>
20-
{% include "_messages.html" %}
21-
<pre>
22-
| v
23-
| /\ | ,.
24-
^\_("))_/| ´ .
25-
/{%} \ | `
26-
/______\ ,'
27-
,' ^ ^ ,'
28-
; :</pre>
29-
</div>
30-
</div>
31-
</div>
32-
{% tracking_html %}
33-
</body>
34-
</html>
5+
{% block content %}
6+
<div class="container-fluid">
7+
<div class="row">
8+
<div class="col-md-8">
9+
</div>
10+
</div>
11+
</div>
12+
{% endblock %}

0 commit comments

Comments
 (0)
Please sign in to comment.