Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class User < ApplicationRecord
# Validations
validates :email, presence: true, uniqueness: { case_sensitive: false }
validate :time_zone_must_be_valid, if: :time_zone_changed?
validate :facilitator_id_must_be_present_if_previously_set, on: :update
validates_associated :project_users

# Search Cop
Expand Down Expand Up @@ -181,6 +182,13 @@ def time_zone_must_be_valid
errors.add(:time_zone, "is not a valid time zone")
end

def facilitator_id_must_be_present_if_previously_set
return unless facilitator_id_was.present?
return if facilitator_id.present?

errors.add(:facilitator_id, "cannot be removed once set")
end

def set_default_values
self.inactive = false if inactive.nil?
self.confirmed = true if confirmed.nil?
Expand Down
18 changes: 5 additions & 13 deletions app/views/users/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<%= simple_form_for @user, html: { multipart: true, class: "space-y-8" } do |f| %>
<%= render "shared/errors", resource: user if user.errors.any? %>

<%= f.hidden_field :facilitator_id, value: params[:facilitator_id] %>

<%= f.hidden_field :facilitator_id, value: @facilitator&.id || f.object.facilitator_id || params[:facilitator_id] %>
<!-- Basic Info + Avatar -->
<!-- Container -->
<div class="flex gap-8 items-start">
Expand All @@ -28,7 +26,6 @@
</p>
</div>
</div>

<div>
<div class="w-full">
<label class="block text-md font-medium text-gray-700 mb-1">
Expand All @@ -55,7 +52,6 @@
</div>
<% end %>
<% end %>

<div class="md:flex-grow md:basis-1/3" id="email_field_wrapper">
<% if current_user.super_user? %>
<div class="w-full">
Expand All @@ -73,7 +69,7 @@
data-controller="confirm-email"
data-confirm-email-user-id-value="<%= @user.id %>"
data-action="click->confirm-email#confirm"
class="btn btn-sm bg-blue-600 hover:bg-blue-700 text-white border-blue-600">
class="btn btn-sm bg-blue-600 hover:bg-blue-700 text-white border-blue-600">
Manually confirm email
</button>
</div>
Expand All @@ -86,9 +82,9 @@
Email <%= email_confirmation_icon(@user) %>
</label>
<div class="flex gap-x-2 items-center">
<span class="text-gray-900 font-medium mb-2">
<%= f.object.email.presence || @facilitator&.email %>
</span>
<span class="text-gray-900 font-medium mb-2">
<%= f.object.email.presence || @facilitator&.email %>
</span>
</div>
<p class="text-sm text-gray-500 mt-1">
Only editable by admins
Expand All @@ -107,7 +103,6 @@
<% end %>
</div>
</div>

<!-- Notes -->
<% if current_user.super_user? %>
<div class="comments-section">
Expand All @@ -117,7 +112,6 @@
</div>
</div>
</div>

<!-- Preferences: timezone for event times etc. -->
<div class="space-y-6 p-3">
<%= f.input :time_zone,
Expand All @@ -129,12 +123,10 @@
input_html: { class: "w-full" },
wrapper_html: { class: "w-full max-w-md" } %>
</div>

<!-- Actions -->
<!-- Action buttons -->
<div class="action-buttons mt-8 flex justify-center gap-3">
<%= render "toggle_lock_button", user: @user %>

<% if f.object.persisted? && allowed_to?(:destroy?, f.object) %>
<%= link_to "Delete", @user, method: :delete, class: "btn btn-danger-outline",
data: { confirm: "Are you sure you want to delete?" } %>
Expand Down