diff --git a/lms/lmsweb/views.py b/lms/lmsweb/views.py index 9eeb6709..2bb18760 100644 --- a/lms/lmsweb/views.py +++ b/lms/lmsweb/views.py @@ -377,7 +377,7 @@ def share(): solution_id = int(request.json.get('solutionId', 0)) try: - shared_solution = share_link.get(solution_id) + shared_solution = share_link.get_or_create(solution_id) except LmsError as e: error_message, status_code = e.args return fail(status_code, error_message) @@ -666,7 +666,7 @@ def shared_solution(shared_url: str, file_id: Optional[int] = None): if shared_solution is None: return fail(404, 'The solution does not exist.') - share_link.new(shared_solution) + share_link.new_visit(shared_solution) solution_id = shared_solution.solution.id return view( solution_id=solution_id, file_id=file_id, shared_url=shared_url, diff --git a/lms/models/share_link.py b/lms/models/share_link.py index b07e11d6..16461a6c 100644 --- a/lms/models/share_link.py +++ b/lms/models/share_link.py @@ -6,7 +6,7 @@ from lms.models.errors import ForbiddenPermission, ResourceNotFound -def get(solution_id: int) -> SharedSolution: +def get_or_create(solution_id: int) -> SharedSolution: if not webapp.config.get('SHAREABLE_SOLUTIONS', False): raise ForbiddenPermission('Shareable solutions are not allowed.', 403) @@ -30,7 +30,7 @@ def get(solution_id: int) -> SharedSolution: return shared_solution -def new(shared_solution: SharedSolution) -> None: +def new_visit(shared_solution: SharedSolution) -> None: SharedSolutionEntry.create( referrer=request.referrer, user=current_user.id, diff --git a/lms/static/my.css b/lms/static/my.css index 12259b3b..553a0d49 100644 --- a/lms/static/my.css +++ b/lms/static/my.css @@ -503,14 +503,14 @@ button#share-action:hover { } .code-toolbar-button, -#share-text { +#shared-text { padding: 0.4rem; margin: 0 0.2rem; border-radius: 0; outline: none; } -#share-box > button { +#shared-box > button { padding: 0 0.7rem; } @@ -537,7 +537,7 @@ button#share-action:hover { align-items: center; } -#share-box { +#shared-box { display: flex; position: absolute; direction: rtl; @@ -551,7 +551,7 @@ button#share-action:hover { padding: 0.4rem; } -#share-box * { +#shared-box * { position: relative; display: flex; line-height: unset; diff --git a/lms/static/my.js b/lms/static/my.js index 3b04a3ab..9e798eb9 100644 --- a/lms/static/my.js +++ b/lms/static/my.js @@ -23,10 +23,10 @@ function sendShareRequest(act, solutionId, callback) { xhr.setRequestHeader('Content-Type', 'application/json'); xhr.responseType = 'json'; - xhr.onreadystatechange = () => { callback(xhr); }; + xhr.onreadystatechange = () => {callback(xhr);}; xhr.send( - JSON.stringify({ act, solutionId }), + JSON.stringify({act, solutionId}), ); return xhr; } @@ -38,7 +38,7 @@ function trackCopyButton(button, context) { } function hideShareLink(xhr) { - const shareBox = document.getElementById('share-box'); + const shareBox = document.getElementById('shared-box'); if (xhr.readyState === 4) { if (xhr.status === 200) { shareBox.classList.add('d-none'); @@ -49,8 +49,8 @@ function hideShareLink(xhr) { } function updateShareLink(xhr) { - const shareBox = document.getElementById('share-box'); - const shareText = document.getElementById('share-text'); + const shareBox = document.getElementById('shared-box'); + const shareText = document.getElementById('shared-text'); if (xhr.readyState === 4) { if (xhr.status === 200) { if (shareBox.classList.contains('d-none')) { diff --git a/lms/templates/view.html b/lms/templates/view.html index bc9e5da9..2be6616e 100644 --- a/lms/templates/view.html +++ b/lms/templates/view.html @@ -56,10 +56,10 @@