Changed Roles within the app to FormRole to account for adding Rolify.

This commit is contained in:
Ben 2024-04-02 16:42:58 -05:00
parent a2a9e1312b
commit 65df59d3e6
13 changed files with 40 additions and 26 deletions

View File

@ -28,6 +28,8 @@ gem "jbuilder"
gem 'devise'
gem 'rolify'
gem 'webpacker'
gem 'kaminari'

View File

@ -228,6 +228,7 @@ GEM
actionpack (>= 5.2)
railties (>= 5.2)
rexml (3.2.6)
rolify (6.0.1)
ruby2_keywords (0.0.5)
rubyzip (2.3.2)
selenium-webdriver (4.16.0)
@ -298,6 +299,7 @@ DEPENDENCIES
kaminari
puma (>= 5.0)
rails (~> 7.1.2)
rolify
selenium-webdriver
sprockets-rails
sqlite3 (~> 1.4)

View File

@ -38,6 +38,11 @@ reset:
# bundle install
# rails g kaminari:views default
# gem 'rolify'
# bundle install
# rails g rolify Role User
# rails db:migrate
# mariams box:
# mariam@flippy:~/obdev$ make version
# Rails 7.1.2

View File

@ -2,7 +2,7 @@ class Form < ApplicationRecord
# Assuming each form can have many onboarding items associated with different owners.
has_many :onboarding_items
has_many :forms_roles
has_many :roles, through: :forms_roles
has_many :form_roles, through: :forms_roles
accepts_nested_attributes_for :forms_roles, allow_destroy: true
validates :name, presence: true

View File

@ -1,4 +1,4 @@
class Role < ApplicationRecord
class FormRole < ApplicationRecord
has_many :forms_roles
has_many :forms, through: :forms_roles
end

View File

@ -1,6 +1,6 @@
class FormsRole < ApplicationRecord
belongs_to :form
belongs_to :role
belongs_to :form_role
attribute :note, :string
attribute :date_completed, :date
end

View File

@ -1,12 +1,3 @@
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable
def admin?
self.admin
end
devise :database_authenticatable, :registerable, :recoverable, :rememberable, :validatable
end

View File

@ -3,7 +3,7 @@
<div class="col-md-6">
<h2 class="mb-3 text-center">Log in</h2>
<%= form_for(resource, as: resource_name, url: session_path(resource_name), html: { class: 'needs-validation', novalidate: true }) do |f| %>
<%= form_with(model: resource, as: resource_name, url: user_session_path, local: true, html: { class: 'needs-validation', novalidate: true }) do |f| %>
<div class="mb-3">
<%= f.label :email, class: 'form-label' %>
<%= f.email_field :email, autofocus: true, autocomplete: "email", class: 'form-control', placeholder: 'Enter email' %>

View File

@ -5,7 +5,7 @@
<% end %>
<%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %>
<%= link_to "Forgot your password?", new_password_path(resource_name), class: "btn btn-link" %>
<%= link_to "Forgot your password?", new_user_password_path(resource_name), class: "btn btn-link" %>
<% end %>
<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %>

View File

@ -21,7 +21,7 @@
<td><%= form.name %></td>
<td><%= form.required ? 'Required' : 'Optional' %></td>
<td><%= form.program %></td>
<td><%= form.roles.map(&:name).join(", ") %></td>
<td><%= form.form_roles.map(&:name).join(", ") %></td>
<td>
<%= link_to edit_form_path(form), class: 'btn btn-info btn-sm' do %>
<i class="bi bi-pencil-fill" style="color: white;"></i>

View File

@ -0,0 +1,5 @@
class RenameRoleToFormRole < ActiveRecord::Migration[7.1]
def change
rename_table :roles, :form_roles
end
end

View File

@ -0,0 +1,9 @@
class FixFormRoleIdInFormsRoles < ActiveRecord::Migration[7.1]
def change
# Rename role_id to form_role_id if the column exists
# This is necessary to match the updated association in your models
if column_exists?(:forms_roles, :role_id)
rename_column :forms_roles, :role_id, :form_role_id
end
end
end

20
db/schema.rb generated
View File

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.1].define(version: 2024_02_17_063857) do
ActiveRecord::Schema[7.1].define(version: 2024_04_02_214014) do
create_table "bank_accounts", force: :cascade do |t|
t.string "institution_name"
t.string "account_type"
@ -72,6 +72,12 @@ ActiveRecord::Schema[7.1].define(version: 2024_02_17_063857) do
t.index ["worker_id"], name: "index_employments_on_worker_id"
end
create_table "form_roles", force: :cascade do |t|
t.string "name"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "forms", force: :cascade do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
@ -83,13 +89,13 @@ ActiveRecord::Schema[7.1].define(version: 2024_02_17_063857) do
create_table "forms_roles", force: :cascade do |t|
t.integer "form_id", null: false
t.integer "role_id", null: false
t.integer "form_role_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "note"
t.date "date_completed"
t.index ["form_id"], name: "index_forms_roles_on_form_id"
t.index ["role_id"], name: "index_forms_roles_on_role_id"
t.index ["form_role_id"], name: "index_forms_roles_on_form_role_id"
end
create_table "onboarding_items", force: :cascade do |t|
@ -143,12 +149,6 @@ ActiveRecord::Schema[7.1].define(version: 2024_02_17_063857) do
t.datetime "updated_at", null: false
end
create_table "roles", force: :cascade do |t|
t.string "name"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "service_contracts", force: :cascade do |t|
t.integer "participant_id", null: false
t.integer "vendor_id", null: false
@ -214,8 +214,8 @@ ActiveRecord::Schema[7.1].define(version: 2024_02_17_063857) do
add_foreign_key "employer_records", "participants"
add_foreign_key "employments", "participants"
add_foreign_key "employments", "workers"
add_foreign_key "forms_roles", "form_roles"
add_foreign_key "forms_roles", "forms"
add_foreign_key "forms_roles", "roles"
add_foreign_key "participants", "employers"
add_foreign_key "participants", "workers"
add_foreign_key "service_contracts", "participants"