Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

💻 Use subdomains to navigate through languages #5829

Closed
wants to merge 59 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
3d7f6a9
add subdomain in routes inside app.py
jpelay Oct 3, 2024
f1d0391
adding subdomains in auth pages
jpelay Oct 3, 2024
5e2ee24
commit to test something
jpelay Oct 7, 2024
3c79486
fixing redirection locally
jpelay Oct 8, 2024
365c171
fix tests
jpelay Oct 9, 2024
d34186b
fix language switcher
jpelay Oct 9, 2024
24ac449
add subdomains to admin routes
jpelay Oct 11, 2024
644364d
add subdomains to class routes
jpelay Oct 11, 2024
c996b15
add routs to feedback
jpelay Oct 11, 2024
192bdb9
change every remaining route
jpelay Oct 11, 2024
a61ee44
fix programs and teacher tests
jpelay Oct 14, 2024
fbe5339
Merge branch 'main' into subdomains
jpelay Oct 28, 2024
af4d50a
fix profile route
jpelay Oct 29, 2024
ff03266
fix end to end tests
jpelay Oct 29, 2024
676cded
update config
jpelay Oct 29, 2024
f944e33
Update app.py
jpelay Oct 29, 2024
1486492
use domain name parameter
jpelay Nov 7, 2024
9755651
Merge main into subdomains
jpelay Nov 7, 2024
9844aad
🤖 Automatically update generated files
jpelay Nov 7, 2024
ca1a343
fix cypress test
jpelay Nov 8, 2024
69598af
correctly redirect after login and signup
jpelay Nov 12, 2024
cef4f51
properly set subdomain when changing lang in profile
jpelay Nov 12, 2024
8fc0533
fix languages witn underscore
jpelay Nov 12, 2024
6828533
Merge branch 'main' into subdomains
jpelay Nov 12, 2024
502198b
🤖 Automatically update generated files
jpelay Nov 12, 2024
d5e22a4
improving things a bit
jpelay Nov 12, 2024
996680f
also login cookie set to stritc
jpelay Nov 13, 2024
11354e2
fix tests
jpelay Nov 13, 2024
a1143a7
Merge branch 'main' into subdomains
jpelay Nov 13, 2024
6251173
🤖 Automatically update generated files
jpelay Nov 13, 2024
ca2e370
delete unwanted file
jpelay Nov 13, 2024
b878194
delete logs
jpelay Nov 13, 2024
0b4393d
fix e2e tests
jpelay Nov 13, 2024
1effa88
Merge branch 'main' into subdomains
jpelay Nov 13, 2024
9be4d87
use strict cookie
jpelay Nov 18, 2024
40426df
no cache for cookies
jpelay Nov 18, 2024
f2cc1c0
Merge branch 'main' into subdomains
jpelay Nov 18, 2024
297f4c4
Update appbundle.js.map
jpelay Nov 18, 2024
9dcedbe
strict
jpelay Nov 18, 2024
ff0bd19
Add domain name to token cookie, changes SESSION_COOKIE_NAME
boryanagoncharenko Nov 25, 2024
4bdbd9d
Merge branch 'main' of github.com:Felienne/hedy into subdomains
boryanagoncharenko Nov 25, 2024
a74d65b
🤖 Automatically update generated files
boryanagoncharenko Nov 25, 2024
adf20a8
Update domain on hedy cookie
boryanagoncharenko Nov 26, 2024
e6a431f
show proper language in profile page
jpelay Nov 27, 2024
c8d6fbf
fix some routes that were not properly adapted
jpelay Nov 27, 2024
50a8d33
Merge branch 'main' into subdomains
jpelay Nov 28, 2024
ca2ec91
🤖 Automatically update generated files
jpelay Nov 28, 2024
2d6dfc1
fix redirection
jpelay Nov 28, 2024
cc79e20
Merge branch 'subdomains' of https://github.com/hedyorg/hedy into sub…
jpelay Nov 28, 2024
9fb23a4
properly redirect when the user hasnt visited a previous page
jpelay Nov 28, 2024
c160415
simplify redirection when loggin in teachers
jpelay Nov 28, 2024
ebb58b5
🤖 Automatically update generated files
jpelay Nov 28, 2024
1af722e
fixes generating links for explore programs
jpelay Nov 28, 2024
19e5bcf
Merge branch 'subdomains' of https://github.com/hedyorg/hedy into sub…
jpelay Nov 28, 2024
9289934
🤖 Automatically update generated files
jpelay Nov 28, 2024
94d4525
fix parsing programs
jpelay Nov 28, 2024
e8edfcf
Add a missing route for clear-preview-class
boryanagoncharenko Nov 29, 2024
5a1e007
Merge branch 'main' into subdomains
jpelay Nov 29, 2024
f563589
🤖 Automatically update generated files
jpelay Nov 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
232 changes: 173 additions & 59 deletions app.py

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@
import socket

