Skip to content

Commit

Permalink
Fixing bugs to get it working on my systems
Browse files Browse the repository at this point in the history
  • Loading branch information
Prashant Solanki authored and Prashant Solanki committed Oct 19, 2014
1 parent 65d22a6 commit bfc4100
Show file tree
Hide file tree
Showing 36 changed files with 208 additions and 155 deletions.
8 changes: 8 additions & 0 deletions app/models/controller_action.rb
Expand Up @@ -11,6 +11,14 @@ class ControllerAction < ActiveRecord::Base
joins('left outer join site_controllers on site_controller_id = site_controllers.id').
order('site_controllers.name, name')
}

def self.find_all_by_site_controller_id (id)
ControllerAction.where(site_controller_id: id)
end

def self.find_or_create_by_name (params)
ControllerAction.find_or_create_by(name: params)
end

def controller
@controller ||= SiteController.find(self.site_controller_id)
Expand Down
4 changes: 4 additions & 0 deletions app/models/menu_item.rb
Expand Up @@ -5,6 +5,10 @@ class MenuItem < ActiveRecord::Base
validates_presence_of :name
validates_uniqueness_of :name

def self.find_or_create_by_name (params)
MenuItem.find_or_create_by(name: params)
end

def delete
children = MenuItem.where(['parent_id = ?',self.id])
children.each {|child| child.delete }
Expand Down
4 changes: 4 additions & 0 deletions app/models/permission.rb
Expand Up @@ -22,6 +22,10 @@ def Permission.find_all_for_role(role)
return find_for_role(roles)
end

def self.find_or_create_by_name (params)
Permission.find_or_create_by(name: params)
end


# Find Permissions that are not already associated with the given
# Role ID.
Expand Down
5 changes: 5 additions & 0 deletions app/models/role.rb
Expand Up @@ -11,6 +11,11 @@ class Role < ActiveRecord::Base

attr_reader :student,:ta,:instructor,:administrator,:superadministrator

def self.find_or_create_by_name (params)
Role.find_or_create_by(name: params)
end


def self.student
@@student_role ||= find_by_name 'Student'
end
Expand Down
3 changes: 3 additions & 0 deletions app/models/site_controller.rb
Expand Up @@ -12,6 +12,9 @@ def actions
@actions ||= controller_actions.order(:name)
end

def self.find_or_create_by_name (params)
SiteController.find_or_create_by(name: params)
end

def self.classes
classes = Hash.new
Expand Down
2 changes: 1 addition & 1 deletion app/models/system_settings.rb
@@ -1,5 +1,5 @@
class SystemSettings < ActiveRecord::Base
set_table_name 'system_settings'
self.table_name 'system_settings'

attr_accessor :public_role, :default_markup_style
attr_accessor :site_default_page, :not_found_page, :permission_denied_page,
Expand Down
4 changes: 2 additions & 2 deletions db/migrate/017_create_assignments.rb
Expand Up @@ -5,7 +5,7 @@ def self.up
t.column "updated_at", :datetime
t.column "name", :string
t.column "directory_path", :string
t.column "submitter_count", :integer, :limit => 10, :default => 0, :null => false
t.column "submitter_count", :integer, :limit => 8, :default => 0, :null => false
t.column "course_id", :integer, :default => 0, :null => false
t.column "instructor_id", :integer, :default => 0, :null => false
t.column "private", :boolean, :default => false, :null => false
Expand All @@ -21,7 +21,7 @@ def self.up
t.column "team_assignment", :boolean
t.column "wiki_type_id", :integer
t.column "require_signup", :boolean
t.column "num_reviewers", :integer, :limit => 10, :default => 0, :null => false
t.column "num_reviewers", :integer, :limit => 8, :default => 0, :null => false
t.column "spec_location", :text
end

Expand Down
2 changes: 1 addition & 1 deletion db/migrate/022_create_review_of_review_mappings.rb
Expand Up @@ -4,7 +4,7 @@ def self.up
t.column "review_mapping_id", :integer
t.column "review_reviewer_id", :integer
t.column "review_id", :integer
t.column "assignment_id", :integer, :limit => 10
t.column "assignment_id", :integer, :limit => 8
end

