diff --git a/Gemfile b/Gemfile index 5eb6b52..e9284df 100644 --- a/Gemfile +++ b/Gemfile @@ -28,6 +28,8 @@ gem "jbuilder" gem 'devise' +gem 'rolify' + gem 'webpacker' gem 'kaminari' diff --git a/Gemfile.lock b/Gemfile.lock index 87bbc21..466bd18 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) diff --git a/Makefile b/Makefile index b5cd076..65a7cc0 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/app/models/form.rb b/app/models/form.rb index 761929f..fd7f138 100644 --- a/app/models/form.rb +++ b/app/models/form.rb @@ -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 diff --git a/app/models/role.rb b/app/models/form_role.rb similarity index 67% rename from app/models/role.rb rename to app/models/form_role.rb index 0a528dc..d247e44 100644 --- a/app/models/role.rb +++ b/app/models/form_role.rb @@ -1,4 +1,4 @@ -class Role < ApplicationRecord +class FormRole < ApplicationRecord has_many :forms_roles has_many :forms, through: :forms_roles end \ No newline at end of file diff --git a/app/models/forms_role.rb b/app/models/forms_role.rb index 5cfa688..b3a5f7b 100644 --- a/app/models/forms_role.rb +++ b/app/models/forms_role.rb @@ -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 diff --git a/app/models/user.rb b/app/models/user.rb index 44eb338..d890566 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 \ No newline at end of file diff --git a/app/views/devise/sessions/new.html.erb b/app/views/devise/sessions/new.html.erb index 27f726b..7703e26 100644 --- a/app/views/devise/sessions/new.html.erb +++ b/app/views/devise/sessions/new.html.erb @@ -3,7 +3,7 @@

Log in

- <%= 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| %>
<%= f.label :email, class: 'form-label' %> <%= f.email_field :email, autofocus: true, autocomplete: "email", class: 'form-control', placeholder: 'Enter email' %> diff --git a/app/views/devise/shared/_links.html.erb b/app/views/devise/shared/_links.html.erb index 800cb2b..04b6fab 100644 --- a/app/views/devise/shared/_links.html.erb +++ b/app/views/devise/shared/_links.html.erb @@ -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' %> diff --git a/app/views/forms/index.html.erb b/app/views/forms/index.html.erb index 25495da..cca703d 100644 --- a/app/views/forms/index.html.erb +++ b/app/views/forms/index.html.erb @@ -21,7 +21,7 @@ <%= form.name %> <%= form.required ? 'Required' : 'Optional' %> <%= form.program %> - <%= form.roles.map(&:name).join(", ") %> + <%= form.form_roles.map(&:name).join(", ") %> <%= link_to edit_form_path(form), class: 'btn btn-info btn-sm' do %> diff --git a/db/migrate/20240402213505_rename_role_to_form_role.rb b/db/migrate/20240402213505_rename_role_to_form_role.rb new file mode 100644 index 0000000..363af28 --- /dev/null +++ b/db/migrate/20240402213505_rename_role_to_form_role.rb @@ -0,0 +1,5 @@ +class RenameRoleToFormRole < ActiveRecord::Migration[7.1] + def change + rename_table :roles, :form_roles + end +end diff --git a/db/migrate/20240402214014_fix_form_role_id_in_forms_roles.rb b/db/migrate/20240402214014_fix_form_role_id_in_forms_roles.rb new file mode 100644 index 0000000..e21a58c --- /dev/null +++ b/db/migrate/20240402214014_fix_form_role_id_in_forms_roles.rb @@ -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 \ No newline at end of file diff --git a/db/schema.rb b/db/schema.rb index aaf8e65..1fc644d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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"