Skip to content
This repository has been archived by the owner on Dec 10, 2017. It is now read-only.

Commit

Permalink
Merge pull request #41 from compserv/kevin/pres_admin
Browse files Browse the repository at this point in the history
Kevin/pres admin
  • Loading branch information
alancyao committed Jan 17, 2014
2 parents 5dd4747 + b6f259e commit 32111d2
Show file tree
Hide file tree
Showing 38 changed files with 298 additions and 108 deletions.
2 changes: 1 addition & 1 deletion app/assets/stylesheets/candidate.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ ul.semi-plain{
text-indent: 0px;
}

#description {
#challenge_description {
width: 178px;
height: 50px;
}
6 changes: 6 additions & 0 deletions app/controllers/admin/pres_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Admin::PresController < ApplicationController
before_filter :authenticate_pres!

def index
end
end
5 changes: 5 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ def active_member_authorize
user_session[:current_comm].nil? ? user_session[:current_comm] = current_user.is_active_member? : user_session[:current_comm]
end

def currently_candidate?
return unless current_user
user_session[:current_cand].nil? ? user_session[:current_cand] = current_user.is_currently_candidate? : user_session[:current_cand]
end

def get_num_deprel_requests
return unless current_user
user_session[:deptTour_number].nil? ? user_session[:deptTour_number] = DeptTour.all.count.to_s : user_session[:deptTour_number]
Expand Down
34 changes: 31 additions & 3 deletions app/controllers/candidate_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,42 @@ class CandidateController < ApplicationController
before_filter :is_candidate?

def is_candidate?
unless current_user.has_role? :candidate, MemberSemester.current
unless currently_candidate?
flash[:notice] = "You're not a candidate, so this information may not apply to you"
end
end

def portal
@challenges = Challenge.all
@announcements = Announcement.all
@events = Event.with_permission(current_user).where('end_time >= ? AND end_time <= ?', Time.now, Time.now + 7.days).order(:start_time)
@challenges = Challenge.where(candidate_id: current_user.id)
@announcements = Announcement.all.limit(10)
set_up_status_and_my_events
set_up_done
end

def set_up_status_and_my_events
req = Hash.new { |h,k| 0 }
req["Mandatory for Candidates"] = 3
req["Fun"] = 3
req["Big Fun"] = 1
req["Service"] = 2
@my_events = current_user.events.group_by(&:event_type)
@my_confirmed_events = current_user.events.joins(:rsvps).where('rsvps.confirmed = ?', 't').group_by(&:event_type)
@status = {}
req.each do |event_type, count_required|
@my_events[event_type] ||= []
@my_confirmed_events[event_type] ||= [] # prevent nil exceptions
@status[event_type] = (@my_confirmed_events[event_type].count >= count_required)
end
end

def set_up_done
@done = Hash.new(false)
@done["events"] = !@status.has_value?(false)
@done["challenges"] = @challenges.where(confirmed: true).count >= 5
@done["resume"] = !current_user.resume.nil?
@done["quiz"] = !current_user.candidate_quiz.nil?
@done["forms"] = @done["resume"] and @done["quiz"]
end

def quiz
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/challenges_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class ChallengesController < ApplicationController
before_filter :is_candidate?, only: [:index, :update]

def is_candidate?
if current_user.has_role? :candidate, MemberSemester.current
if currently_candidate?
redirect_to root_path, notice: "Oops, a candidate shouldn't be here"
end
end
Expand Down
57 changes: 47 additions & 10 deletions app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def index
else
order = "start_time"
end

event_filter = params[:event_filter] || "none"
params[:sort_direction] ||= (params[:category] == 'past') ? 'down' : 'up'

Expand All @@ -23,23 +23,22 @@ def index
event_finder = Event.with_permission(current_user)

