Skip to content

Commit

Permalink
Some changes to get app working.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shanil Puri committed Sep 23, 2014
1 parent 46614c3 commit 7b0e5a3
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 25 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@ Gemfile.lock

# Ignore the .idea folder generated by RubyMine
.idea/

# Ignore all public assets
/public/*
# Add non-default ignores below
2 changes: 1 addition & 1 deletion app/controllers/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class RegistrationsController < Devise::RegistrationsController

def create
@user = User.create(params["user"])
@user.roles << Role.find_by_name("Reporter")
@user.roles << Role.find_by_name("JobSeeker")
sign_in @user
redirect_to root_path
end
Expand Down
37 changes: 36 additions & 1 deletion app/controllers/user_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,41 @@
class UserController < ApplicationController

##
# Function to list all the users.
# This is to be used by job seekers to list all the employers by name
##
def index
@users = User.all
@users = User.get_all_employers
end

##
# Function for the editing of the used profile.
# Uses the user_params for update.
##
def edit

end

##
# Deletes a user.
# A user may chose to terminate his association with the job portal.
##
def destroy

end

##
# Function to update a resume.
# User model accepts nested resources for resume.
# One to One relationship for Resume and User.
##
def update_resume

end

private

def user_params
params.require(:user).permit(:name, :email, :phone, :resume)
end
end
15 changes: 9 additions & 6 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class User < ActiveRecord::Base
has_and_belongs_to_many :jobs
has_many :permissions, :through => :roles
has_one :resume, :foreign_key => :owner_id
has_one :role
has_and_belongs_to_many :roles

accepts_nested_attributes_for :roles
accepts_nested_attributes_for :skills
Expand All @@ -16,11 +16,14 @@ class User < ActiveRecord::Base
validates :name, presence: true, length: { maximum: 50 }
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
validates :email, presence: true,
format: { with: VALID_EMAIL_REGEX },
uniqueness: { case_sensitive: false }
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 }
:format => { with: VALID_EMAIL_REGEX },
:uniqueness => { case_sensitive: false }
VALID_PHONE_REGEX = /\A\d{3}\d{3}\d{4}\z/
validates :phone,
: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
Expand Down
10 changes: 5 additions & 5 deletions app/views/admin/home/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div><%= link_to "Create New Editor", new_admin_user_path %></div>
<div><%= link_to "View All Users", user_index_path %></div>
<div><%= link_to "View All Drafted Posts", posts_drafts_path %></div>
<div><%= link_to "View All Published Posts", posts_published_path %></div>
<div><%= link_to "Create new post", new_post_path %></div>
<div><%= link_to "Create New Editor", "#" %></div>
<div><%= link_to "View All Users", "#" %></div>
<div><%= link_to "View All Drafted Posts", "#" %></div>
<div><%= link_to "View All Published Posts", "#" %></div>
<div><%= link_to "Create new post", "#" %></div>
4 changes: 2 additions & 2 deletions app/views/home/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div><%= link_to "View All Users", user_index_path %></div>
<div><%= link_to "View Articles", post_index_path %></div>
<% if current_user.can_publish? %>
<div><%= link_to "View All Drafted Posts", posts_drafts_path %></div>
<div><%= link_to "View All Drafted Posts", "#" %></div>
<% end %>
<div><%= link_to "Create new post", new_post_path %></div>
<div><%= link_to "Create new post", "#" %></div>
2 changes: 1 addition & 1 deletion app/views/layouts/_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</ul>
</li>
<% else %>
<li><%= link_to "Guest User", post_index_path %></li>
<li><%= link_to "Guest User", "#" %></li>
<li><%= link_to "Sign in", new_user_session_path %></li>
<% end %>
</ul>
Expand Down
4 changes: 1 addition & 3 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@

resources :user

get "posts/published", :to => "post#published"
get "posts/drafts", :to => "post#drafts"
resources :post do
resources :resume do
get :show_post_body
get :publish_draft
end
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20140922043613_add_phone_to_user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddPhoneToUser < ActiveRecord::Migration
def change
add_column :users, :phone, :integer
end
end
12 changes: 6 additions & 6 deletions lib/tasks/setup.rake
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ task :setup_sample_application => [:environment] do
puts "Application is being prepared. Please wait."
perm_list = ['application_admin', 'can_publish']
perm_list.each do |p|
Permission.find_or_create_by_name(p)
Permission.find_or_create_by(:name => p)
end
role_list = ["Admin", "Editor", "Reporter"]
role_list.each do |r|
Role.find_or_create_by_name(r)
Role.find_or_create_by(:name => (r))
end

Role.find_by_name("Admin").permissions << Permission.all
Role.find_by_name("Editor").permissions << Permission.find_by_name("can_publish")
Role.find_by(:name => "Admin").permissions << Permission.all
Role.find_by(:name => "Editor").permissions << Permission.find_by(:name => "can_publish")

# Create Dummy Admin User
user = User.create(:name => "Puneet Goyal", :email => "puneet.goyal@studypadinc.com", :password => "1234567x", :password_confirmation => "1234567x")
user.roles << Role.find_by_name("Admin")
user = User.create!(:name => "Shanil Puri", :email => "shanil.puri@gmail.com", :phone => 9199860912, :password => "1234567x", :password_confirmation => "1234567x")
user.roles << Role.find_by(:name => "Admin")
puts "==============> Setup is complete. You may now use the application. :)"
end

0 comments on commit 7b0e5a3

Please sign in to comment.