Skip to content

Commit 283cc9c

Browse files
authored
Merge pull request #269 from AlchemyCMS/add-timezone-to-users
feat: Add timezone to users
2 parents b92a3ba + 590a5b1 commit 283cc9c

6 files changed

Lines changed: 30 additions & 4 deletions

File tree

app/models/alchemy/user.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ class User < ActiveRecord::Base
1414
:password,
1515
:password_confirmation,
1616
:send_credentials,
17-
:tag_list
17+
:tag_list,
18+
:timezone
1819
]
1920

2021
devise(*Alchemy::Devise.config.devise_modules)

app/views/alchemy/admin/users/_fields.html.erb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
<% end %>
1111
<%= f.input :password, required: while_signup?, input_html: {autocomplete: "new-password"} %>
1212
<%= f.input :password_confirmation, required: while_signup?, input_html: {autocomplete: "new-password"} %>
13+
<%= f.input :timezone,
14+
collection: ActiveSupport::TimeZone.all, label_method: :to_s, value_method: :name,
15+
input_html: {
16+
is: "alchemy-select",
17+
data: {allow_clear: true}
18+
} %>
1319
<% if can_update_role? %>
1420
<%= f.input :alchemy_roles,
1521
collection: @user_roles,

app/views/alchemy/admin/users/_resource_table.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
alchemy.edit_admin_user_path(user), {
99
title: Alchemy.t(:edit_user),
1010
overflow: true,
11-
size: "430x500"
11+
size: "430x530"
1212
},
1313
title: Alchemy.t(:edit_user) %>
1414
<% else %>
@@ -28,5 +28,5 @@
2828
<%= user.human_roles_string %>
2929
<% end %>
3030
<% table.delete_button tooltip: Alchemy.t(:delete_user), confirm_message: Alchemy.t(:confirm_to_delete_user) %>
31-
<% table.edit_button tooltip: Alchemy.t(:edit_user), dialog_size: "430x500" %>
31+
<% table.edit_button tooltip: Alchemy.t(:edit_user), dialog_size: "430x530" %>
3232
<% end %>

app/views/alchemy/admin/users/index.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
tooltip_placement: "top-start",
1313
dialog_options: {
1414
title: Alchemy.t(:create_user),
15-
size: "430x500"
15+
size: "430x530"
1616
},
1717
if_permitted_to: [:create, Alchemy::User]
1818
) %>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class AddTimezoneToAlchemyUsers < ActiveRecord::Migration[7.2]
2+
def change
3+
add_column :alchemy_users, :timezone, :string, if_not_exists: true,
4+
comment: "The timezone of the user, used for displaying dates in the user's timezone"
5+
end
6+
end

spec/features/admin/users_feature_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,19 @@
129129
end
130130

131131
it_behaves_like "allowing to set users language"
132+
133+
it "can set users timezone" do
134+
subject
135+
136+
within "form.alchemy[action*='/admin/users']" do
137+
expect(page).to have_select "Timezone"
138+
select "Berlin", from: "Timezone"
139+
click_button "Save"
140+
end
141+
142+
expect(page).to have_content Alchemy.t("User updated", name: user.name)
143+
expect(user.reload.timezone).to eq "Berlin"
144+
end
132145
end
133146
end
134147
end

0 commit comments

Comments
 (0)