Skip to content

Commit

Permalink
Fix Admin panel routes
Browse files Browse the repository at this point in the history
Update calls to the routes to use _mount point_ - that way we can avoid the errors when engine is used in mixed setup with host application. And some parts of the Admin panel is overridden.

Also disable Sprocket concurency (see rails/sprockets#581)
  • Loading branch information
paranoicsan committed Dec 1, 2021
1 parent a5422d0 commit 3c6fd4a
Show file tree
Hide file tree
Showing 33 changed files with 85 additions and 67 deletions.
11 changes: 8 additions & 3 deletions app/controllers/lcms/engine/admin/access_codes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@ class AccessCodesController < AdminController
def create
@access_code = AccessCode.new(permitted_params)
if @access_code.save
redirect_to({ action: :index }, notice: t('.success'))
redirect_to lcms_engine.admin_access_codes_path, notice: t('.success')
else
render :new
end
end

def destroy
@access_code.destroy
redirect_to({ action: :index }, notice: t('.success'))
redirect_to lcms_engine.admin_access_codes_path, notice: t('.success')
end

def edit
@url = lcms_engine.admin_access_code_path(@access_code)
end

def index
Expand All @@ -30,8 +34,9 @@ def new

def update
if @access_code.update(permitted_params)
redirect_to({ action: :index }, notice: t('.success'))
redirect_to lcms_engine.admin_access_codes_path, notice: t('.success')
else
@url = lcms_engine.admin_access_code_path(@access_code)
render :edit
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def edit
def update
@form = CurriculumForm.new(params[:curriculum])
if @form.save
redirect_to admin_path, notice: t('.success')
redirect_to lcms_engine.root_path, notice: t('.success')
else
@curriculum = CurriculumPresenter.new
render :edit, alert: t('.error')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ def new
if @resources.any?
@resource = BulkEditResourcesService.new(@resources).init_sample
else
redirect_to :admin_resources, alert: t('.no_resources')
redirect_to lcms_engine.admin_resources_path, alert: t('.no_resources')
end
end

def create
BulkEditResourcesService.new(@resources, resource_params).edit!
resources_count_msg = t(:resources_count, count: @resources.count)
notice = t('.success', count: @resources.count, resources_count: resources_count_msg)
redirect_to :admin_resources, notice: notice
redirect_to lcms_engine.admin_resources_path, notice: notice
end

private
Expand Down
12 changes: 6 additions & 6 deletions app/controllers/lcms/engine/admin/resources_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def create

if @resource.save
create_tags
redirect_to :admin_resources, notice: t('.success', resource_id: @resource.id)
redirect_to lcms_engine.admin_resources_path, notice: t('.success', resource_id: @resource.id)
else
render :new
end
Expand All @@ -50,17 +50,17 @@ def export_to_lti_cc
end

def bundle
return redirect_to :admin_resources, notice: t('.fail') unless can_bundle?(@resource)
return redirect_to lcms_engine.admin_resources_path, notice: t('.fail') unless can_bundle?(@resource)

# see settings loaded via `lcms.yml`
generator = DocTemplate.config.dig('bundles', @resource.curriculum_type).constantize
generator.perform(@resource)
redirect_to :admin_resources, notice: t('.success')
redirect_to lcms_engine.admin_resources_path, notice: t('.success')
end

def update
unless Settings[:editing_enabled]
return redirect_to(:admin_resources, alert: t('admin.common.editing_disabled'))
return redirect_to(lcms_engine.admin_resources_path, alert: t('admin.common.editing_disabled'))
end

create_tags
Expand All @@ -70,15 +70,15 @@ def update
end

if @resource.update(resource_params)
redirect_to :admin_resources, notice: t('.success', resource_id: @resource.id)
redirect_to lcms_engine.admin_resources_path, notice: t('.success', resource_id: @resource.id)
else
render :edit
end
end

def destroy
@resource.destroy
redirect_to :admin_resources, notice: t('.success', resource_id: @resource.id)
redirect_to lcms_engine.admin_resources_path, notice: t('.success', resource_id: @resource.id)
end

protected
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/lcms/engine/admin/settings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class SettingsController < AdminController
def toggle_editing_enabled
Settings[:editing_enabled] = !Settings[:editing_enabled]
notice = Settings[:editing_enabled] ? t('.enabled') : t('.disabled')
redirect_to :admin_resources, notice: notice
redirect_to lcms_engine.admin_resources_path, notice: notice
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/lcms/engine/admin/standards_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def index

def update
if @standard.update(standard_params)
redirect_to admin_standards_path, notice: t('.success')
redirect_to lcms_engine.admin_standards_path, notice: t('.success')
else
render :edit
end
Expand Down
13 changes: 8 additions & 5 deletions app/controllers/lcms/engine/admin/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,33 @@ def create
@user.generate_password
if @user.save
@user.send_reset_password_instructions
redirect_to(:admin_users, notice: t('.success', user: @user.email))
redirect_to lcms_engine.admin_users_path, notice: t('.success', user: @user.email)
else
render :new
end
end

def edit; end
def edit
@url = lcms_engine.admin_user_path(@user)
end

def update
if @user.update(user_params)
redirect_to edit_admin_user_path(@user), notice: t('.success', user: @user.email)
redirect_to lcms_engine.admin_users_path, notice: t('.success', user: @user.email)
else
@url = lcms_engine.admin_user_path(@user)
render :edit
end
end

def destroy
@user.destroy
redirect_to :admin_users, notice: t('.success')
redirect_to lcms_engine.admin_users_path, notice: t('.success')
end

def reset_password
@user.send_reset_password_instructions
redirect_to :admin_users, notice: t('.success')
redirect_to lcms_engine.admin_users_path, notice: t('.success')
end

private
Expand Down
10 changes: 5 additions & 5 deletions app/controllers/lcms/engine/resources_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ def show
@resource = find_resource

# redirect to document if resource has it (#161)
return redirect_to document_path(@resource.document) if @resource.document?
return redirect_to dynamic_document_path(@resource.document) if @resource.document?

# redirect grade and module to explore_curriculum (#122)
return redirect_to explore_curriculum_index_path(p: @resource.slug, e: 1) if grade_or_module?
return redirect_to lcms_engine.explore_curriculum_index_path(p: @resource.slug, e: 1) if grade_or_module?

# redirect to the path with slug if we are using just the id
return redirect_to show_with_slug_path(@resource.slug), status: 301 if using_id?
return redirect_to lcms_engine.show_with_slug_path(@resource.slug), status: 301 if using_id?

@related_instructions = related_instructions
@props = CurriculumMap.new(@resource).props
Expand All @@ -27,14 +27,14 @@ def related_instruction

def media
resource = Resource.find(params[:id])
return redirect_to resource_path(resource) unless resource.media?
return redirect_to lcms_engine.resource_path(resource) unless resource.media?

@resource = MediaPresenter.new(resource)
end

def generic
resource = Resource.find(params[:id])
return redirect_to resource_path(resource) unless resource.generic?
return redirect_to lcms_engine.resource_path(resource) unless resource.generic?

@resource = GenericPresenter.new(resource)
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/lcms/engine/admin/access_codes/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= simple_form_for [:admin, @access_code], html: { id: 'access_code_form' } do |f| %>
<%= simple_form_for @access_code, url: @url.presence || lcms_engine.admin_access_codes_path, html: { id: 'access_code_form' } do |f| %>
<%= f.input :code %>
<%= f.input :active %>
<%= f.button :submit, t('ui.save'), name: nil %>
Expand Down
6 changes: 3 additions & 3 deletions app/views/lcms/engine/admin/access_codes/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class=o-page>
<div class=clearfix>
<div class=pull-right>
<%= link_to t('.new_access_code'), :new_admin_access_code, class: 'button success', 'data-turbolinks' => false %>
<%= link_to t('.new_access_code'), lcms_engine.new_admin_access_code_path, class: 'button success', 'data-turbolinks' => false %>
</div>
</div>

Expand All @@ -19,10 +19,10 @@
<% @access_codes.each do |access_code| %>
<% cache access_code do %>
<tr id="access_code_<%= access_code.id %>">
<td><%= link_to access_code.code, edit_admin_access_code_path(access_code) %>
<td><%= link_to access_code.code, lcms_engine.edit_admin_access_code_path(access_code) %>
<td><%= access_code.active ? 'YES' : 'NO' %>
<td>
<%= button_to t('ui.delete'), admin_access_code_path(access_code), class: 'button alert', data: { confirm: t('ui.are_you_sure') }, form_class: 'inline', method: :delete %>
<%= button_to t('ui.delete'), lcms_engine.admin_access_code_path(access_code), class: 'button alert', data: { confirm: t('ui.are_you_sure') }, form_class: 'inline', method: :delete %>
</td>
</tr>
<% end %>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= simple_form_for :query, url: :admin_batch_reimport, html: { class: 'form-inline well o-admin-lessons-search', method: :post } do |f| %>
<%= simple_form_for :query, url: lcms_engine.admin_batch_reimport_path, html: { class: 'form-inline well o-admin-lessons-search', method: :post } do |f| %>

<div class="row align-bottom align-justify">
<button class="button o-admin-search-subject float-right" type="button" data-toggle="subject">Select Subject</button>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= simple_form_for :query, url: :admin_documents, html: { class: 'form-inline well o-admin-lessons-search', method: :get } do |f| %>
<%= simple_form_for :query, url: lcms_engine.admin_documents_path, html: { class: 'form-inline well o-admin-lessons-search', method: :get } do |f| %>

<div class='row align-bottom align-justify'>
<button class="button o-admin-search-subject float-right" type="button" data-toggle="lesson-subject">Select Subject</button>
Expand Down
2 changes: 1 addition & 1 deletion app/views/lcms/engine/admin/documents/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
path: delete_selected_admin_documents_path(query: @query_params),
btn_style: 'alert'} %>

