Skip to content

Commit

Permalink
[frontend/settings] Add deny list feature (#803)
Browse files Browse the repository at this point in the history
* [frontend/settings] Add deny list feature

Propose an implementation for and fix #736

* [frontend/settings] AC type: from str to bool
  • Loading branch information
nrybowski committed Apr 15, 2022
1 parent 391d1f0 commit 589996f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
8 changes: 7 additions & 1 deletion inginious/frontend/courses.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def __init__(self, courseid, content, course_fs, task_factory, plugin_manager, t
self._registration_ac = self._content.get('registration_ac', None)
if self._registration_ac not in [None, "username", "binding", "email"]:
raise Exception("Course has an invalid value for registration_ac: " + self.get_id())
self._registration_ac_accept = self._content.get('registration_ac_accept', True)
self._registration_ac_list = self._content.get('registration_ac_list', [])
self._groups_student_choice = self._content.get("groups_student_choice", False)
self._allow_unregister = self._content.get('allow_unregister', True)
Expand Down Expand Up @@ -170,6 +171,10 @@ def get_access_control_method(self):
""" Returns either None, "username", "binding", or "email", depending on the method used to verify that users can register to the course """
return self._registration_ac

def get_access_control_accept(self):
""" Returns either True (accept) or False (deny), depending on the control type used to verify that users can register to the course """
return self._registration_ac_accept

def get_access_control_list(self) -> List[str]:
""" Returns the list of all users/emails/binding methods/... (see get_access_control_method) allowed by the AC list """
return self._registration_ac_list
Expand Down Expand Up @@ -210,7 +215,8 @@ def is_user_accepted_by_access_control(self, user_info: UserInfo):

# check that at least one key matches in the list
keys = keys_per_access_control_method[self.get_access_control_method()]()
return any(self._registration_ac_regex.match(key) for key in keys)
at_least_one = any(self._registration_ac_regex.fullmatch(key) for key in keys)
return at_least_one if self.get_access_control_accept() else not at_least_one

def allow_preview(self):
return self._allow_preview
Expand Down
3 changes: 3 additions & 0 deletions inginious/frontend/pages/course_admin/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,11 @@ def POST_AUTH(self, courseid): # pylint: disable=arguments-differ
errors.append(_('Invalid ACL value'))
if course_content['registration_ac'] == "None":
course_content['registration_ac'] = None

course_content['registration_ac_accept'] = True if data['registration_ac_accept'] == "true" else False
course_content['registration_ac_list'] = [line.strip() for line in data['registration_ac_list'].splitlines()]


course_content['is_lti'] = 'lti' in data and data['lti'] == "true"
course_content['lti_url'] = data.get("lti_url", "")
course_content['lti_keys'] = dict([x.split(":") for x in data['lti_keys'].splitlines() if x])
Expand Down
29 changes: 29 additions & 0 deletions inginious/frontend/templates/course_admin/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,25 @@ <h2>{{_("Course settings")}}</h2>
</label>
</div>
</div>
<div class="form-group row no-lti ac_accept">
<label for="registration_ac_accept" class="col-sm-2 control-label">{{_("Access control type")}}</label>
<div class="col-sm-10">
<label>
<input type="radio" value="true" name="registration_ac_accept" id="registration_ac_accept"
{% if course.get_access_control_accept() %}
checked="checked"
{% endif %}
/> {{_("Accept")}}
</label><br/>
<label>
<input type="radio" value="false" name="registration_ac_accept"
{% if not course.get_access_control_accept() %}
checked="checked"
{% endif %}
/> {{_("Deny")}}
</label><br/>
</div>
</div>
<div class="form-group row no-lti">
<label for="registration_ac_list" class="col-sm-2 control-label">{{_("Access control list")}}</label>
<div class="col-sm-10">
Expand Down Expand Up @@ -324,6 +343,14 @@ <h2>{{_("Course settings")}}</h2>
</form>

<script type="text/javascript">
function hideAcType() {
if($("#registration_ac").is(":checked")){
$(".ac_accept").hide();
} else {
$(".ac_accept").show();
}
}

function updateLTI() {
if($("#lti").is(":checked"))
{
Expand All @@ -340,6 +367,8 @@ <h2>{{_("Course settings")}}</h2>
updateLTI();
$("#lti").click(updateLTI);
$("#lti").change(updateLTI);
hideAcType();
$("[name='registration_ac']").change(hideAcType);
})
</script>
{% endblock %}

0 comments on commit 589996f

Please sign in to comment.