Skip to content

Commit

Permalink
resolve twig global conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
pjc09h committed May 22, 2024
1 parent 46dcde8 commit f63a5d3
Show file tree
Hide file tree
Showing 26 changed files with 52 additions and 53 deletions.
7 changes: 3 additions & 4 deletions app/Models/Roles.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,13 @@ public function can(array $permissions): bool
}

# user has no permissions on the resource
$userRole->attributes->permissionsList[$resource] ??= [];
if (empty($userRole->attributes->permissionsList[$resource])) {
$userRole->attributes->permissionsList->$resource ??= [];
if (empty($userRole->attributes->permissionsList->$resource)) {
return false;
}

# permission not in user's role
$permissionsArray = $userRole->attributes->permissionsList->toArray();
if (!in_array($action, $permissionsArray[$resource])) {
if (!in_array($action, $userRole->attributes->permissionsList->$resource)) {
return false;
}
}
Expand Down
6 changes: 3 additions & 3 deletions app/Twig.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ private static function factory(array $options = []): \Twig\Environment
$frontendHash = password_hash($frontendKey, PASSWORD_DEFAULT);
$twig->addGlobal("frontendHash", $frontendHash);

# request
$request = Http::request();
$twig->addGlobal("request", $request);
# http request
$http = Http::request();
$twig->addGlobal("http", $http);

# https://github.com/paragonie/anti-csrf
$twig->addFunction(new \Twig\TwigFunction(
Expand Down
3 changes: 1 addition & 2 deletions sections/requests/details.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@
"successMessage" => $successMessage ?? null,
"errorMessage" => $errorMessage ?? null,

"js" => ["vendor/easymde.min", "vendor/tom-select.base.min", "browse", "conversations", "cover_art", "subscriptions"],
"css" => ["vendor/easymde.min", "vendor/tom-select.bootstrap5.min"],
"js" => ["browse", "conversations", "subscriptions"],

"request" => $request,
"isBookmarked" => false, # todo
Expand Down
2 changes: 1 addition & 1 deletion templates/_base/conversation.twig
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
<input type="hidden" name="conversationId" value="{{ conversation.id }}">
<input type="hidden" name="userId" value="{{ user.core.id }}">
<input type="hidden" id="replyToId" name="replyToId" value=""> {# no value yet #}
<input type="hidden" name="redirectToUri" value="{{ request.server.REQUEST_URI }}">
<input type="hidden" name="redirectToUri" value="{{ http.server.REQUEST_URI }}">

{# for some reason, only an underscore not a hyphen works in this context #}
{# https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id #}
Expand Down
4 changes: 2 additions & 2 deletions templates/admin/clientWhitelist.twig
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<form method="post">

{{ form_token(request.server.REQUEST_URI) }}
{{ form_token(http.server.REQUEST_URI) }}

<tr>
<td><input type="text" name="clientName" placeholder="Client name" required></td>
Expand All @@ -28,7 +28,7 @@
{% for item in clients %}
<form method="post">

{{ form_token(request.server.REQUEST_URI) }}
{{ form_token(http.server.REQUEST_URI) }}

<input type="hidden" name="id" value="{{ item.id }}">

Expand Down
2 changes: 1 addition & 1 deletion templates/admin/databaseKey.twig
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<section>
<form method="post">

{{ form_token(request.server.REQUEST_URI) }}
{{ form_token(http.server.REQUEST_URI) }}

<p>
<input type="text" name="databaseKey" style="width: 100%" placeholder="Enter a database encryption key" required>
Expand Down
4 changes: 2 additions & 2 deletions templates/admin/emailBlacklist.twig
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<h3>Add to the blacklist</h3>
<form method="post" class="flexRow">

{{ form_token(request.server.REQUEST_URI) }}
{{ form_token(http.server.REQUEST_URI) }}

<input type="hidden" name="create" value="create">
<input type="text" name="email" placeholder="Email or domain" required>
Expand Down Expand Up @@ -49,7 +49,7 @@
{% for item in data %}
<form method="post">

{{ form_token(request.server.REQUEST_URI) }}
{{ form_token(http.server.REQUEST_URI) }}

<input type="hidden" name="uuid" value="{{ item.uuid }}">

Expand Down
2 changes: 1 addition & 1 deletion templates/admin/miscValues.twig
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ View::footer();
<section>
<form method="post">
{{ form_token(request.server.REQUEST_URI) }}
{{ form_token(http.server.REQUEST_URI) }}
<p>
<input type="text" name="databaseKey" style="width: 100%" placeholder="Enter a database encryption key" required>
Expand Down
2 changes: 1 addition & 1 deletion templates/admin/roles/createUpdate.twig
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

{# form #}
<form method="post">
{{ form_token(request.server.REQUEST_URI) }}
{{ form_token(http.server.REQUEST_URI) }}

<input type="hidden" name="id" value="{{ role.id }}">

Expand Down
2 changes: 1 addition & 1 deletion templates/admin/siteNews.twig
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

{# start the news form (subject and body should be nullable in the controller) #}
<form name="siteNews" method="post" action="/toolbox/newsPosts">
{{ form_token(request.server.REQUEST_URI) }}
{{ form_token(http.server.REQUEST_URI) }}

<input type="hidden" name="auth" value="{{ user.extra.AuthKey }}">

Expand Down
2 changes: 1 addition & 1 deletion templates/collages/updateOrCreate.twig
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<form name="collage" method="post">

{# hidden fields #}
{{ form_token(request.server.REQUEST_URI) }}
{{ form_token(http.server.REQUEST_URI) }}
<input type="hidden" name="id" value={{ collage.id }}>
<input type="hidden" name="userId" value="{{ user.core.id }}">

Expand Down
2 changes: 1 addition & 1 deletion templates/discourse/boards/newEdit.twig
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
{% endif %}

<form method="post">
{{ form_token(request.server.REQUEST_URI) }}
{{ form_token(http.server.REQUEST_URI) }}

<input type="text" id="subject" name="subject" placeholder="Thread subject line" value="" required>

Expand Down
4 changes: 2 additions & 2 deletions templates/discourse/boards/sidebar.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<form method="post">
{{ form_token(request.server.REQUEST_URI) }}
{{ form_token(http.server.REQUEST_URI) }}

<input type="text" id="search" name="search" placeholder="Search the forums">
</form>
Expand All @@ -8,7 +8,7 @@
<h3>Actions</h3>

<form method="post">
{{ form_token(request.server.REQUEST_URI) }}
{{ form_token(http.server.REQUEST_URI) }}

<input type="button" id="create" name="create" value="new thread" class="button-primary">

Expand Down
2 changes: 1 addition & 1 deletion templates/discourse/messages/index.twig
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
{% endif %}

<form method="post">
{{ form_token(request.server.REQUEST_URI) }}
{{ form_token(http.server.REQUEST_URI) }}

<input type="text" id="participants" name="participants" placeholder="Send the message to" value="" required>

Expand Down
6 changes: 3 additions & 3 deletions templates/discourse/messages/sidebar.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<form method="post">
{{ form_token(request.server.REQUEST_URI) }}
{{ form_token(http.server.REQUEST_URI) }}

<input type="text" id="query" name="query" placeholder="Search your private messages">
</form>
Expand All @@ -8,7 +8,7 @@
<h3>Actions</h3>

<form method="post">
{{ form_token(request.server.REQUEST_URI) }}
{{ form_token(http.server.REQUEST_URI) }}

<select name="action" id="action">
<option value="">Do this to the selected messages</option>
Expand All @@ -26,7 +26,7 @@
<h3>Filters</h3>

<form method="post">
{{ form_token(request.server.REQUEST_URI) }}
{{ form_token(http.server.REQUEST_URI) }}

<input type="submit" id="inbox" name="inbox" value="inbox" class="button-primary">

Expand Down
4 changes: 2 additions & 2 deletions templates/discourse/wiki/index.twig
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
{% block sidebar %}

<form method="post">
{{ form_token(request.server.REQUEST_URI) }}
{{ form_token(http.server.REQUEST_URI) }}

<input type="text" id="search" name="search" placeholder="Search the wiki">
</form>
Expand All @@ -28,7 +28,7 @@
<h3>Actions</h3>

<form method="post">
{{ form_token(request.server.REQUEST_URI) }}
{{ form_token(http.server.REQUEST_URI) }}

<input type="button" id="create" name="create" value="create" class="button-primary">

Expand Down
2 changes: 1 addition & 1 deletion templates/index/sidebar.twig
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{# search bar #}
{#
<form method="post">
{{ form_token(request.server.REQUEST_URI) }}
{{ form_token(http.server.REQUEST_URI) }}
<input type="text" id="search" name="search" placeholder="Search the site">
Expand Down
15 changes: 8 additions & 7 deletions templates/requests/sidebarDetails.twig
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

{# vote #}
<form method="post">
{{ form_token(request.server.REQUEST_URI) }}
{{ form_token(http.server.REQUEST_URI) }}

<input type="number" id="voteAmount" name="voteAmount" min="1" placeholder="Vote on this request">

Expand Down Expand Up @@ -78,36 +78,37 @@
</section>


{# creators #}
{# creators # }
<section>
<h3>Creators</h3>
{% for creator in request.relationships.creators %}
{# todo: display_artist #}
{# todo: display_artist # }
{{ creator.name }}
{#
{% set uri = "/requests?creator=" ~ creator.id %}
<a href="{{ uri }}">{{ creator.name }}</a>
#}
# }
{% endfor %}
</section>
{# tags #}
{# tags # }
<section>
<h3>Tags</h3>
{% for creator in request.relationships.creators %}
{# todo: display_artist #}
{# todo: display_artist # }
{{ creator.name }}
{#
{% set uri = "/requests?creator=" ~ creator.id %}
<a href="{{ uri }}">{{ creator.name }}</a>
#}
# }
{% endfor %}
#}

</section>
2 changes: 1 addition & 1 deletion templates/requests/updateOrCreate.twig
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<section>

<form method="post">
{{ form_token(request.server.REQUEST_URI) }}
{{ form_token(http.server.REQUEST_URI) }}

{# id #}
{% if request.id %}
Expand Down
2 changes: 1 addition & 1 deletion templates/torrents/upload.twig
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<form id="torrentForm" method="post" enctype="multipart/form-data">

{# hidden fields #}
{{ form_token(request.server.REQUEST_URI) }}
{{ form_token(http.server.REQUEST_URI) }}
<input type="hidden" name="submit" value="true">
<input type="hidden" name="auth" value="{{ user.extra.AuthKey }}">

Expand Down
2 changes: 1 addition & 1 deletion templates/user/auth/disabled.twig
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
</p>

<form method="post">
{{ form_token(request.server.REQUEST_URI) }}
{{ form_token(http.server.REQUEST_URI) }}

{% if username is defined %}
<input type="hidden" name="username" id="username" value="{{ username }}">
Expand Down
2 changes: 1 addition & 1 deletion templates/user/auth/login.twig
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

{# regular login form #}
<form name="login" id="login" method="post">
{{ form_token(request.server.REQUEST_URI) }}
{{ form_token(http.server.REQUEST_URI) }}

{# username #}
<input type="text" name="username" id="username" placeholder="Username" autofocus="autofocus" autocomplete="username webauthn" required>
Expand Down
4 changes: 2 additions & 2 deletions templates/user/auth/recover.twig
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

{% if not emailSent %}
<form name="recover" id="recover" method="post">
{{ form_token(request.server.REQUEST_URI) }}
{{ form_token(http.server.REQUEST_URI) }}

<input type="email" name="email" id="email" placeholder="Email address" required>

Expand All @@ -45,7 +45,7 @@
</p>

<form name="recover" id="recover" method="post">
{{ form_token(request.server.REQUEST_URI) }}
{{ form_token(http.server.REQUEST_URI) }}

<input type="hidden" name="selector" value="{{ selector }}">

Expand Down
18 changes: 9 additions & 9 deletions templates/user/auth/register.twig
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,23 @@

{# start the registration form itself #}
<form name="register" id="register" method="post" autocomplete="off">
{{ form_token(request.server.REQUEST_URI) }}
{{ form_token(http.server.REQUEST_URI) }}

{# invite #}
{% if request.get.invite is defined %}
{% if http.get.invite is defined %}
<input type="hidden" name="invite" id="invite" value="{{ invite }}">
{% endif %}

{# username #}
{% if request.post.username is defined %}
<input type="text" name="username" id="username" placeholder="Username" value="{{ request.post.username }}" required>
{% if http.post.username is defined %}
<input type="text" name="username" id="username" placeholder="Username" value="{{ http.post.username }}" required>
{% else %}
<input type="text" name="username" id="username" placeholder="Username" required>
{% endif %}

{# email #}
{% if request.post.email is defined %}
<input type="email" name="email" id="email" placeholder="Email address" value="{{ request.post.email }}" required>
{% if http.post.email is defined %}
<input type="email" name="email" id="email" placeholder="Email address" value="{{ http.post.email }}" required>
{% else %}
<input type="email" name="email" id="email" placeholder="Email address" required>
{% endif %}
Expand Down Expand Up @@ -72,7 +72,7 @@
<ul>
<li>
{# isAdult #}
{% if request.post.isAdult is defined %}
{% if http.post.isAdult is defined %}
<input type="checkbox" name="isAdult" id="isAdult" value="true" checked>
{% else %}
<input type="checkbox" name="isAdult" id="isAdult" value="true">
Expand All @@ -82,7 +82,7 @@

<li>
{# privacyConsent #}
{% if request.post.privacyConsent is defined %}
{% if http.post.privacyConsent is defined %}
<input type="checkbox" name="privacyConsent" id="privacyConsent" value="true" checked>
{% else %}
<input type="checkbox" name="privacyConsent" id="privacyConsent" value="true">
Expand All @@ -92,7 +92,7 @@

<li>
{# ruleWikiPledge #}
{% if request.post.ruleWikiPledge is defined %}
{% if http.post.ruleWikiPledge is defined %}
<input type="checkbox" name="ruleWikiPledge" id="ruleWikiPledge" value="true" checked>
{% else %}
<input type="checkbox" name="ruleWikiPledge" id="ruleWikiPledge" value="true">
Expand Down
2 changes: 1 addition & 1 deletion templates/user/settings/settings.twig
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<form method="post" id="userSettingsForm" name="userSettingsForm">

{# hidden fields #}
{{ form_token(request.server.REQUEST_URI) }}
{{ form_token(http.server.REQUEST_URI) }}
<input type="hidden" name="userId" value="{{ user.core.id }}">
<input type="hidden" name="authKey" value="{{ user.extra.AuthKey }}">

Expand Down
2 changes: 1 addition & 1 deletion templates/wiki/compare.twig
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<h2>Revision history for <a href="/wiki/{{ article.id }}">{{ article.attributes.title }}</a></h2>

<form method="post">
{{ form_token(request.server.REQUEST_URI) }}
{{ form_token(http.server.REQUEST_URI) }}

<input type="hidden" name="articleId" value="{{ article.id }}">

Expand Down

0 comments on commit f63a5d3

Please sign in to comment.