RFC 50: fix some more hardcoded paths (#13473)

* fix: remove hardcoded paths

* fix: use path helpers

* swap href for link_to

* feat: use path helpers

* feat: use a data path to send through the path that we will be calling

* feat: pass route through to js

* dus index path

* chore: change to use path_helpers

* feat: update DUS controller

* chore: oops remove these paths
This commit is contained in:
Ridhwana 2021-04-26 17:49:54 +02:00 committed by GitHub
parent 8a7179167c
commit c5bcb4c021
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 52 additions and 47 deletions

View file

@ -14,19 +14,19 @@ module Admin
contrived_name: chat_channel_params[:channel_name],
membership_role: "mod",
)
redirect_back(fallback_location: "/admin/chat_channels")
redirect_back(fallback_location: admin_chat_channels_path)
end
def update
@chat_channel = ChatChannel.find(params[:id])
@chat_channel.invite_users(users: users_by_param)
redirect_back(fallback_location: "/admin/chat_channels")
redirect_back(fallback_location: admin_chat_channels_path)
end
def remove_user
@chat_channel = ChatChannel.find(params[:id])
@chat_channel.remove_user(user_by_param)
redirect_back(fallback_location: "/admin/chat_channels")
redirect_back(fallback_location: admin_chat_channels_path)
end
def destroy
@ -37,7 +37,7 @@ module Admin
else
flash[:alert] = "Channel NOT deleted, because it still has users."
end
redirect_back(fallback_location: "/admin/chat_channels")
redirect_back(fallback_location: admin_chat_channels_path)
end
private

View file

@ -107,7 +107,7 @@ module Admin
<<~HEREDOC
*New note from #{params['author_name']}:*
*Report status: #{params['feedback_message_status']}*
Report page: https://#{SiteConfig.app_domain}/admin/reports/#{params['noteable_id']}
Report page: admin_report_url(params['noteable_id'])
--------
Message: #{params['content']}
HEREDOC

View file

@ -37,7 +37,7 @@ module Admin
@user = User.find(params[:id])
Credits::Manage.call(@user, user_params)
add_note if user_params[:new_note]
redirect_to "/admin/users/#{params[:id]}"
redirect_to admin_user_path(params[:id])
end
def destroy
@ -66,7 +66,7 @@ module Admin
rescue StandardError => e
flash[:danger] = e.message
end
redirect_to "/admin/users/#{@user.id}/edit"
redirect_to edit_admin_user_path(@user.id)
end
def export_data
@ -87,7 +87,7 @@ module Admin
def banish
Moderator::BanishUserWorker.perform_async(current_user.id, params[:id].to_i)
flash[:success] = "This user is being banished in the background. The job will complete soon."
redirect_to "/admin/users/#{params[:id]}/edit"
redirect_to edit_admin_user_path(params[:id])
end
def full_delete
@ -103,7 +103,7 @@ module Admin
rescue StandardError => e
flash[:danger] = e.message
end
redirect_to "/admin/users"
redirect_to admin_users_path
end
def merge
@ -114,7 +114,7 @@ module Admin
flash[:danger] = e.message
end
redirect_to "/admin/users/#{@user.id}/edit"
redirect_to edit_admin_user_path(@user.id)
end
def remove_identity
@ -135,7 +135,7 @@ module Admin
rescue StandardError => e
flash[:danger] = e.message
end
redirect_to "/admin/users/#{@user.id}/edit"
redirect_to edit_admin_user_path(@user.id)
end
def send_email

View file

@ -255,12 +255,12 @@ class StoriesController < ApplicationController
end
def redirect_if_view_param
redirect_to "/admin/users/#{@user.id}" if params[:view] == "moderate"
redirect_to "/admin/users/#{@user.id}/edit" if params[:view] == "admin"
redirect_to admin_user_path(@user.id) if params[:view] == "moderate"
redirect_to edit_admin_user_path(@user.id) if params[:view] == "admin"
end
def redirect_if_show_view_param
redirect_to "/admin/articles/#{@article.id}" if params[:view] == "moderate"
redirect_to admin_article_path(@article.id) if params[:view] == "moderate"
end
def handle_article_show

View file

@ -31,7 +31,7 @@ class TagsController < ApplicationController
def admin
tag = Tag.find_by!(name: params[:tag])
authorize tag
redirect_to "/admin/tags/#{tag.id}/edit"
redirect_to edit_admin_tag_path(tag.id)
end
def onboarding

View file

