Skip to content

Commit

Permalink
address feedback #5990
Browse files Browse the repository at this point in the history
  • Loading branch information
boryanagoncharenko committed Dec 10, 2024
1 parent 1abe81b commit c1c9296
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 12 deletions.
12 changes: 5 additions & 7 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@
cdn, classes, database, for_teachers, s3_logger, parsons,
profile, programs, querylog, quiz, statistics,
translating, tags, surveys, super_teacher, public_adventures, user_activity, feedback)
from website.auth import (current_user, is_admin, is_teacher, is_second_teacher, is_super_teacher, has_public_profile,
login_user_from_token_cookie, requires_login, requires_login_redirect, requires_teacher,
forget_current_user, hide_explore)
from website.auth import (current_user, is_admin, is_teacher, is_second_teacher, is_super_teacher, is_students_teacher,
has_public_profile, login_user_from_token_cookie, requires_login, requires_login_redirect,
requires_teacher, forget_current_user, hide_explore)
from website.log_fetcher import log_fetcher
from website.frontend_types import Adventure, Program, ExtraStory, SaveInfo

Expand Down Expand Up @@ -1946,10 +1946,6 @@ def view_program(user, id):
next_classmate_adventure_id = next_classmate_adventure.get('program_id')
if next_classmate_adventure_id:
break
if is_teacher(user):
second_teachers = [t for t in class_.get('second_teachers', []) if t.get('role', '') == 'teacher']
all_teachers = [class_.get('teacher')] + [t.get('username', '') for t in second_teachers]
arguments_dict['is_students_teacher'] = user.get('username') in all_teachers

student_customizations = DATABASE.get_student_class_customizations(result['username'])
adventure_index = 0
Expand All @@ -1968,6 +1964,8 @@ def view_program(user, id):
if next_program_id:
break

arguments_dict['is_students_teacher'] = is_students_teacher(student=result['username'], teacher=user['username'])

return render_template("view-program-page.html",
blur_button_available=True,
javascript_page_options=dict(
Expand Down
12 changes: 10 additions & 2 deletions static/js/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -772,10 +772,18 @@ export function submit_program (id: string) {
});
}

export function unsubmit_program (id: string) {
function change_to_unsubmitted () {
$('#unsubmit-program-button').hide();
$('#submitted-program-title').hide();
$('#submitted-program-details').hide();
}

export async function unsubmit_program (id: string, prompt: string) {
await modal.confirmP(prompt);
tryCatchPopup(async () => {
const response = await postJson('/programs/unsubmit', { id });
modal.notifySuccess(response.message);
change_to_unsubmitted();
});
}

Expand Down Expand Up @@ -1975,4 +1983,4 @@ export function goToLevel(level: any) {

export function emptyEditor() {
theGlobalEditor.contents = ""
}
}
6 changes: 3 additions & 3 deletions templates/view-program-page.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ <h1>{{initial_adventure.name}}</h1>

{% if initial_adventure.submitted %}
<div class="text-center">
<button class="green-btn" data-cy="unsubmit_btn" onclick="hedyApp.modal.confirm ('{{_('unsubmit_warning')}}', function () {hedyApp.unsubmit_program ('{{initial_adventure.id}}', {{ loop_index }})})">{{_('unsubmit_program')}}</button>
<button id="unsubmit-program-button" class="green-btn" data-cy="unsubmit_btn" onclick="hedyApp.unsubmit_program('{{initial_adventure.id}}', '{{_('unsubmit_warning')}}')">{{_('unsubmit_program')}}</button>
</div>
{% endif %}

Expand All @@ -40,7 +40,7 @@ <h1>{{initial_adventure.name}}</h1>
<h2 class="p-0 m-0">{{_('level_title')}} {{level}}</h2>
{% if initial_adventure.submitted %}
<div class="flex-1"></div>
<h2 class="p-0 m-0">{{_('submitted_header')}}</h2>
<h2 id="submitted-program-title" class="p-0 m-0">{{_('submitted_header')}}</h2>
{% endif %}
</div>
<div class="flex flex-row gap-6 items-center">
Expand All @@ -49,7 +49,7 @@ <h2 class="p-0 m-0">{{_('submitted_header')}}</h2>
<a {% if initial_adventure.public_profile %}onclick="window.open('/user/{{initial_adventure.username}}', '_self')"{% endif %} class="{% if initial_adventure.public_profile %}cursor-pointer{% else %}text-black{% endif %} no-underline">{{ initial_adventure.username }}</a>
</div>
<div class="flex-1"></div>
<h3 class="p-0 m-0">{{_('submission_time')}} {{program_timestamp}}</h3>
<h3 id="submitted-program-details" class="p-0 m-0">{{_('submission_time')}} {{program_timestamp}}</h3>
{% endif %}
</div>

Expand Down
4 changes: 4 additions & 0 deletions website/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ def is_super_teacher(user):
return bool(user.get("is_super_teacher", False))


def is_students_teacher(student, teacher):
return teacher in g.db.get_student_teachers(student)


def has_public_profile(user):
if 'username' not in user or user.get('username') == '':
return False
Expand Down
10 changes: 10 additions & 0 deletions website/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,16 @@ def get_teacher_students(self, username):
students.append(student)
return students

def get_student_teachers(self, username):
"""Return a list of the main and all secondary teachers of a student."""
teachers = []
for class_id in self.get_student_classes_ids(username):
class_ = self.get_class(class_id)
teachers.append(class_["teacher"])
sec_teachers = [t['username'] for t in class_.get('second_teachers', []) if t.get('role', '') == 'teacher']
teachers.extend(sec_teachers)
return teachers

def get_adventure(self, adventure_id):
return self.adventures.get({"id": adventure_id})

Expand Down

0 comments on commit c1c9296

Please sign in to comment.