Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MfSE Spring 2014 Implementation of User Stories add-teaching-assistant-to-course and copying-a-course-does-not-copy-tas #269

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/controllers/courses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ def update
@course.configured_by_user_id = current_user.id
end

if (params[:teaching_assistants])
params[:course][:teaching_assistant_assignments_override] = params[:teaching_assistants]
end

params[:course][:faculty_assignments_override] = params[:teachers]
respond_to do |format|
@course.updated_by_user_id = current_user.id if current_user
Expand Down
14 changes: 7 additions & 7 deletions app/controllers/deliverables_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def grading_queue_for_course
# @assignments = Assignment.where(:course_id => @course.id).all.sort_by(&:task_number)


if @course.faculty.include?(current_user)
if @course.faculty_and_teaching_assistants.include?(current_user)
# Get all deliverables for this team/student
@deliverables = Deliverable.get_deliverables(params[:course_id], current_user.id, {:is_my_team => 1})

Expand All @@ -58,7 +58,7 @@ def get_deliverables
#temporary for mel
def team_index_for_course
@course = Course.find(params[:course_id])
if (current_user.is_admin? || @course.faculty.include?(current_user))
if (current_user.is_admin? || @course.faculty_and_teaching_assistants.include?(current_user))
@deliverables = Deliverable.where("team_id is not null").find_all_by_course_id(@course.id)
else
has_permissions_or_redirect(:admin, root_path)
Expand All @@ -68,7 +68,7 @@ def team_index_for_course
#temporary for mel
def individual_index_for_course
@course = Course.find(params[:course_id])
if (current_user.is_admin? || @course.faculty.include?(current_user))
if (current_user.is_admin? || @course.faculty_and_teaching_assistants.include?(current_user))
@deliverables = Deliverable.where("team_id is null").find_all_by_course_id(@course.id)
else
has_permissions_or_redirect(:admin, root_path)
Expand Down Expand Up @@ -107,7 +107,7 @@ def show
redirect_to root_path and return
end

if (current_user.is_admin? || @course.faculty.include?(current_user))
if (current_user.is_admin? || @course.faculty_and_teaching_assistants.include?(current_user))
if @course.grading_rule.nil?
flash[:error] = I18n.t(:no_grading_rule_for_course)
redirect_to course_path(@course) and return
Expand All @@ -118,7 +118,7 @@ def show
end

respond_to do |format|
if (current_user.is_admin? || @course.faculty.include?(current_user))
if (current_user.is_admin? || @course.faculty_and_teaching_assistants.include?(current_user))
format.html { render layout: false }
else
format.html # show.html.erb
Expand Down Expand Up @@ -281,7 +281,7 @@ def edit_feedback

@deliverable = Deliverable.find(params[:id])

# if [email protected].faculty.include?(current_user)
# if [email protected].faculty_and_teaching_assistants.include?(current_user)
# flash[:error] = "Only faculty teaching this course can provide feedback on deliverables. #{current_user.human_name}"
# redirect_to :controller => "welcome", :action => "index"
# return
Expand All @@ -292,7 +292,7 @@ def edit_feedback
def update_feedback
@deliverable = Deliverable.find(params[:id])

unless (current_user.is_admin? || @deliverable.course.faculty.include?(current_user))
unless (current_user.is_admin? || @deliverable.course.faculty_and_teaching_assistants.include?(current_user))
flash[:error] = I18n.t(:not_your_deliverable)
redirect_to root_path and return
end
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/grades_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def render_grade_book_menu
end

