Skip to content

Commit 9eafbc8

Browse files
committed
fix(timezone): Only set time zone if current user can edit content
If this module is included in a controller out of the Alchemy::Admin scope we need to make sure we do not set the time zone.
1 parent 1e47eb5 commit 9eafbc8

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

lib/alchemy/admin/timezone.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module Timezone
66
extend ActiveSupport::Concern
77

88
included do
9-
around_action :set_timezone
9+
around_action :set_timezone, if: -> { can?(:edit_content, Alchemy::Page) }
1010
end
1111

1212
private

spec/lib/alchemy/admin/timezone_spec.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ def index
1313
private
1414

1515
attr_reader :current_alchemy_user
16+
17+
def can?(*)
18+
true
19+
end
1620
end
1721

1822
let(:original_timezone) { Time.zone.name }
@@ -97,5 +101,26 @@ def index
97101
get :index, params: {admin_timezone: "Hawaii"}
98102
expect(Time.zone.name).to eq(original)
99103
end
104+
105+
context "when user cannot edit content" do
106+
controller(ActionController::Base) do
107+
include Alchemy::Admin::Timezone
108+
109+
def index
110+
render plain: Time.zone.name
111+
end
112+
113+
private
114+
115+
def can?(*)
116+
false
117+
end
118+
end
119+
120+
it "does not set the timezone" do
121+
get :index, params: {admin_timezone: "Hawaii"}
122+
expect(response.body).to eq(original_timezone)
123+
end
124+
end
100125
end
101126
end

0 commit comments

Comments
 (0)