@ -13,7 +13,7 @@ describe('DataUpdateScriptController', () => {
beforeEach(() => {
document.body.innerHTML = `
<div data-controller="data-update-script">
<div data-controller="data-update-script" data-data-update-script-url-value="admin/advanced/data_update_scripts">
<div class="alert alert-danger hidden data-update-script__alert">
<div id="data-update-script__error"></div>
</div>
@ -23,7 +23,7 @@ describe('DataUpdateScriptController', () => {
<td id="data_update_script_1">1</td>
<td class="data_update_script__filename" data-filename="Some filename" id="data_update_script_1_filename">
Some filename
<button id="data_update_script_1_button" data-action="click->data-update-script#forceRun" data-value="1" type="button">
<button id="data_update_script_1_button" data-action="click->data-update-script#forceRun" data-value="1" data-force-run-path="/admin/advanced/data_update_scripts/1/force_run" type="button">
Re-run
</button>
</td>

View file

@ -1,6 +1,8 @@
import { Controller } from 'stimulus';
export default class DataUpdateScriptController extends Controller {
static values = { url: String };
forceRun(event) {
event.preventDefault();
const id = event.target.dataset.value;
@ -21,7 +23,7 @@ export default class DataUpdateScriptController extends Controller {
}
forceRunScript(id, statusColumn, runAtColumn) {
fetch(`/admin/data_update_scripts/${id}/force_run`, {
fetch(`${this.urlValue}/${id}/force_run`, {
method: 'POST',
headers: {
'X-CSRF-Token': document.querySelector("meta[name='csrf-token']")
@ -104,7 +106,7 @@ export default class DataUpdateScriptController extends Controller {
}
checkForUpdatedDataScript(id, runAtColumn, statusColumn) {
return fetch(`/admin/data_update_scripts/${id}`, {
return fetch(`${this.urlValue}/${id}`, {
method: 'GET',
headers: {
'X-CSRF-Token': document.querySelector("meta[name='csrf-token']")

View file

@ -1,4 +1,4 @@
<div data-controller="data-update-script" class="crayons-card p-6 grid gap-6">
<div data-controller="data-update-script" data-data-update-script-url-value="<%= admin_data_update_scripts_path %>" class="crayons-card p-6 grid gap-6">
<div class="alert hidden data-update-script__alert">
<div id="data-update-script__error"></div>
</div>
@ -19,10 +19,12 @@
<td data-filename="<%= script.file_name %>" id="data_update_script_<%= script.id %>_filename" class="data_update_script__filename">
<%= script.file_name %>
<% if script.status == "failed" %>
<button class="ml-2" id="data_update_script_<%= script.id %>_button"
data-action="click->data-update-script#forceRun" data-value="<%= script.id %>" type="button" className="crayons-btn crayons-btn--secondary">
Re-run
</button>
<button type="button"
class="crayons-btn crayons-btn--s crayons-btn--secondary"
id="data_update_script_<%= script.id %>_button"
data-action="click->data-update-script#forceRun"
data-value="<%= script.id %>"
Re-run>
<% end %>
</td>
<td><%= script.created_at %></td>

View file

@ -11,7 +11,7 @@
</a>
<div class="float-right">
✉️ Emails Sent: <%= feedback_message_emails.size %> |
<a href="/admin/reports/<%= feedback_message.id %>">Link to Report #<%= feedback_message.id %></a>
<%= link_to "Link to Report #{feedback_message.id}", admin_report_path(feedback_message.id) %>
</div>
</div>
<div id="collapse<%= feedback_message.id %>" class="collapse show" aria-labelledby="header<%= feedback_message.id %>" data-parent="#accordion-<%= feedback_message.id %>">
@ -145,7 +145,7 @@
<%= text_area_tag :affected_email_body, affected_email_details[:body], class: "form-control my-1", style: "height: 300px;", id: "affected__body__#{feedback_message.id}" %>
</div>
</div>
<button class="btn btn-primary" type="button" id="send__email__btn__<%= feedback_message.id %>">Send Email ✉️</button>
<button class="btn btn-primary" type="button" id="send__email__btn__<%= feedback_message.id %>" data-path="<%= send_email_admin_reports_path %>">Send Email ✉️</button>
</div>
</div>
<div class="email__alert alert w-100 mt-2 d-none" id="email__alert__<%= feedback_message.id %>">
@ -154,7 +154,7 @@
<div class="col-12">
<h3>Status:</h3>
<%= f.select :status, %w[Open Invalid Resolved], {}, id: "status__#{feedback_message.id}" %>
<button class="btn btn-primary d-block mt-3" type="button" id="save__status__<%= feedback_message.id %>">Save Status</button>
<button class="btn btn-primary d-block mt-3" type="button" id="save__status__<%= feedback_message.id %>" data-path="<%= save_status_admin_reports_path %>">Save Status</button>
</div>
</div>
<div class="row my-3">
@ -187,7 +187,7 @@
class="notefield"
id="note__content__<%= feedback_message.id %>"
required>
<button class="btn btn-primary" type="button" id="note__submit__<%= feedback_message.id %>">Submit Note 📝</button>
<button class="btn btn-primary" type="button" id="note__submit__<%= feedback_message.id %>" data-path="<%= create_note_admin_reports_path %>">Submit Note 📝</button>
</div>
</div>
</div>
@ -210,7 +210,7 @@
formData.append('id', id);
formData.append('status', statusSelectTag.options[statusSelectTag.selectedIndex].value);
fetch('/admin/reports/save_status', {
fetch(statusBtn.dataset.path, {
method: 'POST',
headers: {
'X-CSRF-Token': document.querySelector("meta[name='csrf-token']").content,
@ -277,7 +277,7 @@
formData.append('email_subject', subjectLine);
formData.append('email_type', userType);
fetch('/admin/reports/send_email', {
fetch(sendEmailBtn.dataset.path, {
method: 'POST',
headers: {
'X-CSRF-Token': document.querySelector("meta[name='csrf-token']").content,
@ -338,6 +338,8 @@
}
function submitNote(id) {
var submitNoteBtn = document.getElementById('note__submit__<%= feedback_message.id %>');
var formData = new FormData();
formData.append('content', document.getElementById('note__content__' + id).value)
formData.append('reason', document.getElementById('note__reason__' + id).value)
@ -345,7 +347,7 @@
formData.append('noteable_type', document.getElementById('note__noteable-type__' + id).value)
formData.append('author_id', document.getElementById('note__author-id__' + id).value)
fetch('/admin/reports/create_note', {
fetch(submitNoteBtn.dataset.path, {
method: 'POST',
headers: {
'X-CSRF-Token': document.querySelector("meta[name='csrf-token']").content,

View file

@ -17,8 +17,8 @@
<a href="<%= article.path %>/mod" class="btn btn-secondary btn-sm">Mod</a>
<a href="<%= article.path %>/moderate" class="btn btn-secondary btn-sm">admin</a>
<a href="<%= article.user.path %>" class="btn btn-secondary btn-sm">Profile</a>
<a href="/admin/users/<%= article.user_id %>" class="btn btn-secondary btn-sm">admin User</a>
<a href="/admin/users/<%= article.user_id %>/edit" class="btn btn-danger btn-sm">Destructive Actions</a>
<%= link_to "admin User", admin_user_path(article.user_id), class: "btn btn-secondary btn-sm" %>
<%= link_to "Destructive Actions", edit_admin_user_path(article.user_id), class: "btn btn-danger btn-sm" %>
</div>
</div>
<% end %>

View file

@ -12,8 +12,8 @@
<div class="py-2 flex">
<a href="<%= user.path %>">@<%= user.username %></a> - <%= user.name %>
<div class="ml-auto shrink-0">
<a href="/admin/users/<%= user.id %>" class="btn btn-secondary btn-sm">admin User</a>
<a href="/admin/users/<%= user.id %>/edit" class="btn btn-danger btn-sm">Destructive Actions</a>
<%= link_to "admin User", admin_user_path(user.id), class: "btn btn-secondary btn-sm" %>
<%= link_to "Destructive Actions", edit_admin_user_path(user.id), class: "btn btn-danger btn-sm" %>
</div>
</div>
<% end %>

View file

@ -9,8 +9,7 @@
<p class="crayons-subtitle-4 color-base-70 mb-3">Here are a few things we recommend doing now that you're using Forem!</p>
<ol>
<li class="mb-1 -ml-4">Set up and configure your Forem under <%= link_to "Config", admin_config_path, 'data-action': "click->ahoy#trackOverviewLink" %></li>
<li class="mb-1 -ml-4"><a href="/admin/invitations" data-action="click->ahoy#trackOverviewLink">Invite people</a> to join your Forem</li>
<li class="mb-1 -ml-4"><%= link_to "Invite people", admin_invitations_path, 'data-action': "click->ahoy#trackOverviewLink" %> to join your Forem</li>
<li class="mb-1 -ml-4"><%= link_to "Update your Forem tags", admin_tags_path, 'data-action': "click->ahoy#trackOverviewLink" %></li>
<li class="mb-1 -ml-4"><%= link_to "Create pages", admin_pages_path, 'data-action': "click->ahoy#trackOverviewLink" %> and <%= link_to "sort them in the navigation sidebar", admin_navigation_links_path, 'data-action': "click->ahoy#trackOverviewLink" %></li>
<li class="mb-1 -ml-4">Read the <a href="https://forem.gitbook.io/forem-admin-guide/quick-start-guide" data-action="click->ahoy#trackOverviewLink">Quick Start Guide</a></li>

View file

@ -1,4 +1,4 @@
<%= form_tag("/admin/podcasts", method: "get", class: "mb-6") do %>
<%= form_tag(admin_podcasts_path, method: "get", class: "mb-6") do %>
<div class="form-group">
<%= text_field_tag(:search, params[:search], aria: { label: "Search" }) %>
<%= submit_tag("Search") %>

View file

@ -69,7 +69,7 @@
id="tag-admin-button"
data-tag="<%= @tag_model.name %>"
class="crayons-btn crayons-btn--outlined mod-action-button fs-s"
href="/admin/tags/<%= @tag_model.id %>/edit"
href="<%= edit_admin_tag_path(@tag_model.id) %>"
style="color:<%= @tag_model.text_color_hex %>;background-color:<%= @tag_model.bg_color_hex %>"
data-no-instant>
Admin

View file

@ -34,7 +34,7 @@
<%= render "layouts/logo" %>
<h1 class="pl-4 fs-l">
<a href="/admin">Admin</a>
<a href="<%= admin_path %>">Admin</a>
<span class="color-base-60">&raquo;</span> <span class="fw-bold"><%= controller_name.titleize %></span>
</h1>
@ -56,7 +56,7 @@
<% if FeatureFlag.enabled?(:admin_restructure) %>
<ul>
<li>
<a class="crayons-link crayons-link--block <%= "crayons-link--current" if controller.controller_name == "overview" %>" href="/admin/" aria-page="<%= "page" if controller.controller_name == "overview" %>">
<a class="crayons-link crayons-link--block <%= "crayons-link--current" if controller.controller_name == "overview" %>" href="<%= admin_path %>" aria-page="<%= "page" if controller.controller_name == "overview" %>">
<%= inline_svg_tag("stack-line.svg", aria: true, class: "dropdown-icon crayons-icon") %>
Overview
</a>
@ -64,7 +64,7 @@
<%= render "admin/shared/nested_sidebar", menu_items: AdminMenu.navigation_items %>
</ul>
<% else %>
<a class="crayons-link crayons-link--block <%= "crayons-link--current" if controller.controller_name == "overview" %>" href="/admin/">
<a class="crayons-link crayons-link--block <%= "crayons-link--current" if controller.controller_name == "overview" %>" href="<%= admin_path %>">
Overview
</a>
<%= render "admin/shared/navbar", menu_items: admin_menu_items %>

View file

@ -72,10 +72,10 @@
<% if current_user.has_role?(:super_admin) && @moderatable.class.name == "Article" %>
<h3> <a href="<%= @moderatable.path %>/edit">Edit Post</a> |
<a href="/resource_admin/articles/<%= @moderatable.id %>" data-no-instant>ResourceAdmin:Article</a> |
<a href="/admin/articles/<%= @moderatable.id %>" data-no-instant>Admin:Article</a></h3>
<a href="<%= admin_article_path(@moderatable.id) %>" data-no-instant>Admin:Article</a></h3>
<% elsif current_user.has_role?(:super_admin) && @moderatable.class.name == "Comment" %>
<h3> <a href="/admin/comments/<%= @moderatable.id %>" data-no-instant>Admin:Comment</a> |
<a href="/admin/users/<%= @moderatable.user_id %>" data-no-instant>Admin:User</a></h3>
<a href="<%= admin_user_path(@moderatable.user_id) %>" data-no-instant>Admin:User</a></h3>
<% end %>
<p>
<b style="font-size:1em">All negative reactions are private.</b>

View file

@ -4,6 +4,6 @@
<div class="crayons-card text-styles text-padding">
<h1 class="fs-3xl s:fs-4xl l:fs-5xl fw-bold s:fw-heavy lh-tight mb-4 mt-0"><%= title %></h1>
<p>The production <%= title %> page is a page generated at <a href="/admin/pages">/admin/pages</a>! This one is just a placeholder.</p>
<p>The production <%= title %> page is a page generated at <a href="<%= admin_pages_path %>"><%= admin_pages_path %></a>! This one is just a placeholder.</p>
</div>
</div>

View file

@ -6,7 +6,7 @@
Create an account. It will be the first super admin account.
</p>
<p class="mb-4">
Once you sign up below, you can configure your community at <a href="/admin/config">admin/config</a>.
Once you sign up below, you can configure your community at <a href="<%= admin_config_path %>"><%= admin_config_path %></a>.
</p>
<p class="mb-4">
There is lots you can do as an admin, but there is a learning curve.

View file

@ -84,7 +84,7 @@
<% if current_user.has_role?(:super_admin) || current_user.has_role?(:admin) %>
<center>
<h1><a href="/admin/tags/<%= @tag.id %>/edit" data-no-instant><%= @tag.name %>'s admin page</a></h1>
<h1><a href="<%= edit_admin_tag_path(@tag.id) %>" data-no-instant><%= @tag.name %>'s admin page</a></h1>
<br />
<br />
<br />