def validate_permission
unless (current_user.is_admin? || @course.faculty.include?(current_user))
unless (current_user.is_admin? || @course.faculty_and_teaching_assistants.include?(current_user))
has_permissions_or_redirect(:admin, root_path)
end
end
Expand Down Expand Up @@ -58,7 +58,7 @@ def student_deliverables_and_grades_for_course
@user = current_user
end
if (current_user.id != @user.id)
unless (@course.faculty.include?(current_user))||(current_user.is_admin?)
unless (@course.faculty_and_teaching_assistants.include?(current_user))||(current_user.is_admin?)
flash[:error] = I18n.t(:not_your_deliverable)
redirect_to root_path and return
end
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/presentations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def index
# GET /courses/:course_id/presentations
def index_for_course
@course = Course.find(params[:course_id])
if (current_user.is_admin? || @course.faculty.include?(current_user))
if (current_user.is_admin? || @course.faculty_and_teaching_assistants.include?(current_user))
@presentations = Presentation.find_all_by_course_id(@course.id)
else
has_permissions_or_redirect(:admin, root_path)
Expand All @@ -51,7 +51,7 @@ def index_for_course
# GET /course/:person_id/presentations/new
def new
@course = Course.find(params[:course_id])
if (current_person.is_admin? || @course.faculty.include?(current_user))
if (current_person.is_admin? || @course.faculty_and_teaching_assistants.include?(current_user))
@presentation = Presentation.new(:presentation_date => Date.today)
@course =Course.find_by_id(params[:course_id])
else
Expand All @@ -62,7 +62,7 @@ def new
# GET /course/:person_id/presentations/:id/edit
#def edit
# @presentation = Presentation.find(:course_id)
# if (current_person.is_admin? || @course.faculty.include?(current_user))
# if (current_person.is_admin? || @course.faculty_and_teaching_assistants.include?(current_user))
# @presentation = Presentation.new(:presentation_date => Date.today)
# @course =Course.find_by_id(params[:course_id])
# else
Expand Down
36 changes: 35 additions & 1 deletion app/models/course.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ class Course < ActiveRecord::Base
has_many :faculty_assignments
has_many :faculty, :through => :faculty_assignments, :source => :user

has_many :teaching_assistant_assignments
has_many :teaching_assistants, :through => :teaching_assistant_assignments, :source => :user

has_many :registrations
has_many :registered_students, :through => :registrations, :source => :user

Expand All @@ -55,6 +58,7 @@ class Course < ActiveRecord::Base

validates_presence_of :semester, :year, :mini, :name
validate :validate_faculty_assignments
validate :validate_teaching_assistant_assignments

versioned
belongs_to :updated_by, :class_name => 'User', :foreign_key => 'updated_by_user_id'
Expand All @@ -65,10 +69,16 @@ class Course < ActiveRecord::Base
# that they are people in the system) and then to save the people in the faculty association.
attr_accessor :faculty_assignments_override

#When assigning teaching_assistant to a page, the user types in a series of strings that then need to be processed
# :teaching_assistant_assignments_override is a temporary variable that is used to do validation of the strings (to verify
# that they are people in the system) and then to save the people in the teaching_assistant association.
attr_accessor :teaching_assistant_assignments_override

attr_accessible :course_number_id, :name, :number, :semester, :mini, :primary_faculty_label,
:secondary_faculty_label, :twiki_url, :remind_about_effort, :short_name, :year,
:peer_evaluation_first_email, :peer_evaluation_second_email,
:curriculum_url, :configure_course_twiki,
:teaching_assistant_assignments_override,
:faculty_assignments_override

include PeopleInACollection
Expand All @@ -77,6 +87,10 @@ def validate_faculty_assignments
validate_members :faculty_assignments_override
end

def validate_teaching_assistant_assignments
validate_members :teaching_assistant_assignments_override
end

# def to_param
# display_course_name
# end
Expand Down Expand Up @@ -120,7 +134,7 @@ def display_semester
end

#before_validation :set_updated_by_user -- this needs to be done by the controller
before_save :strip_whitespaces, :update_email_address, :need_to_update_google_list?, :update_faculty
before_save :strip_whitespaces, :update_email_address, :need_to_update_google_list?, :update_teaching_assistants, :update_faculty
after_save :update_distribution_list

scope :unique_course_numbers_and_names_by_number, :select => "DISTINCT number, name", :order => 'number ASC'
Expand Down Expand Up @@ -235,6 +249,20 @@ def update_faculty
self.updating_email = true
end

#When modifying validate_teaching_assistant or update_teaching_assistant, modify the same code in team.rb
#Todo - move to a higher class or try as a mixin
def update_teaching_assistants
return "" if teaching_assistant_assignments_override.nil?
self.teaching_assistants = []

