Skip to content

fix: unlock share box from uBlock origins #347

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

Merged
merged 1 commit into from
Oct 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions lms/lmsweb/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions lms/models/share_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions lms/static/my.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -537,7 +537,7 @@ button#share-action:hover {
align-items: center;
}

#share-box {
#shared-box {
display: flex;
position: absolute;
direction: rtl;
Expand All @@ -551,7 +551,7 @@ button#share-action:hover {
padding: 0.4rem;
}

#share-box * {
#shared-box * {
position: relative;
display: flex;
line-height: unset;
Expand Down
10 changes: 5 additions & 5 deletions lms/static/my.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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');
Expand All @@ -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')) {
Expand Down
4 changes: 2 additions & 2 deletions lms/templates/view.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ <h1>{{ _('Exercise view') }} {{ solution['exercise']['number'] }}: {{ solution['
<div id="code-toolbar-buttons">
{% if config.SHAREABLE_SOLUTIONS and not shared_url %}
<div id="share-solution" class="code-toolbar-button glowing">
<div id="share-text">
<div id="shared-text">
<button id="share-action" title="Share solution"><i class="fa fa-share-alt"></i></button>
</div>
<div id="share-box" class="glowing d-none">
<div id="shared-box" class="glowing d-none">
<button id="cancel-share" class="share-button" title="Disable share solution"><i class="fa fa-trash"></i></button>
<button id="copy-link" class="share-button" title="Copy shared link"><i class="fa fa-copy"></i></button>
<input id="shareable-link" class="form-control" type="text" readonly>
Expand Down