Skip to content

Commit

Permalink
Merge pull request #501 from berkmancenter/15702_railsadmin_edit_perf
Browse files Browse the repository at this point in the history
15702 railsadmin edit perf
  • Loading branch information
thatandromeda committed Nov 20, 2018
2 parents 206754d + c7e7fe2 commit bcba9a4
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 35 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ config/database.yml
.byebug_history
.rubocop.yml
rspec_examples.txt
.reek.yml
32 changes: 23 additions & 9 deletions config/initializers/rails_admin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
config.model notice_type do
label { abstract_model.model.label }
list do
# SELECT COUNT is slow when the number of instances is large; let's
# avoid calling it for Notice and its subclasses.
limited_pagination true

field :id
field :title
field(:date_sent) { label 'Sent' }
Expand Down Expand Up @@ -82,6 +86,11 @@
end

edit do
# This dramatically speeds up the admin page.
configure :works do
nested_form false
end

configure :action_taken, :enum do
enum do
%w[Yes No Partial Unspecified]
Expand All @@ -96,15 +105,13 @@
label 'Type'
required true
end
configure(:topic_assignments) { hide }
configure(:topic_relevant_questions) { hide }

configure(:related_blog_entries) { hide }

configure(:blog_topic_assignments) { hide }
configure(:entities) { hide }
configure(:infringing_urls) { hide }
configure(:copyrighted_urls) { hide }
exclude_fields :topic_assignments,
:topic_relevant_questions,
:related_blog_entries,
:blog_topic_assignments,
:infringing_urls,
:copyrighted_urls

configure :review_required do
visible do
Expand Down Expand Up @@ -135,6 +142,8 @@
end
end
edit do
# exclude_fields :notices might be a better performance option than hide,
# but it prevents topics with null ancestries from being saved.
configure(:notices) { hide }
configure(:topic_assignments) { hide }

Expand All @@ -151,12 +160,16 @@
config.model 'EntityNoticeRole' do
edit do
configure(:notice) { hide }
configure :entity do
nested_form false
end
end
end

config.model 'Entity' do
list do
configure(:notices) { hide }
# See exclude_fields comment for Topic.
exclude_fields :notices
configure(:entity_notice_roles) { hide }
configure :parent do
formatted_value do
Expand Down Expand Up @@ -200,6 +213,7 @@
configure(:copyrighted_urls) { hide }
configure(:infringing_urls) { hide }
end

nested do
configure(:infringing_urls) { hide }
configure(:copyrighted_urls) { hide }
Expand Down
51 changes: 26 additions & 25 deletions spec/integration/user_authorizes_spec.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
require 'rails_helper'
require 'support/contain_link'

feature "User authorization" do
feature 'User authorization' do
include ContainLink

scenario "A non logged-in user is redirected to sign in" do
scenario 'A non logged-in user is redirected to sign in' do
user = AdminOnPage.new(create(:user))

user.visit_admin

expect(page).to have_text("You are not authorized to access this page.")
expect(page).to have_text('You are not authorized to access this page.')
end

