.
This commit is contained in:
+38
-6
@@ -51,7 +51,7 @@ from .forms import (
|
||||
UserUserGroupForm,
|
||||
)
|
||||
|
||||
from .models import CidUser, CidUserGroup, Examination, QuestionNote, UserUserGroup
|
||||
from .models import CidUser, CidUserGroup, Examination, QuestionNote, UserUserGroup, get_next_cid
|
||||
|
||||
from rapids.models import Rapid as RapidQuestion
|
||||
from rapids.models import Exam as RapidExam
|
||||
@@ -366,6 +366,9 @@ class ExamViews(View, LoginRequiredMixin):
|
||||
if exam.authors_only:
|
||||
return False
|
||||
|
||||
if user.groups.filter(name="cid_user_manager").exists():
|
||||
return True
|
||||
|
||||
if (
|
||||
self.app_name == "rapids"
|
||||
and not user.groups.filter(name="rapid_checker").exists()
|
||||
@@ -544,7 +547,7 @@ class ExamViews(View, LoginRequiredMixin):
|
||||
exam_list = self.Exam.objects.all().order_by("name")
|
||||
|
||||
if not all:
|
||||
exams = exam_list.filter(exam_mode=True, archive=False).order_by("name")
|
||||
exam_list = exam_list.filter(exam_mode=True, archive=False).order_by("name")
|
||||
|
||||
marking = False
|
||||
|
||||
@@ -555,7 +558,7 @@ class ExamViews(View, LoginRequiredMixin):
|
||||
request,
|
||||
"exam_list.html".format(self.app_name),
|
||||
{
|
||||
"exams": exams,
|
||||
"exams": exam_list,
|
||||
"app_name": self.app_name,
|
||||
"view_all": all,
|
||||
"marking": marking,
|
||||
@@ -947,7 +950,12 @@ class ExamViews(View, LoginRequiredMixin):
|
||||
def exam_json_edit(self, request, pk):
|
||||
if request.is_ajax() and request.method == "POST":
|
||||
|
||||
if not self.check_user_edit_access(request.user, exam_id=pk):
|
||||
|
||||
if request.user.groups.filter(name="cid_user_manager").exists():
|
||||
# This may give more permissions than we actually want
|
||||
pass
|
||||
|
||||
elif not self.check_user_edit_access(request.user, exam_id=pk):
|
||||
data = {"status": "invalid permisions"}
|
||||
return JsonResponse(data, status=400)
|
||||
|
||||
@@ -964,6 +972,8 @@ class ExamViews(View, LoginRequiredMixin):
|
||||
app_exam_map["rapids"] = cid_user.rapid_exams
|
||||
app_exam_map["anatomy"] = cid_user.anatomy_exams
|
||||
app_exam_map["longs"] = cid_user.longs_exams
|
||||
app_exam_map["physics"] = cid_user.physics_exams
|
||||
app_exam_map["sbas"] = cid_user.sba_exams
|
||||
app_exam_map["atlas"] = cid_user.casecollection_exams
|
||||
|
||||
if add:
|
||||
@@ -985,6 +995,8 @@ class ExamViews(View, LoginRequiredMixin):
|
||||
app_exam_map["rapids"] = user_user.user_rapid_exams
|
||||
app_exam_map["anatomy"] = user_user.user_anatomy_exams
|
||||
app_exam_map["longs"] = user_user.user_longs_exams
|
||||
app_exam_map["physics"] = user_user.user_physics_exams
|
||||
app_exam_map["sbas"] = user_user.user_sba_exams
|
||||
# app_exam_map["atlas"] = user_user.casecollection_exams
|
||||
|
||||
if add:
|
||||
@@ -2187,6 +2199,9 @@ def candidate_email_results(request, cid, resend=False):
|
||||
def candidate_email_results_resend(request, cid, resend=True):
|
||||
return candidate_email_results(request, cid, resend=True)
|
||||
|
||||
@user_is_cid_user_manager
|
||||
def create_cid_email(request):
|
||||
pass
|
||||
|
||||
@user_is_cid_user_manager
|
||||
def manage_cid_users(request):
|
||||
@@ -2203,6 +2218,7 @@ def manage_cid_users(request):
|
||||
|
||||
emails = json.loads(request.POST.get("emails"))
|
||||
|
||||
|
||||
number_to_create = int(request.POST.get("number_to_create"))
|
||||
|
||||
add_group = request.POST.get("add_group")
|
||||
@@ -2291,12 +2307,28 @@ def manage_cid_users(request):
|
||||
return JsonResponse({"status": "success"})
|
||||
|
||||
try:
|
||||
new_cid = CidUser.objects.all().order_by("-cid")[0].cid + 1
|
||||
new_cid = get_next_cid()
|
||||
except IndexError:
|
||||
new_cid = 10000
|
||||
|
||||
if emails:
|
||||
if "add_new_emails" in request.POST:
|
||||
email_list = [i.strip() for i in emails.split()]
|
||||
|
||||
# Verify emails are all valid
|
||||
invalid_emails = []
|
||||
for email in email_list:
|
||||
try:
|
||||
validate_email(email)
|
||||
except ValidationError as e:
|
||||
invalid_emails.append(f"Invalid email: {email}")
|
||||
|
||||
print(f"Email list {email_list}")
|
||||
if not email_list:
|
||||
return JsonResponse({"status": "fail", "details": "No valid emails"})
|
||||
if invalid_emails or not email_list:
|
||||
e = "<br/>".join(invalid_emails)
|
||||
return JsonResponse({"status": "fail", "details": f"Unable to create users<hr>{e}"})
|
||||
|
||||
for e in email_list:
|
||||
passcode = "".join(random.choices(string.ascii_uppercase, k=4))
|
||||
c = CidUser(cid=new_cid, passcode=passcode, email=e)
|
||||
|
||||
Reference in New Issue
Block a user