<%= link_to t('.new_lesson'), :new_admin_document, class: 'button primary' %>
<%= link_to t('.new_lesson'), lcms_engine.new_admin_document_path, class: 'button primary' %>
</div>
<table class="lessons-table table">
<tr>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= simple_form_for :query, url: :admin_materials, html: { class: 'form-inline well o-admin-lessons-search', method: :get } do |f| %>
<%= simple_form_for :query, url: lcms_engine.admin_materials_path, html: { class: 'form-inline well o-admin-lessons-search', method: :get } do |f| %>

<div class="row align-bottom align-justify">
<%= f.input :search_term, label: 'Identifier', required: false,
Expand Down
2 changes: 1 addition & 1 deletion app/views/lcms/engine/admin/materials/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
path: delete_selected_admin_materials_path(query: @query_params),
btn_style: 'alert'} %>
<%# link_to t('.new_material_pdf'), new_admin_material_path(source_type: 'pdf'), class: 'button primary' %>
<%= link_to t('.new_material'), :new_admin_material, class: 'button primary' %>
<%= link_to t('.new_material'), lcms_engine.new_admin_material_path, class: 'button primary' %>
</div>
<div class="materials-table materials-table__wrapper">
<table class="table u-text--centered">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class=o-page>
<h2 class=text-center><%= t('.page_title') %></h2>