add_index "review_of_review_mappings", ["review_id"], :name => "fk_review_of_review_mapping_reviews"
Expand Down
33 changes: 17 additions & 16 deletions db/migrate/023_create_survey_responses.rb
@@ -1,31 +1,32 @@
class CreateSurveyResponses < ActiveRecord::Migration
def self.up
create_table "survey_responses", :force => true do |t|
t.column "score", :integer, :limit => 10
t.column "score", :integer, :limit => 8
t.column "comments", :text
t.column "assignment_id", :integer, :limit => 10, :default => 0, :null => false
t.column "question_id", :integer, :limit => 10, :default => 0, :null => false
t.column "survey_id", :integer, :limit => 10, :default => 0, :null => false
t.references :assignment, :null =>false, :default => 0
# t.column "assignment_id", :integer, :limit => 10, :default => 0, :null => false
t.column "question_id", :integer, :limit => 8, :default => 0, :null => false
t.column "survey_id", :integer, :limit => 8, :default => 0, :null => false
t.column "email", :string
end

add_index "survey_responses", ["assignment_id"], :name => "fk_survey_assignments"
# add_index "survey_responses", ["assignment_id"], :name => "fk_survey_assignments"

execute "alter table survey_responses
add constraint fk_survey_assignments
foreign key (assignment_id) references assignments(id)"
# execute "alter table survey_responses
# add constraint fk_survey_assignments
# foreign key (assignment_id) references assignments(id)"

add_index "survey_responses", ["question_id"], :name => "fk_survey_questions"
# add_index "survey_responses", ["question_id"], :name => "fk_survey_questions"

execute "alter table survey_responses
add constraint fk_survey_questions
foreign key (question_id) references questions(id)"
# execute "alter table survey_responses
# add constraint fk_survey_questions
# foreign key (question_id) references questions(id)"

add_index "survey_responses", ["survey_id"], :name => "fk_survey_questionnaires"
# add_index "survey_responses", ["survey_id"], :name => "fk_survey_questionnaires"

execute "alter table survey_responses
add constraint fk_survey_questionnaires
foreign key (survey_id) references questionnaires(id)"
# execute "alter table survey_responses
# add constraint fk_survey_questionnaires
# foreign key (survey_id) references questionnaires(id)"

end

Expand Down
2 changes: 1 addition & 1 deletion db/migrate/029_create_participants.rb
Expand Up @@ -9,7 +9,7 @@ def self.up
t.column "submitted_at", :datetime
t.column "topic", :string
t.column "permission_granted", :boolean
t.column "penalty_accumulated", :integer, :limit => 10, :default => 0, :null => false
t.column "penalty_accumulated", :integer, :limit => 8, :default => 0, :null => false
t.column "submitted_hyperlink", :string, :limit => 500
end

Expand Down
4 changes: 2 additions & 2 deletions db/migrate/044_menu_update_users.rb
Expand Up @@ -4,7 +4,7 @@ def self.up
if permission != nil
site_controller = SiteController.find_by_name('users')
if site_controller != nil
action = ControllerAction.find(:first, :conditions => ['site_controller_id = ? and name = ?',site_controller.id,'list'])
action = ControllerAction.where(:site_controller_id=>site_controller.id, :name=>'list').first
if action != nil
action.permission_id = permission.id
action.save
Expand All @@ -27,7 +27,7 @@ def self.up
def self.down
site_controller = SiteController.find_by_name('users')
if site_controller != nil
action = ControllerAction.find(:first, :conditions => ['site_controller_id = ? and name = ?',site_controller.id,'list'])
action = ControllerAction.where(:site_controller_id=>site_controller.id, :name=>'list').first
if action != nil
action.permission_id = nil
action.save
Expand Down
4 changes: 2 additions & 2 deletions db/migrate/045_menu_update_impersonate.rb
Expand Up @@ -6,12 +6,12 @@ def self.up
if site_controller == nil
site_controller = SiteController.create(:name => 'impersonate', :permission_id => permission1.id, :builtin => 0)
end
action = ControllerAction.find(:first, :conditions => ['name = "start" and site_controller_id = ?',site_controller.id])
action = ControllerAction.where(:site_controller_id=>site_controller.id, :name=>'start').first
if action == nil
action = ControllerAction.create(:name => 'start', :site_controller_id => site_controller.id)
end

