Skip to content
Draft
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
1 change: 0 additions & 1 deletion app/controllers/facilitators_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ def facilitator_params
project_users_attributes: [
:id,
:project_id,
:position,
:title,
:inactive,
:_destroy
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def user_params
:notes, :primary_address, :avatar, :subscribecode,
:agency_id, :facilitator_id, :created_by_id, :updated_by_id,
:confirmed, :inactive, :super_user, :legacy, :legacy_id,
project_users_attributes: [ :id, :project_id, :position, :title, :inactive, :_destroy ]
project_users_attributes: [ :id, :project_id, :title, :inactive, :_destroy ]
)
end
end
2 changes: 1 addition & 1 deletion app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,6 @@ def sector_list
private

def leader
project_users.find_by(position: 2)
project_users.find_by(title: "leader")
end
end
3 changes: 0 additions & 3 deletions app/models/project_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ class ProjectUser < ApplicationRecord
# Validations
validates_presence_of :project_id

# Enum
enum :position, { default: 0, liaison: 1, leader: 2, assistant: 3 }

scope :active, -> { where(inactive: false) }

# Methods
Expand Down
4 changes: 2 additions & 2 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class User < ApplicationRecord
has_many :bookmarked_workshops, through: :bookmarks, source: :bookmarkable, source_type: "Workshop"
has_many :bookmarked_resources, through: :bookmarks, source: :bookmarkable, source_type: "Resource"
has_many :bookmarked_events, through: :bookmarks, source: :bookmarkable, source_type: "Event"
has_many :colleagues, -> { select(:user_id, :position, :project_id).distinct },
has_many :colleagues, -> { select(:user_id, :title, :project_id).distinct },
through: :projects, source: :project_users
has_many :communal_reports, through: :projects, source: :reports
has_many :events, through: :event_registrations
Expand Down Expand Up @@ -66,7 +66,7 @@ def self.search_by_params(params)
end

def has_liasion_position_for?(project_id)
!project_users.where(project_id: project_id, position: 1).first.nil?
!project_users.where(project_id: project_id, title: "liaison").first.nil?
end

def active_for_authentication?
Expand Down
4 changes: 2 additions & 2 deletions app/views/facilitators/_project_user_fields.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
as: :text,
input_html: {
rows: 1,
value: f.object.title || f.object.position,
value: f.object.title,
} %>
</div>

Expand All @@ -38,6 +38,6 @@
</div>
<% else %>
<div class="ps-6 mb-4">
<li><%= f.object.project&.name %> (<%= f.object.title || f.object.position %>)</li>
<li><%= f.object.project&.name %> (<%= f.object.title %>)</li>
</div>
<% end %>
4 changes: 2 additions & 2 deletions app/views/projects/_project_user_fields.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
as: :text,
input_html: {
rows: 1,
value: f.object&.title || f.object&.position,
value: f.object&.title,
} %>
</div>

Expand All @@ -39,6 +39,6 @@
</div>
<% else %>
<div class="ps-6 mb-4">
<li><%= f.object.project&.name %> (<%= f.object.title || f.object.position %>)</li>
<li><%= f.object.project&.name %> (<%= f.object.title %>)</li>
</div>
<% end %>
2 changes: 1 addition & 1 deletion app/views/shared/_project_user.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<div class="col-md-8 white text-left users-group">
<%= user.name %>
<div class="smaller white text-left">
<%= project_user.position %>
<%= project_user.title %>
<p>
<%= "Last logged in #{user.last_logged_in}" %>
</p>
Expand Down
2 changes: 1 addition & 1 deletion app/views/users/_project_user_fields.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
as: :text,
input_html: {
rows: 1,
value: f.object.title || f.object.position,
value: f.object.title,
} %>
</div>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
class ConvertProjectUserPositionToTitle < ActiveRecord::Migration[8.1]
def up
# Map position enum values to human-readable titles
# default: 0, liaison: 1, leader: 2, assistant: 3
position_to_title = {
0 => "default",
1 => "liaison",
2 => "leader",
3 => "assistant"
}

# Update title from position where title is nil
ProjectUser.where(title: nil).find_each do |project_user|
if project_user.position.present?
title_value = position_to_title[project_user.position]
project_user.update_column(:title, title_value) if title_value
end
end

# Remove the position column
remove_column :project_users, :position, :integer
end

def down
# Add position column back
add_column :project_users, :position, :integer

# Map titles back to position enum values
title_to_position = {
"default" => 0,
"liaison" => 1,
"leader" => 2,
"assistant" => 3
}

# Restore position from title
ProjectUser.where.not(title: nil).find_each do |project_user|
position_value = title_to_position[project_user.title]
project_user.update_column(:position, position_value) if position_value
end
end
end
2 changes: 1 addition & 1 deletion spec/factories/project_users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
association :project
association :user

position { :default }
title { "default" }
end
end
4 changes: 0 additions & 4 deletions spec/models/project_user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
it { should validate_presence_of(:project_id) }
end

describe 'enums' do
it { should define_enum_for(:position).with_values(default: 0, liaison: 1, leader: 2, assistant: 3) }
end

it 'is valid with valid attributes' do
# Note: Factory needs associations uncommented for create
# expect(build(:project_user)).to be_valid
Expand Down
2 changes: 1 addition & 1 deletion spec/views/users/show.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
let!(:workshop) { create(:workshop, title: "Mindful Art", user: user, windows_type: windows_type) }

let!(:project) { create(:project, name: "Healing Arts") }
let!(:project_user) { create(:project_user, project: project, user: user, position: :leader) }
let!(:project_user) { create(:project_user, project: project, user: user, title: "leader") }

before do
assign(:user, user)
Expand Down