<%= simple_form_for @resource, url: :admin_resource_bulk_edits do |f| %>
<%= simple_form_for @resource, url: lcms_engine.admin_resource_bulk_edits_path do |f| %>

<% @resources.each do |resource| %>
<%= hidden_field_tag 'ids[]', resource.id %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/lcms/engine/admin/resources/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<% url = @resource.new_record? ? :admin_resources : admin_resource_path(@resource) %>
<% url = @resource.new_record? ? lcms_engine.admin_resources_path : lcms_engine.admin_resource_path(@resource) %>

<%= simple_nested_form_for @resource, url: url, html: { id: 'resource_form' } do |f| %>
<div class="large-10 columns">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= simple_form_for @query, url: :admin_resources, html: { class: 'form-inline well admin-resource-search', method: :get } do |f| %>
<%= simple_form_for @query, url: lcms_engine.admin_resources_path, html: { class: 'form-inline well admin-resource-search', method: :get } do |f| %>

<div class='row align-justify'>
<%= f.input :grades, as: :select, collection: Lcms::Engine::Grades.grades, input_html: { class: 'selectize resource-search-select', multiple: true }, label: t('.grades'), label_method: :humanize, required: false, wrapper_html: { class: 'resource-search-wrap' } %>
Expand Down
24 changes: 12 additions & 12 deletions app/views/lcms/engine/admin/shared/_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,36 @@
<div class="o-top-bar__item c-header__menu">
<ul class="dropdown menu" data-dropdown-menu>
<li class="c-header__link">
<%= link_to t('lcms.engine.admin.nav.curriculum'), edit_admin_curriculum_path %>
<%= link_to t('lcms.engine.admin.nav.curriculum'), lcms_engine.edit_admin_curriculum_path %>
</li>

