diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index 87a88984f..2dcc7da3d 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -67,6 +67,7 @@ def show def new set_user @person = @user ? PersonFromUserService.new(user: @user).call : Person.new + @person.user = @user if @user authorize! @person set_form_variables end @@ -90,6 +91,9 @@ def create authorize! @person @person.user ||= User.find_by(id: params[:user_id]) if params[:user_id].present? @person.user ||= User.find_by(id: params.dig(:person, :user_attributes, :id)) if params.dig(:person, :user_attributes, :id).present? + if @person.user && person_params[:user_attributes].present? + @person.user.assign_attributes(person_params[:user_attributes].except(:id)) + end unless params[:skip_duplicate_check].present? duplicates = find_duplicate_people( @@ -369,7 +373,8 @@ def person_params :city2, :state2, :zip2, - :notes + :notes, + :time_zone ], affiliations_attributes: [ :id, diff --git a/app/views/people/_form.html.erb b/app/views/people/_form.html.erb index eff9a0c93..a48ea0c20 100644 --- a/app/views/people/_form.html.erb +++ b/app/views/people/_form.html.erb @@ -209,6 +209,22 @@ }, hint: "Maximum 250 characters" %> + + <% if f.object.user %> + <%= f.fields_for :user do |user_form| %> +
+ <%= user_form.input :time_zone, + as: :select, + collection: us_time_zone_fundamentals, + selected: user_form.object.time_zone.presence || "Pacific Time (US & Canada)", + include_blank: false, + hint: "Event times and other dates will be shown in this timezone.", + input_html: { class: "w-full" }, + wrapper_html: { class: "w-full max-w-md" } %> +
+ <% end %> + <% end %> +
Social media links: diff --git a/app/views/users/_form.html.erb b/app/views/users/_form.html.erb index 849a515cc..385fbefc6 100644 --- a/app/views/users/_form.html.erb +++ b/app/views/users/_form.html.erb @@ -135,16 +135,34 @@
-
- <%= f.input :time_zone, - as: :select, - collection: us_time_zone_fundamentals, - selected: f.object.time_zone.presence || "Pacific Time (US & Canada)", - include_blank: false, - hint: "Event times and other dates will be shown in this timezone.", - input_html: { class: "w-full" }, - wrapper_html: { class: "w-full max-w-md" } %> -
+ <% if @person %> +
+
+ +
+
+ <%= f.object.time_zone || "Pacific Time (US & Canada)" %> +
+
+

+ Edit on <%= link_to "person profile", edit_person_path(@person), class: "underline" %> +

+
+
+ <% else %> +
+ <%= f.input :time_zone, + as: :select, + collection: us_time_zone_fundamentals, + selected: f.object.time_zone.presence || "Pacific Time (US & Canada)", + include_blank: false, + hint: "Event times and other dates will be shown in this timezone.", + input_html: { class: "w-full" }, + wrapper_html: { class: "w-full max-w-md" } %> +
+ <% end %> <% if f.object.persisted? %> diff --git a/spec/requests/people_create_spec.rb b/spec/requests/people_create_spec.rb new file mode 100644 index 000000000..6ac5b5b41 --- /dev/null +++ b/spec/requests/people_create_spec.rb @@ -0,0 +1,31 @@ +require "rails_helper" + +RSpec.describe "POST /people", type: :request do + let(:admin) { create(:user, :admin) } + + before { sign_in admin } + + describe "user_attributes are applied on create" do + it "updates the user's time_zone from the person form" do + user = create(:user, time_zone: "Hawaii") + + post people_path, params: { + skip_duplicate_check: "1", + person: { + first_name: user.first_name, + last_name: user.last_name, + email: user.email, + created_by_id: admin.id, + updated_by_id: admin.id, + user_attributes: { + id: user.id, + time_zone: "Eastern Time (US & Canada)" + } + } + } + + expect(response).to redirect_to(Person.last) + expect(user.reload.time_zone).to eq("Eastern Time (US & Canada)") + end + end +end