From c5bcb4c021504cdf8cfca186558bc0ce5b5061b4 Mon Sep 17 00:00:00 2001 From: Ridhwana Date: Mon, 26 Apr 2021 17:49:54 +0200 Subject: [PATCH] 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 --- .../admin/chat_channels_controller.rb | 8 ++++---- .../admin/feedback_messages_controller.rb | 2 +- app/controllers/admin/users_controller.rb | 12 ++++++------ app/controllers/stories_controller.rb | 6 +++--- app/controllers/tags_controller.rb | 2 +- .../data_update_script_controller.test.js | 4 ++-- .../controllers/data_update_script_controller.js | 6 ++++-- .../admin/data_update_scripts/index.html.erb | 12 +++++++----- .../feedback_messages/_feedback_message.html.erb | 16 +++++++++------- .../feedback_messages/_latest_articles.html.erb | 4 ++-- .../_potential_spam_users.html.erb | 4 ++-- app/views/admin/overview/index.html.erb | 3 +-- app/views/admin/podcasts/index.html.erb | 2 +- app/views/articles/tags/_sidebar.html.erb | 2 +- app/views/layouts/admin.html.erb | 6 +++--- app/views/moderations/mod.html.erb | 4 ++-- app/views/pages/_placeholder.html.erb | 2 +- .../_initial_account_wizard.html.erb | 2 +- app/views/tags/edit.html.erb | 2 +- 19 files changed, 52 insertions(+), 47 deletions(-) diff --git a/app/controllers/admin/chat_channels_controller.rb b/app/controllers/admin/chat_channels_controller.rb index 0afac8140..69e86699b 100644 --- a/app/controllers/admin/chat_channels_controller.rb +++ b/app/controllers/admin/chat_channels_controller.rb @@ -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 diff --git a/app/controllers/admin/feedback_messages_controller.rb b/app/controllers/admin/feedback_messages_controller.rb index 3d2ac6ca2..16e6917d8 100644 --- a/app/controllers/admin/feedback_messages_controller.rb +++ b/app/controllers/admin/feedback_messages_controller.rb @@ -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 diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index db226e920..b36c2d6a9 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -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 diff --git a/app/controllers/stories_controller.rb b/app/controllers/stories_controller.rb index 07d2f1a13..e024fb60c 100644 --- a/app/controllers/stories_controller.rb +++ b/app/controllers/stories_controller.rb @@ -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 diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index e95c8dd09..d8ad083a5 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -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 diff --git a/app/javascript/admin/__tests__/controllers/data_update_script_controller.test.js b/app/javascript/admin/__tests__/controllers/data_update_script_controller.test.js index f4577d8d1..3efb3dfe9 100644 --- a/app/javascript/admin/__tests__/controllers/data_update_script_controller.test.js +++ b/app/javascript/admin/__tests__/controllers/data_update_script_controller.test.js @@ -13,7 +13,7 @@ describe('DataUpdateScriptController', () => { beforeEach(() => { document.body.innerHTML = ` -
+
@@ -23,7 +23,7 @@ describe('DataUpdateScriptController', () => { 1 Some filename - diff --git a/app/javascript/admin/controllers/data_update_script_controller.js b/app/javascript/admin/controllers/data_update_script_controller.js index 5ff00f885..7fab7e865 100644 --- a/app/javascript/admin/controllers/data_update_script_controller.js +++ b/app/javascript/admin/controllers/data_update_script_controller.js @@ -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']") diff --git a/app/views/admin/data_update_scripts/index.html.erb b/app/views/admin/data_update_scripts/index.html.erb index fd8310500..46372d311 100644 --- a/app/views/admin/data_update_scripts/index.html.erb +++ b/app/views/admin/data_update_scripts/index.html.erb @@ -1,4 +1,4 @@ -
+
@@ -19,10 +19,12 @@ <%= script.file_name %> <% if script.status == "failed" %> - +
@@ -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}" %>
- +
@@ -154,7 +154,7 @@

Status:

<%= f.select :status, %w[Open Invalid Resolved], {}, id: "status__#{feedback_message.id}" %> - +
@@ -187,7 +187,7 @@ class="notefield" id="note__content__<%= feedback_message.id %>" required> - +
@@ -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, diff --git a/app/views/admin/feedback_messages/_latest_articles.html.erb b/app/views/admin/feedback_messages/_latest_articles.html.erb index e0b2fa587..ae57a499b 100644 --- a/app/views/admin/feedback_messages/_latest_articles.html.erb +++ b/app/views/admin/feedback_messages/_latest_articles.html.erb @@ -17,8 +17,8 @@ Mod admin Profile - admin User - Destructive Actions + <%= 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" %> <% end %> diff --git a/app/views/admin/feedback_messages/_potential_spam_users.html.erb b/app/views/admin/feedback_messages/_potential_spam_users.html.erb index f598fd96d..3530e7d3a 100644 --- a/app/views/admin/feedback_messages/_potential_spam_users.html.erb +++ b/app/views/admin/feedback_messages/_potential_spam_users.html.erb @@ -12,8 +12,8 @@
@<%= user.username %> - <%= user.name %>
- admin User - Destructive Actions + <%= 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" %>
<% end %> diff --git a/app/views/admin/overview/index.html.erb b/app/views/admin/overview/index.html.erb index 0f674c937..d782612cf 100644 --- a/app/views/admin/overview/index.html.erb +++ b/app/views/admin/overview/index.html.erb @@ -9,8 +9,7 @@

Here are a few things we recommend doing now that you're using Forem!

  1. Set up and configure your Forem under <%= link_to "Config", admin_config_path, 'data-action': "click->ahoy#trackOverviewLink" %>
  2. -
  3. Invite people to join your Forem
  4. - +
  5. <%= link_to "Invite people", admin_invitations_path, 'data-action': "click->ahoy#trackOverviewLink" %> to join your Forem
  6. <%= link_to "Update your Forem tags", admin_tags_path, 'data-action': "click->ahoy#trackOverviewLink" %>
  7. <%= 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" %>
  8. Read the Quick Start Guide
  9. diff --git a/app/views/admin/podcasts/index.html.erb b/app/views/admin/podcasts/index.html.erb index 855772751..ba951a940 100644 --- a/app/views/admin/podcasts/index.html.erb +++ b/app/views/admin/podcasts/index.html.erb @@ -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 %>
    <%= text_field_tag(:search, params[:search], aria: { label: "Search" }) %> <%= submit_tag("Search") %> diff --git a/app/views/articles/tags/_sidebar.html.erb b/app/views/articles/tags/_sidebar.html.erb index 3eb4fa994..3c749cad8 100644 --- a/app/views/articles/tags/_sidebar.html.erb +++ b/app/views/articles/tags/_sidebar.html.erb @@ -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 diff --git a/app/views/layouts/admin.html.erb b/app/views/layouts/admin.html.erb index 7618bd80f..c1f04b529 100644 --- a/app/views/layouts/admin.html.erb +++ b/app/views/layouts/admin.html.erb @@ -34,7 +34,7 @@ <%= render "layouts/logo" %>

    - Admin + Admin » <%= controller_name.titleize %>

    @@ -56,7 +56,7 @@ <% if FeatureFlag.enabled?(:admin_restructure) %> <% else %> - " href="/admin/"> + " href="<%= admin_path %>"> Overview <%= render "admin/shared/navbar", menu_items: admin_menu_items %> diff --git a/app/views/moderations/mod.html.erb b/app/views/moderations/mod.html.erb index c2b990395..b174bdb05 100644 --- a/app/views/moderations/mod.html.erb +++ b/app/views/moderations/mod.html.erb @@ -72,10 +72,10 @@ <% if current_user.has_role?(:super_admin) && @moderatable.class.name == "Article" %>

    Edit Post | ResourceAdmin:Article | - Admin:Article

    + Admin:Article <% elsif current_user.has_role?(:super_admin) && @moderatable.class.name == "Comment" %>

    Admin:Comment | - Admin:User

    + Admin:User <% end %>

    All negative reactions are private. diff --git a/app/views/pages/_placeholder.html.erb b/app/views/pages/_placeholder.html.erb index 13154d592..c016f4edd 100644 --- a/app/views/pages/_placeholder.html.erb +++ b/app/views/pages/_placeholder.html.erb @@ -4,6 +4,6 @@

    <%= title %>

    -

    The production <%= title %> page is a page generated at /admin/pages! This one is just a placeholder.

    +

    The production <%= title %> page is a page generated at <%= admin_pages_path %>! This one is just a placeholder.

    diff --git a/app/views/shared/authentication/_initial_account_wizard.html.erb b/app/views/shared/authentication/_initial_account_wizard.html.erb index 2cd90b0e0..a0cc80333 100644 --- a/app/views/shared/authentication/_initial_account_wizard.html.erb +++ b/app/views/shared/authentication/_initial_account_wizard.html.erb @@ -6,7 +6,7 @@ Create an account. It will be the first super admin account.

    - Once you sign up below, you can configure your community at admin/config. + Once you sign up below, you can configure your community at <%= admin_config_path %>.

    There is lots you can do as an admin, but there is a learning curve. diff --git a/app/views/tags/edit.html.erb b/app/views/tags/edit.html.erb index 6e34cd4d6..514c6984f 100644 --- a/app/views/tags/edit.html.erb +++ b/app/views/tags/edit.html.erb @@ -84,7 +84,7 @@ <% if current_user.has_role?(:super_admin) || current_user.has_role?(:admin) %>

    -

    <%= @tag.name %>'s admin page

    +

    <%= @tag.name %>'s admin page