<li class="dropdown c-header__link">
<%= link_to t('lcms.engine.admin.nav.resources'), admin_resources_path %>
<%= link_to t('lcms.engine.admin.nav.resources'), lcms_engine.admin_resources_path %>
<ul class="menu vertical">
<%= nav_link t('lcms.engine.admin.nav.resources'), admin_resources_path %>
<%= nav_link t('lcms.engine.admin.nav.add_resource'), new_admin_resource_path %>
<%= nav_link t('lcms.engine.admin.nav.resources'), lcms_engine.admin_resources_path %>
<%= nav_link t('lcms.engine.admin.nav.add_resource'), lcms_engine.new_admin_resource_path %>
<%#= nav_link t('lcms.engine.admin.nav.sketch_compilation', version: 'v1'), new_admin_sketch_compiler_path(:v1) %>
<%#= nav_link t('lcms.engine.admin.nav.sketch_compilation', version: 'v2'), new_admin_sketch_compiler_path(:v2) %>
<%= nav_link t('lcms.engine.admin.nav.lessons'), admin_documents_path %>
<%= nav_link t('lcms.engine.admin.nav.materials'), admin_materials_path %>
<%= nav_link t('lcms.engine.admin.nav.batch_reimport'), new_admin_batch_reimport_path %>
<%= nav_link t('lcms.engine.admin.nav.lessons'), lcms_engine.admin_documents_path %>
<%= nav_link t('lcms.engine.admin.nav.materials'), lcms_engine.admin_materials_path %>
<%= nav_link t('lcms.engine.admin.nav.batch_reimport'), lcms_engine.new_admin_batch_reimport_path %>
</ul>
</li>

<li class="c-header__link">
<%= link_to t('lcms.engine.admin.nav.standards'), admin_standards_path %>
<%= link_to t('lcms.engine.admin.nav.standards'), lcms_engine.admin_standards_path %>
</li>

<li class="dropdown c-header__link">
<%= link_to t('lcms.engine.admin.nav.users'), admin_users_path %>
<%= link_to t('lcms.engine.admin.nav.users'), lcms_engine.admin_users_path %>
<ul class="menu vertical">
<%= nav_link t('lcms.engine.admin.nav.users'), admin_users_path %>
<%= nav_link t('lcms.engine.admin.nav.access_codes'), admin_access_codes_path %>
<%= nav_link t('lcms.engine.admin.nav.users'), lcms_engine.admin_users_path %>
<%= nav_link t('lcms.engine.admin.nav.access_codes'), lcms_engine.admin_access_codes_path %>
</ul>
</li>

<li class="c-header__link">
<%= link_to t('lcms.engine.admin.nav.sign_out'), destroy_user_session_path %>
<%= link_to t('lcms.engine.admin.nav.sign_out'), lcms_engine.destroy_user_session_path %>
</li>
</ul>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/lcms/engine/admin/standards/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= simple_form_for @standard, as: :standard, url: admin_standard_path(@standard), html: { class: 'o-standard-form' } do |f| %>
<%= simple_form_for @standard, as: :standard, url: lcms_engine.admin_standard_path(@standard), html: { class: 'o-standard-form' } do |f| %>

