diff --git a/app/controllers/facilitators_controller.rb b/app/controllers/facilitators_controller.rb
index ad1a27044..59ade76db 100644
--- a/app/controllers/facilitators_controller.rb
+++ b/app/controllers/facilitators_controller.rb
@@ -179,7 +179,6 @@ def facilitator_params
project_users_attributes: [
:id,
:project_id,
- :position,
:title,
:inactive,
:_destroy
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 78102f9c9..f4878368e 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -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
diff --git a/app/models/project.rb b/app/models/project.rb
index 7e978c83f..e9ae60be2 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -102,6 +102,6 @@ def sector_list
private
def leader
- project_users.find_by(position: 2)
+ project_users.find_by(title: "leader")
end
end
diff --git a/app/models/project_user.rb b/app/models/project_user.rb
index d68313262..92dc39837 100644
--- a/app/models/project_user.rb
+++ b/app/models/project_user.rb
@@ -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
diff --git a/app/models/user.rb b/app/models/user.rb
index 88526c7da..55dc26291 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -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
@@ -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?
diff --git a/app/views/facilitators/_project_user_fields.html.erb b/app/views/facilitators/_project_user_fields.html.erb
index f9b50287d..b49c70cbd 100644
--- a/app/views/facilitators/_project_user_fields.html.erb
+++ b/app/views/facilitators/_project_user_fields.html.erb
@@ -17,7 +17,7 @@
as: :text,
input_html: {
rows: 1,
- value: f.object.title || f.object.position,
+ value: f.object.title,
} %>
@@ -38,6 +38,6 @@
<% else %>
-
<%= f.object.project&.name %> (<%= f.object.title || f.object.position %>)
+ <%= f.object.project&.name %> (<%= f.object.title %>)
<% end %>
diff --git a/app/views/projects/_project_user_fields.html.erb b/app/views/projects/_project_user_fields.html.erb
index 424ed1913..97538a627 100644
--- a/app/views/projects/_project_user_fields.html.erb
+++ b/app/views/projects/_project_user_fields.html.erb
@@ -18,7 +18,7 @@
as: :text,
input_html: {
rows: 1,
- value: f.object&.title || f.object&.position,
+ value: f.object&.title,
} %>
@@ -39,6 +39,6 @@
<% else %>
-
<%= f.object.project&.name %> (<%= f.object.title || f.object.position %>)
+ <%= f.object.project&.name %> (<%= f.object.title %>)
<% end %>
diff --git a/app/views/shared/_project_user.html.erb b/app/views/shared/_project_user.html.erb
index a5f40f6e4..d19bf2c12 100644
--- a/app/views/shared/_project_user.html.erb
+++ b/app/views/shared/_project_user.html.erb
@@ -11,7 +11,7 @@
<%= user.name %>
- <%= project_user.position %>
+ <%= project_user.title %>
<%= "Last logged in #{user.last_logged_in}" %>
diff --git a/app/views/users/_project_user_fields.html.erb b/app/views/users/_project_user_fields.html.erb
index a81060233..3bee547d4 100644
--- a/app/views/users/_project_user_fields.html.erb
+++ b/app/views/users/_project_user_fields.html.erb
@@ -17,7 +17,7 @@
as: :text,
input_html: {
rows: 1,
- value: f.object.title || f.object.position,
+ value: f.object.title,
} %>
diff --git a/db/migrate/20260120010312_convert_project_user_position_to_title.rb b/db/migrate/20260120010312_convert_project_user_position_to_title.rb
new file mode 100644
index 000000000..cc78001b7
--- /dev/null
+++ b/db/migrate/20260120010312_convert_project_user_position_to_title.rb
@@ -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
diff --git a/spec/factories/project_users.rb b/spec/factories/project_users.rb
index 5db0f5344..415ff6768 100644
--- a/spec/factories/project_users.rb
+++ b/spec/factories/project_users.rb
@@ -3,6 +3,6 @@
association :project
association :user
- position { :default }
+ title { "default" }
end
end
diff --git a/spec/models/project_user_spec.rb b/spec/models/project_user_spec.rb
index 1bfcad0ff..fd01914a2 100644
--- a/spec/models/project_user_spec.rb
+++ b/spec/models/project_user_spec.rb
@@ -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
diff --git a/spec/views/users/show.html.erb_spec.rb b/spec/views/users/show.html.erb_spec.rb
index aa1fd0a55..dcfb4e987 100644
--- a/spec/views/users/show.html.erb_spec.rb
+++ b/spec/views/users/show.html.erb_spec.rb
@@ -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)