app_name = os.getenv('HEROKU_APP_NAME', socket.gethostname())
dyno = os.getenv('DYNO')
dyno = os.getenv('DYNO') # if this env variable is set, it means we are in a Heroku
athena_query = os.getenv('AWS_ATHENA_PREPARE_STATEMENT')

config = {
'port': os.getenv('PORT') or 8080,
'port': os.getenv('PORT', 8080),
# I can't reference a previous field, so copying and pasting here
boryanagoncharenko marked this conversation as resolved.
Show resolved Hide resolved
'domain_name': (
f"{os.getenv('DOMAIN_NAME')}" if dyno # if we are in localhost no need to add port
boryanagoncharenko marked this conversation as resolved.
Show resolved Hide resolved
else f"{os.getenv('DOMAIN_NAME', 'localhost')}:{os.getenv('PORT', 8080)}"
),
'session': {
'cookie_name': 'hedy',
# in minutes
Expand Down
4 changes: 2 additions & 2 deletions dodo.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from glob import glob
import sys
import platform

from config import config as CONFIG
from doit.tools import LongRunning

if os.getenv('GITHUB_ACTION') and platform.system() == 'Windows':
Expand Down Expand Up @@ -354,7 +354,7 @@ def task_devserver():
LongRunning([python3, 'app.py'], shell=False, env=dict(
os.environ,
# These are required to make some local features work.
BASE_URL="http://localhost:8080/",
BASE_URL=f"http://{CONFIG['domain_name']}",
ADMIN_USER="admin",))
],
verbosity=2, # show everything live
Expand Down
44 changes: 27 additions & 17 deletions static/js/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ let theAdventures: Record<string, Adventure> = {};
export let theLevel: number = 0;
export let theLanguage: string = '';
export let theKeywordLanguage: string = 'en';
export let theDomainName: string = '';
let theStaticRoot: string = '';
let currentTab: string;
let theUserIsLoggedIn: boolean;
Expand Down Expand Up @@ -123,10 +124,11 @@ const slides_template = `
export interface InitializeAppOptions {
readonly level: number;
readonly keywordLanguage: string;
readonly domainName: string
/**
* The URL root where static content is hosted
*/
readonly staticRoot?: string;
readonly staticRoot?: string;
}

/**
Expand All @@ -138,6 +140,7 @@ export function initializeApp(options: InitializeAppOptions) {
theStaticRoot = options.staticRoot ?? '';
// When we are in Alpha or in dev the static root already points to an internal directory
theStaticRoot = theStaticRoot === '/' ? '' : theStaticRoot;
theDomainName = options.domainName;
initializeCopyToClipboard();

// Close the dropdown menu if the user clicks outside of it
Expand Down Expand Up @@ -668,7 +671,7 @@ export function tryPaletteCode(exampleCode: string) {
}

export function viewProgramLink(programId: string) {
return window.location.origin + '/hedy/' + programId + '/view';
return `${location.protocol}//${theDomainName}/hedy/${programId}/view`;
}

function updateProgramCount() {
Expand Down Expand Up @@ -1557,22 +1560,29 @@ export function toggle_blur_code() {
}
}