if category == 'past'
@events = event_finder.past
event_finder = event_finder.past
@heading = "Past Events"
elsif category == 'future'
@events = event_finder.upcoming
event_finder = event_finder.upcoming
@heading = "Upcoming Events"
else
@events = event_finder
@heading = "All Events"
end
if event_filter != "none"
@events = @events.where('lower(event_type) = ?', event_filter)
event_finder = event_finder.where('lower(event_type) = ?', event_filter)
end

# Maintains start_time as secondary sort column
ord = "#{order} #{sort_direction}, start_time #{sort_direction}"
options = { :page => params[:page], :per_page => 20 }
@events = @events.order(ord).paginate options
@events = event_finder.order(ord).paginate options

respond_to do |format|
format.html # index.html.erb
Expand All @@ -65,7 +64,7 @@ def create
format.html { redirect_to(@event, :notice => 'Event was successfully created.') }
format.xml { render :xml => @event, :status => :created, :location => @event }
else
format.html { render :action => "new" }
format.html { render :new }
format.xml { render :xml => @event.errors, :status => :unprocessable_entity }
end
end
Expand All @@ -79,7 +78,7 @@ def update
format.html { redirect_to(@event, :notice => 'Event was successfully updated.') }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.html { render :edit }
format.xml { render :xml => @event.errors, :status => :unprocessable_entity }
end
end
Expand Down Expand Up @@ -125,7 +124,7 @@ def show
def calendar
month = (params[:month] || Time.now.month).to_i
year = (params[:year] || Time.now.year).to_i
@start_date = Date.new(year, month, 1)
@start_date = Date.new(year, month, 1)
@end_date = Date.new(year, month, 1).end_of_month
@events = Event.with_permission(current_user).select { |event| (@start_date.to_time..@end_date.at_end_of_day).cover? event.start_time }.sort_by { |event| event.start_time }
@event_types = Event.pluck(:event_type)
Expand Down Expand Up @@ -171,13 +170,51 @@ def confirm_rsvps
@rsvps = @event.rsvps.joins(:user).where("users.id in (?)", users).sort_by { |rsvp| rsvp.user.full_name }
end

def leaderboard
@semester = params[:semester] ? MemberSemester.find_by_id(params[:semester]) : MemberSemester.current
@users = Role.members.semester_filter(@semester).all_users
@users_array = []
#moar_people = [ 'eunjian' ].collect{|u|Person.find_by_username(u)} # TODO remove when we have leaderboard opt-in
@users.each do |user|
# Makeshift data structure
events = user.rsvps.where(confirmed: 't').joins(:event).where("events.start_time > ? AND events.start_time < ?", @semester.start_time, @semester.end_time)
@users_array << {
:user => user,
:total => events.count,
:events => events
}
end

@users_array.each do |entry|
entry[:big_fun] = entry[:events].where("events.event_type = ? ", "Big Fun").count
entry[:fun] = entry[:events].where("events.event_type = ? ", "Fun").count
entry[:service] = entry[:events].where("events.event_type = ? ", "Service").count
entry[:score] = 2*entry[:big_fun] + entry[:fun] + 3*entry[:service]
end

@users_array.sort!{|a,b| a[:score] <=> b[:score]}
@users_array.reverse!
rank = 0
last_num = -1
incr = 1
@users_array.each do |entry|
if last_num != entry[:score]
rank += incr
last_num = entry[:score]
incr = 0
end
entry[:rank] = rank
incr += 1
end
end

private
def event_authorize
@event_auth = comm_authorize
end

def event_params
params.require(:event).permit(:title, :description, :location, :start_time, :end_time, :event_type,
:view_permission_roles, :rsvp_permission_roles, :max_rsvps, :need_transportation?)
:view_permission_roles, :rsvp_permission_roles, :max_rsvps, :need_transportation)
end
end
2 changes: 1 addition & 1 deletion app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class PagesController < ApplicationController
#tocache.each {|a| caches_action a, :layout => false}