self.teaching_assistant_assignments_override = teaching_assistant_assignments_override.select { |name| name != nil && name.strip != "" }
list = map_member_strings_to_users(self.teaching_assistant_assignments_override)
raise "Error converting teaching_assistant_assignments_override to IDs!" if list.include?(nil)
self.teaching_assistants = list
teaching_assistant_assignments_override = nil
self.updating_email = true
end

def copy_as_new_course
new_course = self.dup
new_course.is_configured = false
Expand All @@ -244,6 +272,7 @@ def copy_as_new_course
new_course.updated_at = Time.now
new_course.curriculum_url = nil if self.curriculum_url.nil? || self.curriculum_url.include?("twiki")
new_course.faculty = self.faculty
new_course.teaching_assistants = self.teaching_assistants
new_course.grading_rule = self.grading_rule.dup if self.grading_rule.present?
self.assignments.each { |assignment| new_course.assignments << assignment.dup } if self.assignments.present?
return new_course
Expand Down Expand Up @@ -363,6 +392,11 @@ def copy_pages_to_another_course(destination_course_id, url_prefix)
end

public

def faculty_and_teaching_assistants
faculty + teaching_assistants
end

def registered_students_and_students_on_teams_hash
students = Hash.new
self.registered_students.each do |student|
Expand Down
2 changes: 1 addition & 1 deletion app/models/deliverable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ def send_deliverable_feedback_email(url, faculty_email=nil)

# To check if the current user can change/edit the deliverable
def editable?(current_user)
return true if self.course.faculty.include?(current_user)
return true if self.course.faculty_and_teaching_assistants.include?(current_user)

if self.is_team_deliverable?
unless self.team.is_user_on_team?(current_user)
Expand Down
5 changes: 5 additions & 0 deletions app/models/teaching_assistant_assignment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class TeachingAssistantAssignment < ActiveRecord::Base
belongs_to :user
belongs_to :course

end
6 changes: 6 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class User < ActiveRecord::Base
has_many :faculty_assignments
has_many :teaching_these_courses, :through => :faculty_assignments, :source => :course

has_many :teaching_assistant_assignments
has_many :teacher_assisting_these_courses, :through => :teaching_assistant_assignments, :source => :course

has_many :team_assignments
has_many :teams, :through => :team_assignments, :source => :team

Expand Down Expand Up @@ -104,6 +107,9 @@ def self.find_by_param(param)
end
end

def teacher_assisting_these_courses_during_current_semester
teacher_assisting_these_courses.where(:semester => AcademicCalendar.current_semester, :year => Date.today.year)
end

def teaching_these_courses_during_current_semester
teaching_these_courses.where(:semester => AcademicCalendar.current_semester, :year => Date.today.year)
Expand Down
17 changes: 16 additions & 1 deletion app/views/courses/_form_create.erb
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,29 @@

<div class="formItem indented"><p><%= link_to "Add a teacher", "#", :id => "add_person" %></p></div>

<div id="students_in_a_collection">
<p>Teaching Assistants for this course<br/>
<span class="help_text">They will be notified of the assignment</span>
</p>
<% if @course.teaching_assistant_assignments_override.nil? %>
<%= render :partial => '/people/person_in_a_collection', :collection => @course.teaching_assistants.map(&:human_name), :as => :person, :locals => {:collection_form => f, :member_label => "Teaching Assistant"} %>
<% else %>
<%= render :partial => '/people/person_in_a_collection', :collection => @course.teaching_assistant_assignments_override, :as => :person, :locals => {:collection_form => f, :member_label => "Teaching Assistant"} %>
<% end %>
</div>

<div class="formItem indented"><p><%= link_to "Add a teaching assistant", "#", :id => "add_teaching assistant" %></p></div>

