diff --git a/app/controllers/assignments_controller.rb b/app/controllers/assignments_controller.rb index 48b2a5c4..57060720 100644 --- a/app/controllers/assignments_controller.rb +++ b/app/controllers/assignments_controller.rb @@ -1,4 +1,5 @@ class AssignmentsController < ApplicationController + before_action :require_user! before_action :set_assignment, only: %i[ show edit update destroy ] # GET /assignments or /assignments.json @@ -65,6 +66,6 @@ def set_assignment # Only allow a list of trusted parameters through. def assignment_params - params.require(:assignment).permit(:user_id, :project_id, :proposed, :status) + params.require(:assignment).permit(:user_id, :project_id, :status) end end diff --git a/app/controllers/clients_controller.rb b/app/controllers/clients_controller.rb index d4780c6e..a0ec8e66 100644 --- a/app/controllers/clients_controller.rb +++ b/app/controllers/clients_controller.rb @@ -1,4 +1,5 @@ class ClientsController < ApplicationController + before_action :require_user! before_action :set_client, only: %i[ show edit update destroy ] # GET /clients or /clients.json diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 5bed1361..942ee10c 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -1,9 +1,10 @@ class ProjectsController < ApplicationController + before_action :require_user! before_action :set_project, only: %i[ show edit update destroy ] # GET /projects or /projects.json def index - @projects = Project.all + @projects = Project.includes(:company). all end # GET /projects/1 or /projects/1.json @@ -65,6 +66,6 @@ def set_project # Only allow a list of trusted parameters through. def project_params - params.require(:project).permit(:client_id, :name, :status, :company_id, :proposed, :cost, :payment_frequency) + params.require(:project).permit(:client_id, :name, :status, :cost, :payment_frequency) end end diff --git a/app/controllers/work_weeks_controller.rb b/app/controllers/work_weeks_controller.rb index 9d471dd0..32f61050 100644 --- a/app/controllers/work_weeks_controller.rb +++ b/app/controllers/work_weeks_controller.rb @@ -1,4 +1,5 @@ class WorkWeeksController < ApplicationController + before_action :require_user! before_action :set_work_week, only: %i[ show edit update destroy ] # GET /work_weeks or /work_weeks.json diff --git a/app/models/assignment.rb b/app/models/assignment.rb index 4afc1577..36841273 100644 --- a/app/models/assignment.rb +++ b/app/models/assignment.rb @@ -3,7 +3,9 @@ class Assignment < ApplicationRecord belongs_to :project has_many :work_weeks, dependent: :destroy + VALID_STATUSES = %w(proposed active archived completed).freeze + validates :user_id, presence: true, uniqueness: { scope: :project_id } validates :project_id, presence: true, uniqueness: { scope: :user_id } - validates :status, presence: true, inclusion: { in: %w(proposed active archived completed) } + validates :status, presence: true, inclusion: { in: VALID_STATUSES } end diff --git a/app/models/client.rb b/app/models/client.rb index e3476797..1a42ae53 100644 --- a/app/models/client.rb +++ b/app/models/client.rb @@ -2,7 +2,12 @@ class Client < ApplicationRecord belongs_to :company has_many :projects, dependent: :destroy + VALID_STATUSES = %w(active archived).freeze + validates :company_id, presence: true, uniqueness: { scope: :name } validates :name, presence: true, uniqueness: { scope: :company_id } - validates :status, presence: true, inclusion: { in: %w(active archived) } + validates :status, presence: true, inclusion: { in: VALID_STATUSES } + + scope :active, -> { where(status: 'active') } + scope :archived, -> { where(status: 'archived') } end diff --git a/app/models/project.rb b/app/models/project.rb index 439221ee..1921a6c8 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -5,9 +5,12 @@ class Project < ApplicationRecord has_many :users, through: :assignments has_many :work_weeks, through: :assignments, dependent: :destroy + VALID_STATUSES = %w(proposed active archived cancelled completed).freeze + VALID_PAYMENT_FREQUENCIES = %w(weekly monthly fortnightly quarterly annually).freeze + validates :client_id, presence: true validates :name, presence: true, uniqueness: { case_sensitive: false } - validates :status, presence: true, inclusion: { in: %w(proposed active archived cancelled completed) } + validates :status, presence: true, inclusion: { in: VALID_STATUSES } validates :cost, presence: true, numericality: { greater_than_or_equal_to: 0.0 } - validates :payment_frequency, presence: true, inclusion: { in: %w(weekly monthly fortnightly quarterly annually) } + validates :payment_frequency, presence: true, inclusion: { in: VALID_PAYMENT_FREQUENCIES } end diff --git a/app/views/assignments/_assignment.html.erb b/app/views/assignments/_assignment.html.erb index 6da2f6d1..55b7ec96 100644 --- a/app/views/assignments/_assignment.html.erb +++ b/app/views/assignments/_assignment.html.erb @@ -9,11 +9,6 @@ <%= assignment.project_id %>
-- Proposed: - <%= assignment.proposed %> -
-Status: <%= assignment.status %> diff --git a/app/views/assignments/_form.html.erb b/app/views/assignments/_form.html.erb index a80544a6..d43ea039 100644 --- a/app/views/assignments/_form.html.erb +++ b/app/views/assignments/_form.html.erb @@ -13,22 +13,17 @@
Company: - <%= project.company_id %> -
- -- Proposed: - <%= project.proposed %> + <%= project.company.id %>
diff --git a/app/views/work_weeks/_form.html.erb b/app/views/work_weeks/_form.html.erb index d973b8b6..084539a2 100644 --- a/app/views/work_weeks/_form.html.erb +++ b/app/views/work_weeks/_form.html.erb @@ -33,7 +33,7 @@