Skip to content

Commit

Permalink
💻 Stop aproving teacher accounts (#5747)
Browse files Browse the repository at this point in the history
Changes the process of becoming a teacher by skipping the approving step. Now users can simply make a teacher account by choosing the option when creating an account or simply choosing to do so from the profile menu.

Fixes #5724

**How to test**

* Create a new account choosing the teacher option. You can use this function to make your life easier:
```
function fill_fields() {
    let username = `teacher_${Math.random()}`;
    $('#username').val(username)
    $('#email').val(username + '@p.ai');
    $('#password').val('123456')
    $('#password_repeat').val('123456')
    $('#language').val('en')
    $('#birth_year').val('1999')
    $('#gender').val('f')
    $('#country').val('VE')    
}
```
* After creating the account you should be able to create classes and such.

Then, you can log into a normal account, go to the profile page and click this button:
![image](https://github.com/user-attachments/assets/5f5d73fe-d571-4f9a-94de-a2bce046147d)

Now your account should be a teacher account.
  • Loading branch information
jpelay committed Sep 6, 2024
1 parent 996c426 commit 900c912
Show file tree
Hide file tree
Showing 70 changed files with 978 additions and 967 deletions.
15 changes: 3 additions & 12 deletions messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,6 @@ msgstr ""
msgid "already_program_running"
msgstr ""

msgid "already_teacher"
msgstr ""

msgid "already_teacher_request"
msgstr ""

msgid "are_you_sure"
msgstr ""

Expand Down Expand Up @@ -1643,12 +1637,6 @@ msgstr ""
msgid "teacher"
msgstr ""

msgid "teacher_account_request"
msgstr ""

msgid "teacher_account_success"
msgstr ""

msgid "teacher_invalid"
msgstr ""

Expand Down Expand Up @@ -1745,6 +1733,9 @@ msgstr ""
msgid "translator"
msgstr ""

msgid "turned_into_teacher"
msgstr ""

msgid "tutorial"
msgstr ""

Expand Down
19 changes: 11 additions & 8 deletions static/js/appbundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -60478,7 +60478,6 @@ ${o3}` : i3;
remove_student_invite: () => remove_student_invite,
rename_class: () => rename_class,
report_program: () => report_program,
request_teacher_account: () => request_teacher_account,
resetDebug: () => resetDebug,
resolve_student: () => resolve_student,
restore_customization_to_default: () => restore_customization_to_default,
Expand Down Expand Up @@ -60522,6 +60521,7 @@ ${o3}` : i3;
tryCatchErrorBox: () => tryCatchErrorBox,
tryCatchPopup: () => tryCatchPopup,
tryPaletteCode: () => tryPaletteCode,
turn_into_teacher_account: () => turn_into_teacher_account,
unsubmit_program: () => unsubmit_program,
update_adventure: () => update_adventure,
update_user_tags: () => update_user_tags,
Expand Down Expand Up @@ -119612,21 +119612,22 @@ def note_with_error(value, err):
location.reload();
});
}
async function request_teacher_account() {
async function turn_into_teacher_account() {
tryCatchPopup(async () => {
const response = await postJson("/auth/request_teacher");
const response = await postJson("/auth/turn-into-teacher");
modal.notifySuccess(response.message);
setTimeout(function() {
location.reload();
redirect("for-teachers");
}, 2e3);
});
}
function initializeFormSubmits() {
$("form#signup").on("submit", async function(e) {
e.preventDefault();
tryCatchPopup(async () => {
await postNoResponse("/auth/signup", convertFormJSON($(this)));
afterLogin({ "first_time": true });
const body = convertFormJSON($(this));
await postNoResponse("/auth/signup", body);
afterLogin({ "first_time": true, "is_teacher": "is_teacher" in body });
});
});
$("form#login").on("submit", function(e) {
Expand Down Expand Up @@ -119761,7 +119762,7 @@ def note_with_error(value, err):
async function afterLogin(loginData) {
var _a3;
const { url } = (_a3 = localLoadOnce(REDIRECT_AFTER_LOGIN_KEY)) != null ? _a3 : {};
if (url) {
if (url && !loginData["first_time"]) {
window.location = url;
return;
}
Expand All @@ -119771,7 +119772,9 @@ def note_with_error(value, err):
localStorage.removeItem("hedy-join");
return join_class(joinClass.id, joinClass.name);
}
if (loginData["first_time"]) {
if (loginData["first_time"] && loginData["is_teacher"]) {
return redirect("for-teachers");
} else if (loginData["first_time"] && !loginData["is_teacher"]) {
return redirect("hedy/1");
}
if (loginData["admin"]) {
Expand Down
4 changes: 2 additions & 2 deletions static/js/appbundle.js.map

Large diffs are not rendered by default.

22 changes: 13 additions & 9 deletions static/js/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ export function destroy_public(confirmation: string) {
});
}

export async function request_teacher_account() {
export async function turn_into_teacher_account() {
tryCatchPopup(async () => {
const response = await postJson('/auth/request_teacher');
const response = await postJson('/auth/turn-into-teacher');
modal.notifySuccess(response.message);
setTimeout (function () {location.reload ()}, 2000);
setTimeout (function () { redirect('for-teachers') }, 2000);
});
}

Expand All @@ -91,8 +91,9 @@ export function initializeFormSubmits() {
$('form#signup').on('submit', async function (e) {
e.preventDefault();
tryCatchPopup(async () => {
await postNoResponse('/auth/signup', convertFormJSON($(this)));
afterLogin({"first_time": true});
const body = convertFormJSON($(this))
await postNoResponse('/auth/signup', body);
afterLogin({"first_time": true, "is_teacher": "is_teacher" in body});
});
});

Expand Down Expand Up @@ -248,7 +249,7 @@ export function update_user_tags() {
*/
async function afterLogin(loginData: Dict<boolean>) {
const { url } = localLoadOnce(REDIRECT_AFTER_LOGIN_KEY) ?? {};
if (url) {
if (url && !loginData['first_time']) {
window.location = url;
return;
}
Expand All @@ -260,9 +261,12 @@ async function afterLogin(loginData: Dict<boolean>) {
return join_class(joinClass.id, joinClass.name);
}

// If the user logs in for the first time -> redirect to the first-level after signup
if (loginData['first_time']) {
return redirect('hedy/1');
// If the user logs in for the first time and is a teacher -> redirect to the for teacher page
if (loginData['first_time'] && loginData['is_teacher']) {
return redirect('for-teachers');
// If it's a student, send him to the first level
} else if(loginData['first_time'] && !loginData['is_teacher']) {
return redirect('hedy/1')
}
// If the user is an admin -> re-direct to admin page after login
if (loginData['admin']) {
Expand Down
22 changes: 5 additions & 17 deletions templates/admin/admin-users.html
Original file line number Diff line number Diff line change
Expand Up @@ -164,23 +164,11 @@ <h4 class="text-center">Total amount of shown users: {{ users|length }}</h4>
<td class="gender_cell hidden">{{user.gender}}</td>
<td class="experience_cell hidden">{{user.prog_experience}}</td>
<td class="tags_cell text-center cursor-pointer"><span onclick="hedyApp.edit_user_tags('{{user.username}}');">✏️</span></td>
{% if user.teacher_request %}
<td id="teacher_request_{{user.username}}" class="teacher_cell text-center">
<span class="fa-solid fa-circle-question cursor-pointer"
hx-trigger="click"
hx-post="/admin/mark-as-teacher/{{user.username}}"
_="on click
remove #teacher_request_{{user.username}}
then toggle .hidden on #is_teacher_{{user.username}}
then set #check_teacher_{{user.username}}.checked to true">
</span>
</td>
{% endif %}
<td id="is_teacher_{{user.username}}" class="{% if user.teacher_request %}hidden{% endif %} teacher_cell text-center">
<input id="check_teacher_{{user.username}}" type="checkbox" {% if user.is_teacher %}checked{% endif %}
hx-trigger="click"
hx-post="/admin/mark-as-teacher/{{user.username}}">
</td>
<td id="is_teacher_{{user.username}}" class="teacher_cell text-center">
<input id="check_teacher_{{user.username}}" type="checkbox" {% if user.is_teacher %}checked{% endif %}
hx-trigger="click"
hx-post="/admin/mark-as-teacher/{{user.username}}">
</td>
<td class="teacher_cell text-center">
<input type="checkbox" {% if user.is_super_teacher %}checked="checked"{% endif %}
hx-trigger="click"
Expand Down
15 changes: 4 additions & 11 deletions templates/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@

{% block regular_content %}
<div>
{% if user_data['teacher_request'] %}
<div class="flex items-center justify-center w-full h-10 bg-yellow-500 text-white font-bold">
<div>
{{_('teacher_account_request')}}
</div>
</div>
{% endif %}
<h2 class="mx-4 lg:mx-16 px-2 mb-4">{{_('account_overview')}}</h2>
<div class="flex flex-col gap-4 mx-4 lg:mx-16">
{% if invitations %}
Expand Down Expand Up @@ -174,10 +167,10 @@ <h2 class="profile-section-body-header">{{_('change_password')}}</h2>
<button type="submit" class="green-btn mt-2">{{_('change_password')}}</button>
</form>
</div>
{% if not is_teacher and not user_data['teacher_request'] %}
<h1 id="teacher_toggle" class="section-header" onclick="$ ('#request_teacher_body').toggle()">{{_('request_teacher')}}</h1>
<div class="profile-section-body text-center" id="request_teacher_body">
<button class="blue-btn" onclick="hedyApp.request_teacher_account();">{{_('request_teacher_account')}}</button>
{% if not is_teacher %}
<h1 id="teacher_toggle" class="section-header" onclick="$ ('#turn_into_teacher_body').toggle()">{{_('request_teacher')}}</h1>
<div class="profile-section-body text-center" id="turn_into_teacher_body">
<button class="blue-btn" onclick="hedyApp.turn_into_teacher_account();">{{_('request_teacher_account')}}</button>
</div>
{% endif %}
</div>
Expand Down
11 changes: 1 addition & 10 deletions templates/super-teacher/support.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,10 @@ <h4 class="text-center">Total amount of shown users: {{ users|length }}</h4>
<td class="language_cell text-center p-2">{{user.language}}</td>
<td class="country_cell text-center p-2">{{user.country}}</td>
<td class="tags_cell text-center cursor-pointer text-center p-2">
{% if user.teacher_request %}
<button id="teacher_request_{{user.username}}" class="blue-btn"
hx-trigger="click"
hx-post="/admin/mark-as-teacher/{{user.username}}"
_="on click
remove #teacher_request_{{user.username}}
then toggle .hidden on #invite_support_teacher_{{user.username}}"
>Make teacher</button>
{% endif %}
{% if user.support_teacher %}
{{user.support_teacher}}
{% else %}
<button class="green-btn {% if user.teacher_request %}hidden{% endif %}" id="invite_support_teacher_{{user.username}}"
<button class="green-btn" id="invite_support_teacher_{{user.username}}"
onclick='hedyApp.invite_support_teacher("{{user.username}}")'>Pair support teacher</button>
{% endif %}
</td>
Expand Down
2 changes: 1 addition & 1 deletion tests/cypress/e2e/signup_page/signup.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ it('Is able to sign up as a teacher', () => {
cy.intercept('/auth/signup').as('sign_up');
cy.getDataCy('submit_button').click()
cy.wait('@sign_up').should('have.nested.property', 'response.statusCode', 200)
cy.url().should('contain', Cypress.config('baseUrl'));
cy.url().should('contain', Cypress.env('teachers_page'));

//delete profile
goToProfilePage();
Expand Down
31 changes: 15 additions & 16 deletions translations/ar/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 +322,6 @@ msgstr "هل لديك حساب بالفعل؟"
msgid "already_program_running"
msgstr "هناك بالفعل برنامج اخر تحت التنفيذ، قم بانهاء ذلك البرنامج أولاً."

#, fuzzy
msgid "already_teacher"
msgstr "You already have a teacher account."

#, fuzzy
msgid "already_teacher_request"
msgstr "You already have a pending teacher request."

msgid "are_you_sure"
msgstr "هل أنت متأكد؟ لا يمكنك التراجع عن هذا الإجراء."

Expand Down Expand Up @@ -1913,14 +1905,6 @@ msgstr "العلامات"
msgid "teacher"
msgstr "معلم"

#, fuzzy
msgid "teacher_account_request"
msgstr "You have a pending teacher account request"

#, fuzzy
msgid "teacher_account_success"
msgstr "You successfully requested a teacher account."

msgid "teacher_invalid"
msgstr "قيمة المعلم الخاصة بك غير صالحة."

Expand Down Expand Up @@ -2033,6 +2017,9 @@ msgstr "Translating Hedy"
msgid "translator"
msgstr "Translator"

msgid "turned_into_teacher"
msgstr ""

#, fuzzy
msgid "tutorial"
msgstr "Tutorial"
Expand Down Expand Up @@ -2518,3 +2505,15 @@ msgstr "Your program"
#~ msgid "your_last_program"
#~ msgstr "آخر برنامج تم حفظه"

#~ msgid "already_teacher"
#~ msgstr "You already have a teacher account."

#~ msgid "already_teacher_request"
#~ msgstr "You already have a pending teacher request."

#~ msgid "teacher_account_request"
#~ msgstr "You have a pending teacher account request"

#~ msgid "teacher_account_success"
#~ msgstr "You successfully requested a teacher account."

31 changes: 15 additions & 16 deletions translations/bg/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -338,14 +338,6 @@ msgstr "Вече имаш акаунт?"
msgid "already_program_running"
msgstr "There is already a program running, finish that one first."

#, fuzzy
msgid "already_teacher"
msgstr "You already have a teacher account."

#, fuzzy
msgid "already_teacher_request"
msgstr "You already have a pending teacher request."

msgid "are_you_sure"
msgstr "Внимание! Това действие е необратимо."

Expand Down Expand Up @@ -2127,14 +2119,6 @@ msgstr "Tags"
msgid "teacher"
msgstr "Teacher"

#, fuzzy
msgid "teacher_account_request"
msgstr "You have a pending teacher account request"

#, fuzzy
msgid "teacher_account_success"
msgstr "You successfully requested a teacher account."

#, fuzzy
msgid "teacher_invalid"
msgstr "Your teacher value is invalid."
Expand Down Expand Up @@ -2260,6 +2244,9 @@ msgstr "Translating Hedy"
msgid "translator"
msgstr "Translator"

msgid "turned_into_teacher"
msgstr ""

#, fuzzy
msgid "tutorial"
msgstr "Tutorial"
Expand Down Expand Up @@ -2776,3 +2763,15 @@ msgstr "Your program"
#~ msgid "your_last_program"
#~ msgstr "Your last saved program"

#~ msgid "already_teacher"
#~ msgstr "You already have a teacher account."

#~ msgid "already_teacher_request"
#~ msgstr "You already have a pending teacher request."

#~ msgid "teacher_account_request"
#~ msgstr "You have a pending teacher account request"

#~ msgid "teacher_account_success"
#~ msgstr "You successfully requested a teacher account."

Loading

0 comments on commit 900c912

Please sign in to comment.