Skip to content

Commit

Permalink
Combine types of user models into just one (use controller to restric…
Browse files Browse the repository at this point in the history
…t based on roles) and add resume model
  • Loading branch information
Druotic authored and Shanil Puri committed Sep 22, 2014
1 parent c62cc4c commit e9f5ee5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 20 deletions.
3 changes: 0 additions & 3 deletions app/models/jobseeker.rb

This file was deleted.

8 changes: 0 additions & 8 deletions app/models/post.rb

This file was deleted.

5 changes: 5 additions & 0 deletions app/models/resume.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Resume < ActiveRecord::Base
belongs_to :jobseekers
validates :title, :presence => true, :length => {:maximum => 128}
validates :body, :presence => true, :length => {:maximum => 10000}
end
23 changes: 14 additions & 9 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
class User < ActiveRecord::Base
has_and_belongs_to_many :roles
has_many :permissions, :through => :roles
has_many :skills
has_and_belongs_to_many :jobs

accepts_nested_attributes_for :roles
accepts_nested_attributes_for :skills

devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :timeoutable

Expand All @@ -9,12 +17,9 @@ class User < ActiveRecord::Base
validates :email, presence: true,
format: { with: VALID_EMAIL_REGEX },
uniqueness: { case_sensitive: false }

has_and_belongs_to_many :roles
has_many :permissions, :through => :roles
has_many :posts, :foreign_key => "owner_id"

accepts_nested_attributes_for :roles
VALID_PHONE_REGEX = /^(\([0-9]{3}\) |[0-9]{3}-|[0-9]{3})[0-9]{3}-[0-9]{4}$/
validates :phone,
format: { with: VALID_PHONE_REGEX }

def has_permission? perm
self.permissions.pluck(:name).include? perm
Expand All @@ -28,7 +33,7 @@ def is_admin?
self.has_permission? "application_admin"
end

def can_publish?
self.has_permission? "can_publish"
def can_post?
self.has_permission? "can_post"
end
end
end

0 comments on commit e9f5ee5

Please sign in to comment.