Skip to content

Commit

Permalink
Deadlines enforced
Browse files Browse the repository at this point in the history
  • Loading branch information
reddragon committed Jun 28, 2010
1 parent 770d1cc commit a2f855a
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 18 deletions.
9 changes: 8 additions & 1 deletion app/controllers/dashboard_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def set_timeframes
calendar_events = [ \
{ :name => "Project Creation Timeframe", :dates => ["pct_from", "pct_to"] },\
{ :name => "Proposal Submission Timeframe", :dates => ["pst_from", "pst_to"] },\
{ :name => "Project Application Timeframe", :dates => ["pat_from", "pat_to"] },\
{ :name => "Proposal Acceptance Timeframe", :dates => ["pat_from", "pat_to"] },\
{ :name => "Coding Starts", :dates => ["csd_on", "csd_on"] },\
{ :name => "Mid-Term Evaluation Timeframe", :dates => ["met_from", "met_to"] },\
{ :name =>"Coding Ends", :dates => ["ced_on", "ced_on"] },\
Expand All @@ -64,6 +64,7 @@ def set_timeframes
redirect_to :action => "configure"
end
end
APP_CONFIG['timeframesset'] = "true"
flash[:notice] = "Timeframes successfully set."
redirect_to :action => "configure"
end
Expand All @@ -73,6 +74,12 @@ def configure
flash[:notice] = 'You are not authorized to perform this operation'
redirect_to :controller => "dashboard"
end

if APP_CONFIG['fsocmode'] == "Summer Coding" and\
APP_CONFIG['timeframesset'] == "false"
flash[:notice] = 'FSoC is in Summer Coding mode, but Timeframes
have not yet been set.'
end
end

def task_status
Expand Down
14 changes: 9 additions & 5 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,15 @@ def show
# GET /projects/new.xml
def new
@project = Project.new

respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @project }
end
if !can_create_project?
flash[:notice] = 'You are not authorised to create a project.'
redirect_to projects_url
else
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @project }
end
end
end

# GET /projects/1/edit
Expand Down
2 changes: 2 additions & 0 deletions app/views/dashboard/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
Name
%th
Proposed by
%th
 
- current_user.project_mentorships.each do |project|
%tr
%td
Expand Down
7 changes: 5 additions & 2 deletions app/views/dashboard/proposals.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@
%div{:style => 'clear: both'}  
.entry

- if student?(current_user) && can_view_user_proposal_list?(user)
- if student?(current_user) && can_view_user_proposal_list?(current_user)
%br
= render :partial => "proposals/list", :locals => { :proposals => user.proposals }
= render :partial => "proposals/list", :locals => { :proposals => current_user.proposals }
%br

- if !current_user.project_proposals.empty?
%h3
Expand All @@ -37,6 +38,8 @@
Name
%th
Mentor
%th
 

- current_user.project_proposals.each do |project|
%tr
Expand Down
6 changes: 5 additions & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ Released : 20090910
<li><%= link_to project.name, project %></li>
<% end %>
<% else %>
<li>No Projects listed. <%= link_to 'Create', new_project_path %></li>
<li>No Projects listed.
<% if can_create_project? %>
<%= link_to 'Create', new_project_path %>
<% end %>
</li>
<% end %>
</ul>
</li>
Expand Down
5 changes: 4 additions & 1 deletion app/views/projects/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@
<h3>No projects listed.</h3>
<% end %>
<% if logged_in? %>
<p class="links"><%= link_to 'Write a new project idea', new_project_path %></p>
<p class="links">
<% if can_create_project? %>
<%= link_to 'Write a new project idea', new_project_path %></p>
<% end %>
<% else %>
<p class="links"><%= link_to 'Login', login_path %> or <%= link_to 'Signup', signup_path %> to get started.</p>
<% end %>
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#++

ActionController::Routing::Routes.draw do |map|
#map.calendar '/calendar/dates', :controller => 'calendar', :action => 'dates'
map.calendar '/calendar/:year/:month', :controller => 'calendar', \
:action => 'index', :year => Time.zone.now.year, :month => Time.zone.now.month

Expand Down
25 changes: 17 additions & 8 deletions lib/access_control.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ module AccessControl
#methods for access control for users, projects etc.

protected

def within_timeframe?(timeframe)
APP_CONFIG['fsocmode'] == "Year Round" || (APP_CONFIG[timeframe + "_from"] <= DateTime.now and DateTime.now <= APP_CONFIG[timeframe + "_to"])
end
#user specific
def mentor?(user = current_user)
if user == current_user
Expand All @@ -42,8 +44,12 @@ def admin?(user = current_user)
end

#project specific
def can_create_project?
within_timeframe?("pct")
end

def can_edit_project?(project)
logged_in? && ((current_user == project.proposer && project.status == 'proposed') || \
logged_in? && within_timeframe?("pct") && ((current_user == project.proposer && project.status == 'proposed') || \
current_user == project.mentor || current_user.user_type == 'admin')
end

Expand All @@ -59,16 +65,17 @@ def can_add_proposal?(project)
proposals = project.proposals.find(:all, \
:conditions => {:student_id => current_user.id})
end
student? && proposals.empty? && !(current_user.project)
within_timeframe?("pst") && student? && proposals.empty? && \
!(current_user.project)
end

def can_view_proposal_list?(project)
(mentor? && project.mentor == current_user) || admin?
end

def can_edit_proposal?(proposal)
(student? && proposal.student == current_user && \
proposal.status == 'pending') || admin?
(within_timeframe?("pst") && student? && proposal.student == current_user\
&& proposal.status == 'pending') || admin?
end

def can_view_proposal?(proposal)
Expand All @@ -81,7 +88,8 @@ def can_view_user_proposal_list?(user)
end

def can_accept_proposal?(proposal)
mentor? && proposal.project.mentor == current_user && \
within_timeframe?("pat") && mentor? && \
proposal.project.mentor == current_user && \
!proposal.project.unallocated_tasks.empty? && \
(proposal.status == 'pending' || proposal.status == 'accepted')
end
Expand Down Expand Up @@ -154,8 +162,9 @@ def can_configure?(user = current_user)
#Make available as ActionView helper methods.
def self.included(base)
if base.respond_to? :helper_method
base.send :helper_method, :mentor?, :student?, :admin?
base.send :helper_method, :can_edit_project?, :can_delete_project?
base.send :helper_method, :within_timeframe?, :mentor?, :student?, :admin?
base.send :helper_method, :can_create_project?, :can_edit_project?,\
:can_delete_project?
base.send :helper_method, :can_add_proposal?, :can_edit_proposal?, \
:can_view_proposal_list?, :can_view_user_proposal_list?
base.send :helper_method, :can_accept_proposal?, :can_signoff_proposal?
Expand Down

0 comments on commit a2f855a

Please sign in to comment.