def home
#@events = Event.upcoming_events(0, @current_user)
@events = Event.with_permission(current_user).where('end_time >= ? AND end_time <= ?', Time.now, Time.now + 7.days).order(:start_time)
@show_searcharea = true
#prop = Property.get_or_create
#@tutoring_enabled = prop.tutoring_enabled
Expand Down
13 changes: 6 additions & 7 deletions app/controllers/rsvps_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def create
format.html { redirect_to(@event, :notice => 'Thanks for RSVPing! See you there!') }
format.xml { render :xml => @rsvp, :status => :created, :location => @rsvp }
else
format.html { render :action => "new" }
format.html { render :new }
format.xml { render :xml => @rsvp.errors, :status => :unprocessable_entity }
end
end
Expand All @@ -72,7 +72,7 @@ def update
format.html { redirect_to(@event, :notice => 'Rsvp was successfully updated.') }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.html { render :edit }
format.xml { render :xml => @rsvp.errors, :status => :unprocessable_entity }
end
end
Expand All @@ -92,10 +92,10 @@ def destroy

def confirm

role = params[:role] || :candidate
role = params[:role] || :candidates

respond_to do |format|
if @rsvp.update_attribute :confirmed, Rsvp::Confirmed
if @rsvp.update_attributes(confirmed: Rsvp::Confirmed, confirmed_by: current_user.id, confirmed_at: Time.now)
format.html { redirect_to(confirm_rsvps_path(@rsvp.event_id, :role => role), :notice => 'Rsvp was confirmed.') }
format.xml { render :xml => @rsvp }
else
Expand All @@ -106,7 +106,7 @@ def confirm
end

def unconfirm
@rsvp.update_attribute :confirmed, Rsvp::Unconfirmed
@rsvp.update_attributes(confirmed: Rsvp::Unconfirmed, confirmed_by: current_user.id, confirmed_at: Time.now)
role = params[:role] || "candidates"

respond_to do |format|
Expand All @@ -116,8 +116,7 @@ def unconfirm
end

def reject
@rsvp.update_attribute :confirmed, Rsvp::Rejected

@rsvp.update_attributes(confirmed: Rsvp::Rejected, confirmed_by: current_user.id, confirmed_at: Time.now)
role = params[:role] || "candidates"

respond_to do |format|
Expand Down
9 changes: 5 additions & 4 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ def list

opts = { page: params[:page], per_page: params[:per_page] || 20 }
ord = "users." + params["sort"] + " " + sort_direction
joinstr = 'INNER JOIN "users_roles" ON "users_roles"."user_id" = "users"."id" INNER JOIN "roles" ON "roles"."id" = "users_roles"."role_id"' # this looks terribad...
joinstr = 'INNER JOIN "users_roles" ON "users_roles"."user_id" = "users"."id" INNER JOIN "roles" ON "roles"."id" = "users_roles"."role_id"'

user_selector = User.uniq(:id)
if authenticate_vp and params[:approved] == 'false'
user_selector = user_selector.where(:approved => false )
@users = user_selector.where(approved: false).paginate opts
else
@users = user_selector.order(ord).joins(joinstr).where(cond).paginate opts
end

@users = user_selector.order(ord).joins(joinstr).where(cond).paginate opts