export async function change_language(lang: string) {
await tryCatchPopup(async () => {
const response = await postJson('/change_language', { lang });
if (response) {
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);

if (lang === 'en' || urlParams.get("language") !== null) {
urlParams.set("language", lang)
urlParams.set('keyword_language', lang);
window.location.search = urlParams.toString();
} else {
location.reload();
export async function change_language(lang: string) {
if (theDomainName.includes('localhost')) {
await tryCatchPopup(async () => {
const response = await postJson('/change_language', { lang });
if (response) {
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);

if (lang === 'en' || urlParams.get("language") !== null) {
urlParams.set("language", lang)
urlParams.set('keyword_language', lang);
window.location.search = urlParams.toString();
} else {
location.reload();
}
}
}
});
});
} else {
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
urlParams.set('keyword_language', lang);
location.href = `${location.protocol}//${lang}.${theDomainName}${location.pathname}?${urlParams.toString()}`
}
}

function update_view(selector_container: string, new_lang: string) {
Expand Down
97 changes: 65 additions & 32 deletions static/js/appbundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -60665,6 +60665,7 @@ ${o3}` : i3;
store_parsons_attempt: () => store_parsons_attempt,
submit_program: () => submit_program,
success: () => success,
theDomainName: () => theDomainName,
theGlobalDebugger: () => theGlobalDebugger,
theGlobalEditor: () => theGlobalEditor,
theGlobalSourcemap: () => theGlobalSourcemap,
Expand Down Expand Up @@ -120017,9 +120018,19 @@ def note_with_error(value, err):
});
return result;
}
function redirect(where) {
where = "/" + where;
window.location.pathname = where;
function redirect(where, lang) {
if (lang === void 0) {
location.pathname = "/" + where;
return;
}
if (/^localhost:\d\d\d\d|(\d+\.\d+\.\d+\.\d+:\d\d\d\d)$/.test(theDomainName)) {
window.location.href = `http://${theDomainName}/${where}?lang=${lang}`;
return;
} else {
const protocol = location.protocol;
window.location.href = `${protocol}//${lang}.${theDomainName}/${where}`;
return;
}
}
async function logout() {
await postNoResponse("/auth/logout");
Expand Down Expand Up @@ -120052,17 +120063,21 @@ def note_with_error(value, err):
tryCatchPopup(async () => {
const body = convertFormJSON($(this));
await postNoResponse("/auth/signup", body);
afterLogin({ "first_time": true, "is_teacher": "is_teacher" in body });
afterLogin({ "first_time": true, "teacher": "is_teacher" in body, "lang": body["language"] || "en" });
});
});
$("form#login").on("submit", function(e) {
e.preventDefault();
tryCatchPopup(async () => {
const response = await postJson("/auth/login", convertFormJSON($(this)));
if (response["first_time"]) {
return afterLogin({ "first_time": true });
return afterLogin({ "first_time": true, "lang": response["lang"] });
}
return afterLogin({ "admin": response["admin"] || false, "teacher": response["teacher"] });
return afterLogin({
"admin": response["admin"] || false,
"teacher": response["teacher"] || false,
"lang": response["lang"]
});
});
});
$("form#profile").on("submit", function(e) {
Expand All @@ -120072,7 +120087,12 @@ def note_with_error(value, err):
if (response.reload) {
modal.notifySuccess(response.message, 2e3);
setTimeout(function() {
location.reload();
if (response["new_lang"]) {
const new_lang = response["new_lang"];
location.href = `${location.protocol}//${new_lang}.${theDomainName}/my-profile`;
} else {
location.reload();
}
}, 2e3);
} else {
modal.notifySuccess(response.message);
Expand Down Expand Up @@ -120187,8 +120207,10 @@ def note_with_error(value, err):
async function afterLogin(loginData) {
var _a3;
const { url } = (_a3 = localLoadOnce(REDIRECT_AFTER_LOGIN_KEY)) != null ? _a3 : {};
const userLang = loginData["lang"];
if (url && !loginData["first_time"]) {
window.location = url;
const urlObject = new URL(url);
window.location.href = `${urlObject.protocol}//${userLang}.${theDomainName}${urlObject.pathname}${urlObject.search !== "" ? "?" + urlObject.search : ""}`;
return;
}
const joinClassString = localStorage.getItem("hedy-join");
Expand All @@ -120197,18 +120219,18 @@ def note_with_error(value, err):
localStorage.removeItem("hedy-join");
return join_class(joinClass.id, joinClass.name);
}
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["teacher"]) {
redirect("for-teachers", userLang);
return;
} else if (loginData["first_time"] && !loginData["teacher"]) {
redirect("hedy/1", userLang);
return;
}
if (loginData["admin"]) {
return redirect("admin");
}
if (loginData["teacher"]) {
return redirect("for-teachers");
redirect("admin", userLang);
return;
}
redirect("");
redirect("", userLang);
}

// static/js/local-save-warning.ts
Expand Down Expand Up @@ -120578,6 +120600,7 @@ def note_with_error(value, err):
var theLevel = 0;
var theLanguage2 = "";
var theKeywordLanguage = "en";
var theDomainName = "";
var theStaticRoot = "";
var currentTab;
var theUserIsLoggedIn;
Expand Down Expand Up @@ -120649,6 +120672,7 @@ def note_with_error(value, err):
theKeywordLanguage = options.keywordLanguage;
theStaticRoot = (_a3 = options.staticRoot) != null ? _a3 : "";
theStaticRoot = theStaticRoot === "/" ? "" : theStaticRoot;
theDomainName = options.domainName;
initializeCopyToClipboard();
$(document).on("click", function(event2) {
if (!$(event2.target).closest(".dropdown").length) {
Expand Down Expand Up @@ -121041,7 +121065,7 @@ def note_with_error(value, err):
}
}
function viewProgramLink(programId) {
return window.location.origin + "/hedy/" + programId + "/view";
return `${location.protocol}//${theDomainName}/hedy/${programId}/view`;
}
function updateProgramCount() {
const programCountDiv = $("#program_count");
Expand Down Expand Up @@ -121723,20 +121747,27 @@ def note_with_error(value, err):
}
}
async function change_language(lang) {
await tryCatchPopup(async () => {
const response = await postJson("/change_language", { lang });
if (response) {
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
if (lang === "en" || urlParams.get("language") !== null) {
urlParams.set("language", lang);
urlParams.set("keyword_language", lang);
window.location.search = urlParams.toString();
} else {
location.reload();
if (theDomainName.includes("localhost")) {
await tryCatchPopup(async () => {
const response = await postJson("/change_language", { lang });
if (response) {
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
if (lang === "en" || urlParams.get("language") !== null) {
urlParams.set("language", lang);
urlParams.set("keyword_language", lang);
window.location.search = urlParams.toString();
} else {
location.reload();
}
}
}
});
});
} else {
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
urlParams.set("keyword_language", lang);
location.href = `${location.protocol}//${lang}.${theDomainName}${location.pathname}?${urlParams.toString()}`;
}
}
function update_view(selector_container, new_lang) {
$("#" + selector_container + " > div").map(function() {
Expand Down Expand Up @@ -122326,7 +122357,8 @@ def note_with_error(value, err):
initializeApp({
level: level3,
keywordLanguage: options.keyword_language,
staticRoot: options.staticRoot
staticRoot: options.staticRoot,
domainName: options.domainName
});
initializeFormSubmits();
initializeTutorial();
Expand Down Expand Up @@ -127507,6 +127539,7 @@ def note_with_error(value, err):
lang: js.lang,
level: parseInt(js.level),
keyword_language: js.lang,
domainName: js.domainName,
javascriptPageOptions: js
});
}, 1e3);
Expand Down
4 changes: 2 additions & 2 deletions static/js/appbundle.js.map

Large diffs are not rendered by default.

Loading