<div class="row o-admin-standard-readonly">
<label>Name: </label>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= simple_form_for :query, url: :admin_standards, html: { class: 'form-inline well o-admin-standards-search', method: :get } do |f| %>
<%= simple_form_for :query, url: lcms_engine.admin_standards_path, html: { class: 'form-inline well o-admin-standards-search', method: :get } do |f| %>

<div class='row align-bottom align-justify'>
<%= f.input :name, label: 'Name', required: false, wrapper_html: { class: 'resource-search-title' } %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/lcms/engine/admin/users/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= simple_form_for [:admin, @user], html: { id: 'user_form' } do |f| %>
<%= simple_form_for @user, url: @url.presence || lcms_engine.admin_users_path, html: { id: 'user_form' } do |f| %>
<%= f.input :id, disabled: true %>
<%= f.input :name %>
<%= f.input :email %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/lcms/engine/admin/users/_search_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= simple_form_for :query, url: :admin_users, html: { class: 'form-inline well o-admin-users-search', method: :get } do |f| %>
<%= simple_form_for :query, url: lcms_engine.admin_users_path, html: { class: 'form-inline well o-admin-users-search', method: :get } do |f| %>

<div class='row align-bottom align-justify'>
<%= f.input :email, label: false, required: false, placeholder: 'Search by E-mail', wrapper_html: { class: 'o-admin-search-term' } %>
Expand Down
12 changes: 6 additions & 6 deletions app/views/lcms/engine/admin/users/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<div class="row">
<div class="flex-pull-right">
<%= link_to t('.new_user'), :new_admin_user, class: 'button success' %>
<%= link_to t('.new_user'), lcms_engine.new_admin_user_path, class: 'button success' %>
</div>
<table class="table">
<tr>
Expand All @@ -27,17 +27,17 @@
<% @users.each do |user| %>
<% cache user do %>
<tr id="user_<%= user.id %>">
<td><%= link_to user.id, edit_admin_user_path(user) %>
<td><%= link_to user.survey&.fetch('first_name', nil) || user.name, edit_admin_user_path(user) %>
<td><%= link_to user.id, lcms_engine.edit_admin_user_path(user) %>
<td><%= link_to user.survey&.fetch('first_name', nil) || user.name, lcms_engine.edit_admin_user_path(user) %>
<td><%= raw user.survey&.fetch('last_name', nil) %>
<td><%= user.email %>
<td><%= user.role %>
<td><%= user.access_code.presence || '-' %>
<td><%= user.confirmed? ? 'YES' : 'NO' %>
<td class="u-txt--small"><%= user.created_at.to_s %>
<td><%= link_to content_tag(:i, nil, class: 'fas fa-pencil-alt').html_safe, edit_admin_user_path(user), class: 'button small primary' %>
<td><%= button_to t('.reset_password_btn'), reset_password_admin_user_path(user), class: 'button small', data: { confirm: t('ui.are_you_sure') }, form_class: 'inline', method: :post %>
<td><%= button_to t('ui.delete'), admin_user_path(user), class: 'button small alert', data: { confirm: t('ui.are_you_sure') }, form_class: 'inline', method: :delete %></td>
<td><%= link_to content_tag(:i, nil, class: 'fas fa-pencil-alt').html_safe, lcms_engine.edit_admin_user_path(user), class: 'button small primary' %>
<td><%= button_to t('.reset_password_btn'), lcms_engine.reset_password_admin_user_path(user), class: 'button small', data: { confirm: t('ui.are_you_sure') }, form_class: 'inline', method: :post %>
<td><%= button_to t('ui.delete'), lcms_engine.admin_user_path(user), class: 'button small alert', data: { confirm: t('ui.are_you_sure') }, form_class: 'inline', method: :delete %></td>
</tr>
<% end %>
<% end %>
Expand Down
Loading

0 comments on commit 3c6fd4a

Please sign in to comment.