Permalink
Browse files

Merge branch 'admissions'

  • Loading branch information...
2 parents 027d1f3 + 79d8059 commit 582d66e1841c17e0413ee0b5178294eb66baaf6e @jordanbyron jordanbyron committed Mar 15, 2011
@@ -0,0 +1,33 @@
+class Admissions::SubmissionsController < ApplicationController
+ skip_before_filter :authenticate_user!, :only => [:new, :create]
+ skip_before_filter :change_password_if_needed, :only => [:new, :create]
+
+ def index
+ @submissions = Admissions::Submission.order("created_at")
+
+ render :text => "todo"
+ end
+
+ def new
+ @user = User.new
+ @user.admissions_submission = Admissions::Submission.new
+ end
+
+ def create
+ @user = User.new(params[:user])
+ @user.admissions_submission ||= Admissions::Submission.new
+
+ if @user.save
+ @user.update_attribute(:requires_password_change, false)
+ @user.update_attribute(:access_level, "applicant")
+
+ flash[:notice] = "Your application has been sucessfully created!"
+
+ sign_in(@user)
+
+ redirect_to dashboard_path
+ else
+ render :action => :new
+ end
+ end
+end
@@ -1,6 +1,6 @@
class UsersController < ApplicationController
skip_before_filter :change_password_if_needed
- before_filter lambda { @selected = :directory }, :except => [:edit, :update, :change_password]
+ before_filter :check_permissions, :except => [:edit, :update, :change_password]
def index
@users = User.search(params[:search], params[:page],
@@ -38,4 +38,15 @@ def change_password
flash[:alert] = current_user.errors.full_messages.to_sentence
end
end
+
+ private
+
+ def check_permissions
+ return if params[:id] && User.find(params[:id]) == current_user
+
+ unless current_access_level.allows? :view_directory
+ flash[:error] = "Your account does not have access to this area"
+ redirect_to dashboard_path
+ end
+ end
end
@@ -0,0 +1,2 @@
+module Admissions::SubmissionsHelper
+end
View
@@ -0,0 +1,5 @@
+module Admissions
+ def self.table_name_prefix
+ 'admissions_'
+ end
+end
@@ -0,0 +1,2 @@
+class Admissions::Status < ActiveRecord::Base
+end
@@ -0,0 +1,44 @@
+class Admissions::Submission < ActiveRecord::Base
+ after_create :save_attachment
+ before_destroy :delete_attachment
+
+ belongs_to :status, :class_name => "Admissions::Status"
+ belongs_to :user
+ belongs_to :course
+
+ has_many :comments, :as => :commentable,
+ :dependent => :delete_all
+
+ def attachment=(tempfile)
+ @tempfile = tempfile
+ end
+
+ def attachment
+ File.join(attachment_dir, self.id.to_s + '.zip')
+ end
+
+ def attachment_dir
+ File.join(Rails.root, 'public', 'admissions', 'submissions')
+ end
+
+ private
+
+ def save_attachment
+ FileUtils.mkdir_p(attachment_dir)
+ File.open(attachment, "wb") { |f| f.write(@tempfile.read) }
+ end
+
+ def delete_attachment
+ FileUtils.rm(attachment)
+ end
+
+ def validate
+ if new_record?
+ if @tempfile.blank?
+ errors.add("attachment", "must be present")
+ elsif !File.basename(@tempfile.original_filename)[/.zip/]
+ errors.add("attachment", "should be a zip file")
+ end
+ end
+ end
+end
@@ -6,6 +6,7 @@ class Assignment::Submission < ActiveRecord::Base
has_many :comments, :as => :commentable,
:dependent => :delete_all
+
has_many :activities, :dependent => :delete_all
def create_comment(comment_data)
View
@@ -21,6 +21,8 @@ class User < ActiveRecord::Base
:format => GITHUB_FORMAT
validate :real_name_or_nick_name_required
+
+ validates_presence_of :github_account_name
has_many :chat_channel_memberships, :class_name => "Chat::ChannelMembership"
@@ -36,6 +38,10 @@ class User < ActiveRecord::Base
has_many :course_instructor_associations, :foreign_key => "instructor_id"
has_many :comments, :as => :commentable
+ has_one :admissions_submission, :class_name => "Admissions::Submission",
+ :dependent => :destroy
+ accepts_nested_attributes_for :admissions_submission
+
attr_protected :access_level, :alumni_number, :alumni_month, :alumni_year
has_one :alumni_preferences
@@ -0,0 +1,24 @@
+#admissions
+ +container
+
+ #application
+ +column(10)
+
+ form
+ display: block
+ padding: 1em
+ background-color: #eee
+ width: 315px
+ +border-radius(3px)
+ +box-shadow(#aaa, 0px, 1px, 1px, inset)
+
+ hr.ruler
+ width: 310px
+
+ span.label
+ display: block
+ color: #777
+ #instructions
+ +column(14, true)
+ &:first-child, h3
+ margin-top: 0
@@ -79,7 +79,6 @@ form.bp
margin: 0 0 0 129px
input.text, input.title, input[type="email"], input[type="text"], input[type="password"]
-
color: #555
select
@@ -121,6 +120,25 @@ form.bp
width: auto
&:after
content: ""
+
+ &.inline
+ p, div.field_with_errors
+ position: relative
+
+ input[type="submit"]
+ width: 100%
+
+ label
+ text-align: left
+ &.infield
+ position: absolute
+ top: 1em
+ left: 4px
+ color: #777
+ display: inline-block
+ width: auto
+ &:after
+ content: none
form.search
p
@@ -24,6 +24,7 @@
@import "partials/pagination"
@import "partials/tabs"
@import "partials/logs"
+@import "partials/admissions"
h1, h2, h3
margin: 1em 0
@@ -0,0 +1,61 @@
+- content_for :header_bottom do
+ :javascript
+ $(function(){
+ jQuery("label.infield").inFieldLabels();
+ });
+
+#admissions
+
+ %h1 Application for Admission
+
+ #application
+ = form_for @user, :url => admissions_submissions_path,
+ :html => {:class => 'bp inline', :multipart => true} do |f|
+ = error_messages_for(@user)
+
+ %p
+ = f.label :email, :class => "infield"
+ = f.text_field :email
+
+ %p
+ = f.label :real_name, :class => "infield"
+ = f.text_field :real_name
+
+ %p
+ = f.label :nickname, :class => "infield"
+ = f.text_field :nickname
+
+ %p
+ = f.label :password, :class => "infield"
+ = f.password_field :password
+
+ %p
+ = f.label :password_confirmation, :class => "infield"
+ = f.password_field :password_confirmation
+
+ %hr.ruler
+
+ %p
+ = f.label :github_account_name, "Github name", :class => "infield"
+ = f.text_field :github_account_name
+
+ %p
+ = f.label :twitter_account_name, "Twitter name", :class => "infield"
+ = f.text_field :twitter_account_name
+
+ %hr.ruler
+
+ = f.fields_for :admissions_submission do |s|
+ %p
+ %span.label Puzzlenode zip file
+ = s.file_field :attachment
+
+ %hr.ruler
+
+ %p
+ = f.submit "Submit Application", :class => "clean"
+
+ .clear
+
+ #instructions
+ %h3 These are the instructions for the zip file
@@ -5,21 +5,23 @@
%li
= link_to "Dashboard", dashboard_path, :class => "first"
= selected_arrow(:dashboard)
- %li#courses
- = link_to "Courses".html_safe + image_tag("down_arrow.png", :class => "drop"), '#'
- = selected_arrow(:courses)
- #courses_dropdown
- %ul
- - current_user.courses.active.group_by(&:term).each do |term, courses|
- - if term
- %li.term= term.name
- - courses.each do |course|
- %li= link_to course.name, course_path(course)
- - if current_user.courses.archived.any?
- %li.small= link_to "Archived Courses", courses_path
- %li
- = link_to "Directory", users_path
- = selected_arrow(:directory)
+ - if current_access_level.allows? :view_courses
+ %li#courses
+ = link_to "Courses".html_safe + image_tag("down_arrow.png", :class => "drop"), '#'
+ = selected_arrow(:courses)
+ #courses_dropdown
+ %ul
+ - current_user.courses.active.group_by(&:term).each do |term, courses|
+ - if term
+ %li.term= term.name
+ - courses.each do |course|
+ %li= link_to course.name, course_path(course)
+ - if current_user.courses.archived.any?
+ %li.small= link_to "Archived Courses", courses_path
+ - if current_access_level.allows? :view_directory
+ %li
+ = link_to "Directory", users_path
+ = selected_arrow(:directory)
- if current_access_level.allows? :manage_users
%li#administration
= link_to "Administration".html_safe + image_tag("down_arrow.png", :class => "drop"), '#'
@@ -37,9 +39,7 @@
%li= link_to "Broadcast Emails", new_admin_group_mail_path
- else
%li
- %a.first{:href => "/"} Home
- %li
- = link_to "Sign in", new_user_session_path
+ = link_to "Sign in", new_user_session_path, :class => "first"
:javascript
DropdownMenu.register('courses');
DropdownMenu.register('administration');
@@ -2,10 +2,11 @@
define "guest",
:permissions => []
- define "student",
- :permissions => [:do_stuff]
+ define "student",
+ :permissions => [:view_directory, :view_courses]
- define "admin",
+ define "admin",
+ :parent => "student",
:permissions => [:manage_users, :manage_documents]
end
View
@@ -78,10 +78,8 @@
resources :comments
- # TODO Remove these routes and replace with Exam#hash_url
- #get "exams/#{ENTRANCE_EXAM_HASH}" => 'exams#entrance',
- # :as => 'entrance_exam'
- #post "exams/#{ENTRANCE_EXAM_HASH}" => 'exams#submit_exam',
- # :as => 'submit_entrance_exam'
+ namespace :admissions do
+ resources :submissions
+ end
end
@@ -0,0 +1,15 @@
+class CreateAdmissionsSubmissions < ActiveRecord::Migration
+ def self.up
+ create_table :admissions_submissions do |t|
+ t.belongs_to :user
+ t.belongs_to :status
+ t.belongs_to :course
+
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :admissions_submissions
+ end
+end
@@ -0,0 +1,15 @@
+class CreateAdmissionsStatuses < ActiveRecord::Migration
+ def self.up
+ create_table :admissions_statuses do |t|
+ t.text :name
+ t.integer :sort_order
+ t.string :hex_color
+
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :admissions_statuses
+ end
+end
Oops, something went wrong.

0 comments on commit 582d66e

Please sign in to comment.