respond_to do |format|
format.html
format.js {
Expand All @@ -109,6 +109,7 @@ def list
def approve
authenticate_vp! # current user must at least be vp to approve
if @user.update(approved: true)
@user.add_position_for_semester_and_role_type(:candidate, MemberSemester.current, :candidate)
flash[:notice] = "Successfully approved #{@user.full_name}, an email has been sent to #{@user.email}"
AccountMailer.account_approval(@user).deliver
else
Expand Down
2 changes: 0 additions & 2 deletions app/helpers/companies_helper.rb

This file was deleted.

2 changes: 0 additions & 2 deletions app/helpers/events_helper.rb

This file was deleted.

2 changes: 0 additions & 2 deletions app/helpers/indrel_event_types_helper.rb

This file was deleted.

2 changes: 0 additions & 2 deletions app/helpers/notifications_helper.rb

This file was deleted.

2 changes: 0 additions & 2 deletions app/helpers/resume_book_urls_helper.rb

This file was deleted.

23 changes: 10 additions & 13 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
# start_time :datetime
# end_time :datetime
# event_type :string(255)
# need_transportation? :boolean
# need_transportation :boolean
# view_permission_roles :string(255)
# rsvp_permission_roles :string(255)
# max_rsvps :integer
#

class Event < ActiveRecord::Base
EVENT_TYPES = ["Big Fun", "Fun", "Industry", "Mandatory for Candidates", "Miscellaneous", "Service"]
EVENT_TYPES = ["Big Fun", "Fun", "Industry", "Mandatory for Candidates", "Miscellaneous", "Service", "Exam", "Review Session"]
PERMISSION_OPTIONS = [["Candidates and Members", "candidates"], ["Officers and Committee Members", "committee_members"], ["Officers", "officers"], ["Members", 'members'], ["Everyone", nil]]
has_many :rsvps, dependent: :destroy
has_many :users, through: :rsvps

Expand All @@ -30,24 +31,20 @@ class Event < ActiveRecord::Base
validates :start_time, :presence => true
validates :end_time, :presence => true
validates :max_rsvps, presence: true, numericality: { greater_than_or_equal_to: 0 }
validates_inclusion_of :rsvp_permission_roles, in: ['candidates', 'committee_members', 'officers', nil]
validates_inclusion_of :view_permission_roles, in: ['candidates', 'committee_members', 'officers', nil]
validates_inclusion_of :rsvp_permission_roles, in: PERMISSION_OPTIONS.collect(&:last)
validates_inclusion_of :view_permission_roles, in: PERMISSION_OPTIONS.collect(&:last)
validates_inclusion_of :event_type, in: EVENT_TYPES

def self.permission_options
[["Candidates and Members", "candidates"], ["Committee Members", "committee_members"],
["Officers", "officers"], ["Everyone", nil]]
end

scope :with_permission, Proc.new { |user|
scope :with_permission, Proc.new { |user|
if user.nil?
where(:view_permission_roles => nil)
elsif user.is_officer_for_semester? MemberSemester.current
all
#if user is member?
elsif user.is_active_member?
where(view_permission_roles: %w[candidates committee_members nil])
elsif user.is_candidate?
where(view_permission_roles: %w[candidates members committee_members nil])
elsif user.is_member?
where(view_permission_roles: %w[candidates members nil])
elsif user.is_currently_candidate?
where(view_permission_roles: %w[candidates nil])
else
where(:view_permission_roles => nil)
Expand Down
16 changes: 16 additions & 0 deletions app/models/member_semester.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,20 @@ def prev
MemberSemester.find_by_year_and_season(year, "Spring")
end
end

def start_time
if season == "Spring"
Date.civil(year)
else
Date.civil(year, 8)
end
end

def end_time
if season == "Spring"
Date.civil(year, 6)
else
Date.civil(year, 12, 30)
end
end
end
5 changes: 3 additions & 2 deletions app/models/role.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class Role < ActiveRecord::Base
@Committees = %w(pres vp rsec treas csec deprel act alumrel bridge compserv indrel serv studrel tutoring pub examfiles ejc) #This generates a constant which is an array of possible committees.
Positions = %w(officer committee_member candidate) # A list of possible positions
Positions = %w(officer committee_member candidate member) # A list of possible positions
Execs = %w(pres vp rsec csec treas deprel) # Executive positions
NonExecs = @Committees-Execs

Expand Down Expand Up @@ -121,7 +121,8 @@ def nice_committee
"tutoring" => "Tutoring",
"pub" => "Publicity",
"examfiles"=> "Exam Files",
"candidate"=> ""
"candidate"=> "",
"member" => ""
}
nice_committees[name]
end
Expand Down
Loading

0 comments on commit 32111d2

Please sign in to comment.