scenario "Submitters- cannot access admin" do
scenario 'Submitters - cannot access admin' do
page_objects = [
AdminOnPage.new(create(:user)),
AdminOnPage.new(create(:user, :submitter))
Expand All @@ -25,7 +25,7 @@
end
end

scenario "Redactors+ are able to access admin" do
scenario 'Redactors+ are able to access admin' do
page_objects = [
AdminOnPage.new(create(:user, :redactor)),
AdminOnPage.new(create(:user, :publisher)),
Expand All @@ -40,7 +40,7 @@
end
end

scenario "All levels can edit notices" do
scenario 'All levels can edit notices' do
notice = create(:dmca)
page_objects = [
AdminOnPage.new(create(:user, :redactor)),
Expand All @@ -56,7 +56,7 @@
end
end

scenario "Redactors cannot publish (admin)" do
scenario 'Redactors cannot publish (admin)' do
page_object = AdminOnPage.new(create(:user, :redactor))
notice = create(:dmca, review_required: true)

Expand All @@ -65,7 +65,7 @@
expect(page).to have_no_css('input#notice_review_required')
end

scenario "Publishers+ can publish (admin)" do
scenario 'Publishers+ can publish (admin)' do
notice = create(:dmca, review_required: true)
page_objects = [
AdminOnPage.new(create(:user, :publisher)),
Expand All @@ -80,7 +80,7 @@
end
end

scenario "Redactors cannot publish (redact tool)" do
scenario 'Redactors cannot publish (redact tool)' do
notice = create(:dmca, review_required: true)
page_object = AdminOnPage.new(create(:user, :redactor))

Expand All @@ -89,7 +89,7 @@
expect(page).to have_no_css('input#notice_review_required')
end

scenario "Publishers+ can publish (redact tool)" do
scenario 'Publishers+ can publish (redact tool)' do
notice = create(:dmca, review_required: true)
page_objects = [
AdminOnPage.new(create(:user, :publisher)),
Expand All @@ -104,7 +104,7 @@
end
end

scenario "Redactors and Publishers cannot create/delete notices" do
scenario 'Redactors and Publishers cannot create/delete notices' do
notice = create(:dmca)
page_objects = [
AdminOnPage.new(create(:user, :redactor)),
Expand All @@ -122,7 +122,7 @@
end
end

scenario "Redactors and Publishers cannot edit site data" do
scenario 'Redactors and Publishers cannot edit site data' do
site_data = [
create(:topic),
create(:relevant_question),
Expand All @@ -146,7 +146,7 @@
end
end

scenario "Redactors and Publishers cannot rescind notices" do
scenario 'Redactors and Publishers cannot rescind notices' do
notice = create(:dmca)
page_objects = [
AdminOnPage.new(create(:user, :redactor)),
Expand All @@ -160,8 +160,9 @@
end
end

scenario "Admins and Super admins can edit site data" do
scenario 'Admins and Super admins can edit site data' do
topic = create(:topic)
topic.save
page_objects = [
AdminOnPage.new(create(:user, :admin)),
AdminOnPage.new(create(:user, :super_admin))
Expand All @@ -174,7 +175,7 @@
end
end

scenario "Admins and Super admins can rescind notices" do
scenario 'Admins and Super admins can rescind notices' do
notice = create(:dmca)
page_objects = [
AdminOnPage.new(create(:user, :admin)),
Expand All @@ -188,7 +189,7 @@
end
end

scenario "Admins cannot edit Users or Access levels" do
scenario 'Admins cannot edit Users or Access levels' do
site_data = [
create(:user),
create(:role)
Expand All @@ -203,25 +204,25 @@
end
end

scenario "Super admins can edit other Users" do
scenario 'Super admins can edit other Users' do
obj = AdminOnPage.new(create(:user, :super_admin))
other_user = create(:user)

obj.sign_in_and_edit(other_user, user_email: "new-email@example.com")
obj.sign_in_and_edit(other_user, user_email: 'new-email@example.com')

expect(other_user.reload.email).to eq "new-email@example.com"
expect(other_user.reload.email).to eq 'new-email@example.com'
end

scenario "Super admins can edit Roles" do
scenario 'Super admins can edit Roles' do
obj = AdminOnPage.new(create(:user, :super_admin))
role = create(:role, name: "some_name")
role = create(:role, name: 'some_name')

obj.sign_in_and_edit(role, Name: "another_name")
obj.sign_in_and_edit(role, Name: 'another_name')

expect(role.reload.name).to eq "another_name"
expect(role.reload.name).to eq 'another_name'
end

scenario "Visibility of notice administation links" do
scenario 'Visibility of notice administation links' do
notice = create(:dmca)
admin_path = rails_admin.show_path(model_name: 'dmca', id: notice.id)

Expand All @@ -236,7 +237,7 @@

expect(page).to contain_link(admin_path)

click_on "Edit in Admin"
click_on 'Edit in Admin'

expect(obj).to be_in_admin
end
Expand Down
1 change: 0 additions & 1 deletion spec/support/page_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ def fill_in_form_with(attributes)
end
end
end

end

0 comments on commit bcba9a4

Please sign in to comment.