action2 = ControllerAction.find(:first, :conditions => ['name = "restore" and site_controller_id = ?',site_controller.id])
action2 = ControllerAction.where(:site_controller_id=>site_controller.id, :name=>'restore').first
if action2 == nil
action2 = ControllerAction.create(:name => 'restore', :site_controller_id => site_controller.id, :permission_id => permission2.id)
end
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/046_menu_update_import_file.rb
@@ -1,7 +1,7 @@
class MenuUpdateImportFile < ActiveRecord::Migration
def self.up
permission1 = Permission.find_by_name('administer assignments')
site_controller = SiteController.find_or_create_by_name('import_file')
site_controller = SiteController.find_or_create_by(name: 'import_file')
site_controller.permission_id = permission1.id
site_controller.builtin = 0
site_controller.save
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/047_menu_update_review_mapping.rb
Expand Up @@ -2,7 +2,7 @@ class MenuUpdateReviewMapping < ActiveRecord::Migration
def self.up
permission1 = Permission.find_by_name('administer assignments');
menuParent = MenuItem.find_by_label('Assignment Creation')
site_controller = SiteController.find_or_create_by_name('review_mapping')
site_controller = SiteController.find_or_create_by(name: 'review_mapping')
site_controller.permission_id = permission1.id
site_controller.builtin = 0
site_controller.save
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/048_menu_update_grades.rb
@@ -1,7 +1,7 @@
class MenuUpdateGrades < ActiveRecord::Migration
def self.up
permission1 = Permission.find_by_name('administer assignments')
site_controller = SiteController.find_or_create_by_name('grades')
site_controller = SiteController.find_or_create_by(name: 'grades')
site_controller.permission_id = permission1.id
site_controller.builtin = 0
site_controller.save
Expand Down
4 changes: 3 additions & 1 deletion db/migrate/053_create_nodes.rb
Expand Up @@ -3,7 +3,9 @@ def self.up
create_table :nodes do |t|
t.column :parent_id, :integer
t.column :node_object_id, :integer
t.column :type, :string
t.column :type, :string
t.integer :lft
t.integer :rgt
end
end

Expand Down
6 changes: 4 additions & 2 deletions db/migrate/060_menu_update_tree_display.rb
Expand Up @@ -21,7 +21,8 @@ def self.up
site_controller = SiteController.find_or_create_by_name('survey_deployment')
site_controller.permission_id = permission1.id
site_controller.save
action = ControllerAction.find(:first, :conditions => ['site_controller_id = ? and name = ?',site_controller.id,'list'])
#action = ControllerAction.find(:first, :conditions => ['site_controller_id = ? and name = ?',site_controller.id,'list'])
action = ControllerAction.where(site_controller_id: site_controller.id, name: 'list').first
if action == nil
action = ControllerAction.create(:name => 'list', :site_controller_id => site_controller.id)
end
Expand All @@ -30,7 +31,8 @@ def self.up
site_controller = SiteController.find_or_create_by_name('statistics')
site_controller.permission_id = permission1.id
site_controller.save
action = ControllerAction.find(:first, :conditions => ['site_controller_id = ? and name = ?',site_controller.id,'list_surveys'])
#action = ControllerAction.find(:first, :conditions => ['site_controller_id = ? and name = ?',site_controller.id,'list_surveys'])
action = ControllerAction.where(site_controller_id: site_controller.id, name: 'list_surveys').first
if action == nil
action = ControllerAction.create(:name => 'list_surveys', :site_controller_id => site_controller.id)
end
Expand Down
6 changes: 4 additions & 2 deletions db/migrate/069_move_files.rb
@@ -1,6 +1,7 @@
class MoveFiles < ActiveRecord::Migration
def self.up
courses = Course.find(:all, :conditions => ['not instructor_id is null'])
#courses = Course.find(:all, :conditions => ['not instructor_id is null'])
courses = Course.where.not('instructor_id = null')
courses.each{
| course |

Expand Down Expand Up @@ -35,7 +36,8 @@ def self.up
FileHelper.create_directory(course)
}