<%# content_for :javascript do %>
<%# javascript_tag do %>
<script type="text/javascript">
$(function () {
$("#add_person").click(function () {
$("#people_in_a_collection").append("<%= escape_javascript(render(:partial => '/people/person_in_a_collection', :object => Person.new, :locals => { :member_label => "Teacher"} )) %>");
});

$("#add_teaching_assistant").click(function () {
$("#students_in_a_collection").append("<%= escape_javascript(render(:partial => '/people/person_in_a_collection', :object => Person.new, :locals => { :member_label => "Teaching Assistant"} )) %>");
});
});
</script>
<%# end %>
Expand Down
10 changes: 10 additions & 0 deletions app/views/courses/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@
<% end %>
</td>
</tr>
<% if not @course.teaching_assistants.empty? %>
<tr class="cmu_table_even">
<td>Teaching Assistants:</td>
<td>
<% @course.teaching_assistants.each do |teaching_assitant| %>
<p><%= link_to teaching_assistant.human_name, user_path(teaching_assistant) %></p>
<% end %>
</td>
</tr>
<% end %>
</table>
<br/>

Expand Down
2 changes: 1 addition & 1 deletion app/views/deliverables/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@

</div> <!-- /.container -->

<% if current_user.is_admin? || @course.faculty.include?(current_user) %>
<% if current_user.is_admin? || @course.faculty_and_teaching_assistants.include?(current_user) %>
<%= render :partial => "edit_student_feedback", :locals => {:button_name => "Submit"} %>
<%# link_to "Alter feedback", deliverable_feedback_path(@deliverable) %>
<% elsif current_user.is_student? %>
Expand Down
18 changes: 18 additions & 0 deletions db/migrate/20140503230056_create_teaching_assistant_assignments.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class CreateTeachingAssistantAssignments < ActiveRecord::Migration
def up
create_table "teaching_assistant_assignments", id: false, force: true do |t|
t.integer "course_id"
t.integer "user_id"
t.datetime "created_at"
t.datetime "updated_at"
end

add_index "teaching_assistant_assignments", ["course_id", "user_id"], name: "index_teaching_assistant_assignments_on_course_id_and_person_id", unique: true
end

def down
remove_index "teaching_assistant_assignments", name: "index_teaching_assistant_assignments_on_course_id_and_person_id"

drop_table "teaching_assistant_assignments"
end
end
11 changes: 10 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20140124184429) do
ActiveRecord::Schema.define(:version => 20140503230056) do

create_table "assignments", :force => true do |t|
t.string "name"
Expand Down Expand Up @@ -530,6 +530,15 @@
t.datetime "updated_at"
end

create_table "teaching_assistant_assignments", :id => false, :force => true do |t|
t.integer "course_id"
t.integer "user_id"
t.datetime "created_at"
t.datetime "updated_at"
end

add_index "teaching_assistant_assignments", ["course_id", "user_id"], :name => "index_teaching_assistant_assignments_on_course_id_and_person_id", :unique => true

create_table "team_assignments", :id => false, :force => true do |t|
t.integer "team_id"
t.integer "user_id"
Expand Down
16 changes: 16 additions & 0 deletions spec/controllers/course_navigations_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,22 @@

end

context "any teaching assistang can" do
before do
login(FactoryGirl.create(:teaching_assistant_kyle))
end

describe "GET show" do
before do
get :show, :id => course.to_param
end

it "can't access page" do
response.should redirect_to(root_path)
end
end
end

context "any faculty can" do
before do
login(FactoryGirl.create(:faculty_frank))
Expand Down
4 changes: 3 additions & 1 deletion spec/controllers/deliverables_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
@faculty_fagan = FactoryGirl.create(:faculty_fagan)
@student_sam = FactoryGirl.create(:student_sam)
@student_sally = FactoryGirl.create(:student_sally)

@teaching_assistant_kyle = FactoryGirl.create(:teaching_assistant_kyle)
@teaching_assistant_plato = FactoryGirl.create(:teaching_assistant_plato)

end

Expand Down Expand Up @@ -269,6 +270,7 @@
@deliverable.stub(:team).and_return(@team)

@course.stub(:grading_rule).and_return(true)
@course.stub(:faculty_and_teaching_assistants).and_return([@faculty_frank, @faculty_fagan, @teaching_assistant_kyle, @teaching_assistant_plato])
@course.stub_chain(:grading_rule, :default_values?).and_return(true)
@course = Course.stub(:find).and_return(@course)

Expand Down
Loading