diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 91b8086..c79039a 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -1,5 +1,7 @@ class HomeController < ApplicationController def index - + if current_user.is_employer + redirect_to employer_home_path + end end end \ No newline at end of file diff --git a/app/controllers/resume_controller.rb b/app/controllers/resume_controller.rb index 76e8c48..b621ab5 100644 --- a/app/controllers/resume_controller.rb +++ b/app/controllers/resume_controller.rb @@ -4,58 +4,41 @@ class ResumeController < ApplicationController skip_before_filter :authenticate_user!, :only => [:index, :show] def index - @posts = current_user ? (current_user.is_admin? ? Post.all : (Post.published + current_user.posts)) : Post.published + @resume = current_user.resume end def new - @post = Post.new + @resume = Resume.new end def create - post = Post.new + resume = Resume.new @errors = [] ActiveRecord::Base.transaction do - update_new_post post, params["resume"] + update_new_resume resume, params["resume"] end redirect_to create_redirector_path if @errors.blank? end - - def published - @posts = Post.published - end - - def drafts - @posts = Post.drafts - end - - def publish_draft - post = Post.find(params["post_id"].to_i) - post.draft = false - post.save! - flash[:success] = "The article has been successfully published." - redirect_to posts_drafts_path - end - def show - post = Post.find(params["id"].to_i) - render :partial => "show_post", :locals => {:resume => post} + resume = Resume.find(params["id"].to_i) + render :partial => "show_resume", :locals => {:resume => resume} end private - def update_new_post post, new_post_hash - post.update_attributes(new_post_hash) - if post.errors.blank? - post.owner_id = current_user.id - current_user.can_publish? ? (post.draft = false) : (post.draft = true) - post.save! + def update_new_resume resume, new_resume_hash + Resume.update_attributes(new_resume_hash) + if Resume.errors.blank? + Resume.owner_id = current_user.id + current_user.can_publish? ? (Resume.draft = false) : (Resume.draft = true) + Resume.save! else - @errors = post.errors.full_messages + @errors = Resume.errors.full_messages @errors.each do |e| flash[:error] = e end - redirect_to new_post_path + redirect_to new_resume_path end end end \ No newline at end of file diff --git a/app/models/role.rb b/app/models/role.rb index be852c3..4828b44 100644 --- a/app/models/role.rb +++ b/app/models/role.rb @@ -1,4 +1,4 @@ class Role < ActiveRecord::Base - has_many :users + has_and_belongs_to_many :users has_and_belongs_to_many :permissions end diff --git a/app/models/user.rb b/app/models/user.rb index 724467f..9a62d3f 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -23,11 +23,8 @@ class User < ActiveRecord::Base :presence => true, :format => { with: VALID_PHONE_REGEX } - scope :get_all_employers, lambda{Role.find_by(:name => "employer").users.pluck(:name)} - - def has_permission? perm - self.permissions.pluck(:name).include? perm - end + scope :get_all_employers, lambda{Role.find_by(:name => "Employer").users.pluck(:name)} + scope :get_all_jobseekers, lambda{Role.find_by(:name => "Jobseeker").users.pluck(:name)} def has_role? role self.roles.include? role @@ -37,7 +34,21 @@ def is_admin? self.has_permission? "application_admin" end - def can_post? - self.has_permission? "can_post" + def can_publish? + self.has_permission? "can_publish" + end + + def can_apply_to_job? + self.has_permission? "can_apply" + end + + private + + ## + # Function: Checks the permissions of the user against the requested permissions + # Returns: TRUE if permission exists else FALSE + ## + def has_permission? perm + self.permissions.pluck(:name).include? perm end end diff --git a/app/views/admin/home/index.html.erb b/app/views/admin/home/index.html.erb index 07853f1..c589653 100644 --- a/app/views/admin/home/index.html.erb +++ b/app/views/admin/home/index.html.erb @@ -2,4 +2,4 @@