Skip to content

Commit

Permalink
Merge pull request #2085 from tf/entry-create-redirect
Browse files Browse the repository at this point in the history
Add config option to redirect to editor after entry create
  • Loading branch information
tf authored Mar 4, 2024
2 parents d538c2b + ebe2faa commit 6a78645
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
13 changes: 13 additions & 0 deletions admins/pageflow/entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,19 @@ module Pageflow
end
end

def create
create! do |success, _|
success.html do
case Pageflow.config.after_entry_create_redirect_to
when :admin
redirect_to admin_entry_path(resource)
when :editor
redirect_to pageflow.editor_entry_path(resource)
end
end
end
end

def update
update! do |success, _|
success.html { redirect_to(admin_entry_path(resource, params.permit(:tab))) }
Expand Down
9 changes: 9 additions & 0 deletions lib/pageflow/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,14 @@ class Configuration
# files based on feature flags and other entry or account traits.
attr_accessor :transform_theme_customization_files

# Where to redirect after creating an entry.
#
# Possible values:
#
# `:admin`: Go to entry admin page (default)
# `:editor`: Open created entry in editor
attr_accessor :after_entry_create_redirect_to

# Submit video/audio encoding jobs only after the user has
# explicitly confirmed in the editor. Can either be set to a
# boolean or a lambda that is passed the file and returns a
Expand Down Expand Up @@ -433,6 +441,7 @@ def initialize(target_type_name = nil)
@transform_theme_customization_overrides = ->(overrides, _entry) { overrides }
@transform_theme_customization_files = ->(files, _entry) { files }

@after_entry_create_redirect_to = :admin
@confirm_encoding_jobs = false
@default_published_until_duration_in_months = 12

Expand Down
27 changes: 27 additions & 0 deletions spec/controllers/admin/entries_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,33 @@ def self.name

expect(response.body).to have_selector('.pageflow_permalink.error')
end

it 'redirects to entry admin page by default' do
user = create(:user)
account = create(:account, with_publisher: user)

sign_in(user, scope: :user)

post :create, params: {entry: attributes_for(:entry, account:)}

expect(request).to redirect_to(admin_entry_path(Pageflow::Entry.last))
end

it 'redirects to editor if after_entry_create is set to editor' do
user = create(:user)
account = create(:account, with_publisher: user)
Pageflow.config.after_entry_create_redirect_to = :editor

sign_in(user, scope: :user)

post :create, params: {entry: attributes_for(:entry, account:)}

expect(request).to(
redirect_to(
Pageflow::Engine.routes.url_helpers.editor_entry_path(Pageflow::Entry.last)
)
)
end
end

describe '#edit' do
Expand Down

0 comments on commit 6a78645

Please sign in to comment.