assignments = Assignment.find(:all, :conditions => ['wiki_type_id = 1 and not instructor_id is null'])
#assignments = Assignment.find(:all, :conditions => ['wiki_type_id = 1 and not instructor_id is null'])
assignments = Assignment.where('wiki_type_id = 1 and instructor_id != null')
assignments.each{
| assignment |
directories = Assignment.find_all_by_directory_path(assignment.directory_path)
Expand Down
18 changes: 12 additions & 6 deletions db/migrate/073_remove_missing_controllers.rb
Expand Up @@ -2,9 +2,11 @@ class RemoveMissingControllers < ActiveRecord::Migration
def self.up
controller = SiteController.find_by_name('courses_users')
if controller
ControllerAction.find_all_by_site_controller_id(controller.id).each{
#ControllerAction.find_all_by_site_controller_id(controller.id).each{
ControllerAction.where(site_controller_id: controller.id).each{
| action |
MenuItem.find_all_by_controller_action_id(action.id).each{
#MenuItem.find_all_by_controller_action_id(action.id).each{
MenuItem.where(controller_action_id: action.id).each{
|item|
item.destroy
}
Expand All @@ -15,9 +17,11 @@ def self.up

controller = SiteController.find_by_name('publishing')
if controller
ControllerAction.find_all_by_site_controller_id(controller.id).each{
#ControllerAction.find_all_by_site_controller_id(controller.id).each{
ControllerAction.where(site_controller_id: controller.id).each{
| action |
MenuItem.find_all_by_controller_action_id(action.id).each{
#MenuItem.find_all_by_controller_action_id(action.id).each{
MenuItem.where(controller_action_id: action.id).each{
|item|
item.destroy
}
Expand All @@ -28,9 +32,11 @@ def self.up

controller = SiteController.find_by_name('submission')
if controller
ControllerAction.find_all_by_site_controller_id(controller.id).each{
#ControllerAction.find_all_by_site_controller_id(controller.id).each{
ControllerAction.where(site_controller_id: controller.id).each{
| action |
MenuItem.find_all_by_controller_action_id(action.id).each{
#MenuItem.find_all_by_controller_action_id(action.id).each{
MenuItem.where(controller_action_id: action.id).each{
|item|
item.destroy
}
Expand Down
5 changes: 3 additions & 2 deletions db/migrate/076_update_menus.rb
Expand Up @@ -38,7 +38,8 @@ def self.up
assignments_action.site_controller_id = site_controller.id
assignments_action.save

MenuItem.find(:all, :conditions => ['parent_id is null and seq >= 3']).each{
#MenuItem.find(:all, :conditions => ['parent_id is null and seq >= 3']).each{
MenuItem.where('parent_id = null and seq >= 3').each{
|item|
item.seq += 1
item.save
Expand Down Expand Up @@ -75,7 +76,7 @@ def self.up
admin_item = MenuItem.find_by_label('Administration')
admin_item.controller_action_id = nil
content_page = ContentPage.find_by_name('site_admin')
content_page.permission_id = Permission.find_by_name('administer goldberg')
content_page.permission_id = Permission.find_by_name('administer goldberg').id
content_page.save
admin_item.content_page_id = content_page.id
admin_item.save
Expand Down
3 changes: 2 additions & 1 deletion db/migrate/085_update_controllers_teammate_review.rb
Expand Up @@ -15,7 +15,8 @@ def self.up
action = ControllerAction.create(:site_controller_id => controller.id, :name => 'goto_teammate_reviews')

item = MenuItem.find_by_name('manage/questionnaires')
maxseq = MenuItem.find_all_by_parent_id(item.id).length
#maxseq = MenuItem.find_all_by_parent_id(item.id).length
maxseq = MenuItem.where(parent_id: item.id).length
MenuItem.create(:name => 'manage/questionnaires/teammate reviews', :label => 'Teammate Review', :parent_id => item.id, :seq => maxseq+1, :controller_action_id => action.id)

Role.rebuild_cache
Expand Down
3 changes: 2 additions & 1 deletion db/migrate/104_update_rubric_types.rb
Expand Up @@ -2,7 +2,8 @@ class UpdateRubricTypes < ActiveRecord::Migration
def self.up
metareview_type = ActiveRecord::Base.connection.select_one("select * from `questionnaire_types` where name = 'Metareview'")
pnode = QuestionnaireTypeNode.find_by_node_object_id(metareview_type["id"])
questionnaires = Questionnaire.find(:all, :conditions => ['id in (6,16,43,91)'])
#questionnaires = Questionnaire.find(:all, :conditions => ['id in (6,16,43,91)'])
questionnaires = Questionnaire.where('id in (6,16,43,91)')
questionnaires.each{
| questionnaire |
questionnaire.type_id = metareview_type["id"]
Expand Down
8 changes: 5 additions & 3 deletions db/migrate/108_create_questionnaire_folder_nodes.rb
@@ -1,8 +1,9 @@
class CreateQuestionnaireFolderNodes < ActiveRecord::Migration
def self.up
add_column :tree_folders, :parent_id, :integer, :null => true
#add_column :tree_folders, :parent_id, :integer, :null => true

Node.find(:all, :conditions => ['type in ("QuestionnaireTypeNode","QuestionnaireNode")']).each{
#Node.find(:all, :conditions => ['type in ("QuestionnaireTypeNode","QuestionnaireNode")']).each{
Node.where('type in ("QuestionnaireTypeNode","QuestionnaireNode")').each{
| node |
node.destroy
}
Expand Down Expand Up @@ -66,7 +67,8 @@ def self.up
QuestionnaireNode.create(:parent_id => pfNode.id, :node_object_id => questionnaire.id)
}

folders = TreeFolder.find_all_by_child_type('QuestionnaireNode')
#folders = TreeFolder.find_all_by_child_type('QuestionnaireNode')
folders = TreeFolder.where(child_type: 'QuestionnaireNode')
folders.each {
| folder |
folder.update_attribute("parent_id",parent.id)
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/121_create_suggestions.rb
@@ -1,7 +1,7 @@
class CreateSuggestions < ActiveRecord::Migration
def self.up
create_table :suggestions do |t|
t.column :id, :int
#t.column :id, :int
t.column :assignment_id, :int
t.column :title, :string
t.column :description, :string, :limit=>750
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/122_create_suggestion_comments.rb
@@ -1,7 +1,7 @@
class CreateSuggestionComments < ActiveRecord::Migration
def self.up
create_table :suggestion_comments do |t|
t.column :id, :int
#t.column :id, :int
t.column :comments, :text
t.column :commenter, :string
t.column :vote, :string
Expand Down
3 changes: 2 additions & 1 deletion db/migrate/129_menu_update_leaderboard.rb
Expand Up @@ -10,7 +10,8 @@ def self.up
site_controller = SiteController.create(:name => 'leaderboard', :permission_id => permission1.id, :builtin => 0)
end
# is there an index action for leaderboard?
action = ControllerAction.find(:first, :conditions => ['name = "index" and site_controller_id = ?',site_controller.id])
#action = ControllerAction.find(:first, :conditions => ['name = "index" and site_controller_id = ?',site_controller.id])
action = ControllerAction.where('name = "index" and site_controller_id = ?',site_controller.id).first
# if not, create an index action for leaderboard
if action == nil
action = ControllerAction.create(:name => 'index', :site_controller_id => site_controller.id)
Expand Down

0 comments on commit bfc4100

Please sign in to comment.