scidea-schools 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. data/MIT-LICENSE +7 -0
  2. data/README.md +1 -0
  3. data/Rakefile +2 -0
  4. data/app/assets/javascripts/backbone_apps/models/school.js +13 -0
  5. data/app/assets/javascripts/backbone_apps/school_selector.js +396 -0
  6. data/app/assets/stylesheets/scidea/admin/pages/schools/edit_user.css +57 -0
  7. data/app/assets/stylesheets/scidea/admin/pages/schools/user_migrate.css +3 -0
  8. data/app/assets/stylesheets/scidea/pages/schools/user_profile.css +53 -0
  9. data/app/controllers/admin/schools_controller.rb +125 -0
  10. data/app/controllers/application_controller.rb +5 -0
  11. data/app/controllers/schools_controller.rb +58 -0
  12. data/app/controllers/test/scidea_schools_qunit_tests_controller.rb +51 -0
  13. data/app/helpers/schools_helper.rb +22 -0
  14. data/app/models/school.rb +93 -0
  15. data/app/themes/global_sass/_mixins.scss +5 -0
  16. data/app/themes/scidea/sass/_config.scss +7 -0
  17. data/app/themes/scidea/sass/admin/pages/schools/edit_user.scss +14 -0
  18. data/app/themes/scidea/sass/admin/pages/schools/user_migrate.scss +21 -0
  19. data/app/themes/scidea/sass/components/_schools.scss +170 -0
  20. data/app/themes/scidea/sass/pages/schools/user_profile.scss +6 -0
  21. data/app/views/admin/schools/_form.html.erb +20 -0
  22. data/app/views/admin/schools/_school.html.erb +10 -0
  23. data/app/views/admin/schools/_search.html.erb +14 -0
  24. data/app/views/admin/schools/confirm_migration.html.erb +17 -0
  25. data/app/views/admin/schools/edit.html.erb +7 -0
  26. data/app/views/admin/schools/index.html.erb +60 -0
  27. data/app/views/admin/schools/new.html.erb +5 -0
  28. data/app/views/admin/schools/new_migration.html.erb +76 -0
  29. data/app/views/admin/schools/show.html.erb +46 -0
  30. data/app/views/admin/users/_profile_show_school.html.erb +4 -0
  31. data/app/views/admin/users/_school_edit.html.erb +5 -0
  32. data/app/views/layouts/application.html.erb +14 -0
  33. data/app/views/schools/_form.html.erb +19 -0
  34. data/app/views/schools/_profile_form.html.erb +43 -0
  35. data/app/views/schools/_script_form.html.erb +3 -0
  36. data/app/views/schools/_search.html.erb +6 -0
  37. data/app/views/users/_school_edit.html.erb +5 -0
  38. data/config/compass.rb +28 -0
  39. data/config/cucumber.yml +8 -0
  40. data/config/environment.rb +18 -0
  41. data/config/initializers/schools_assets.rb +6 -0
  42. data/config/locales/en.yml +8 -0
  43. data/config/requirejs.yml +2 -0
  44. data/config/routes.rb +25 -0
  45. data/db/seeds.rb +14 -0
  46. data/features/applying_for_seminars.feature +0 -0
  47. data/features/edit_seminar_application.feature +42 -0
  48. data/features/manage_users.feature +23 -0
  49. data/features/qunit/qunit.feature +7 -0
  50. data/features/schools/manage_schools.feature +87 -0
  51. data/features/schools/schools.feature +208 -0
  52. data/features/step_definitions/audience_steps.rb +10 -0
  53. data/features/step_definitions/authentication_steps.rb +34 -0
  54. data/features/step_definitions/custom_form_steps.rb +33 -0
  55. data/features/step_definitions/email_steps.rb +206 -0
  56. data/features/step_definitions/menu_steps.rb +4 -0
  57. data/features/step_definitions/misc_steps.rb +52 -0
  58. data/features/step_definitions/qunit_steps.rb +20 -0
  59. data/features/step_definitions/registration_steps.rb +17 -0
  60. data/features/step_definitions/school_steps.rb +35 -0
  61. data/features/step_definitions/seminar_application_steps.rb +16 -0
  62. data/features/step_definitions/seminar_steps.rb +5 -0
  63. data/features/step_definitions/steps.rb +0 -0
  64. data/features/step_definitions/user_steps.rb +16 -0
  65. data/features/step_definitions/web_steps.rb +211 -0
  66. data/features/support/env.rb +21 -0
  67. data/features/support/hooks.rb +16 -0
  68. data/features/support/paths.rb +39 -0
  69. data/features/support/seed_user_roles.rb +16 -0
  70. data/features/support/selectors.rb +66 -0
  71. data/lib/generators/scidea/schools/migrations_generator.rb +14 -0
  72. data/lib/generators/scidea/schools/removal_migrations_generator.rb +14 -0
  73. data/lib/generators/scidea/schools/templates/removal/scidea_schools_99_remove.rb +35 -0
  74. data/lib/generators/scidea/schools/templates/scidea_schools_01_install.rb +35 -0
  75. data/lib/scidea/schools/engine.rb +31 -0
  76. data/lib/scidea/schools/models/ability.rb +28 -0
  77. data/lib/scidea/schools/models/profile.rb +25 -0
  78. data/lib/scidea/schools/version.rb +5 -0
  79. data/lib/scidea/schools.rb +5 -0
  80. data/lib/scidea-schools.rb +1 -0
  81. data/lib/tasks/db/seed.rake +5 -0
  82. data/qunit/helpers/qunit.js +1598 -0
  83. data/qunit/html_fixtures/backbone_apps/_school_selector.html.erb +16 -0
  84. data/qunit/test_runner.html.erb +25 -0
  85. data/qunit/tests/backbone_apps/school_selector.js +50 -0
  86. data/spec/factories/schools.rb +10 -0
  87. data/spec/models/ability_spec.rb +27 -0
  88. data/spec/models/profile_spec.rb +38 -0
  89. data/spec/models/school_spec.rb +304 -0
  90. data/spec/routing/admin/admin_schools_routing_spec.rb +47 -0
  91. data/spec/routing/schools_routing_spec.rb +35 -0
  92. data/spec/spec_helper.rb +48 -0
  93. metadata +249 -0
@@ -0,0 +1,16 @@
1
+ Given /^there exists learner "([^"]*)"(?: with password "([^"]*)")?$/ do |email, password|
2
+ Factory(:user_learner, :email => email)
3
+ end
4
+
5
+ Given /^there exists learner "([^"]*)" named "([^"]*)"(?: with password "([^"]*)")?$/ do |email, name, password|
6
+ Factory(:user_learner, :email => email, :profile => Factory(:profile, :last_name => name, :first_name => name))
7
+ end
8
+
9
+ Given /^user "([^"]*)" has school "([^"]*)"$/ do |email, school|
10
+ profile = User.find_by_email(email).profile
11
+ school = School.find_by_name( school ) || Factory(:school, :name => school)
12
+ audience = Audience.find_by_name( 'Educator' ) || Factory(:audience, :name => 'Educator')
13
+ profile.school = school
14
+ profile.audience = audience
15
+ profile.save!
16
+ end
@@ -0,0 +1,211 @@
1
+ # TL;DR: YOU SHOULD DELETE THIS FILE
2
+ #
3
+ # This file iwas generated by Cucumber-Rails and is only here to get you a head start
4
+ # These step definitions are thin wrappers around the Capybara/Webrat API that lets you
5
+ # visit pages, interact with widgets and make assertions about page content.
6
+ #
7
+ # If you use these step definitions as basis for your features you will quickly end up
8
+ # with features that are:
9
+ #
10
+ # * Hard to maintain
11
+ # * Verbose to read
12
+ #
13
+ # A much better approach is to write your own higher level step definitions, following
14
+ # the advice in the following blog posts:
15
+ #
16
+ # * http://benmabey.com/2008/05/19/imperative-vs-declarative-scenarios-in-user-stories.html
17
+ # * http://dannorth.net/2011/01/31/whose-domain-is-it-anyway/
18
+ # * http://elabs.se/blog/15-you-re-cuking-it-wrong
19
+ #
20
+
21
+
22
+ require 'uri'
23
+ require 'cgi'
24
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
25
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "selectors"))
26
+
27
+ module WithinHelpers
28
+ def with_scope(locator)
29
+ locator ? within(*selector_for(locator)) { yield } : yield
30
+ end
31
+ end
32
+ World(WithinHelpers)
33
+
34
+ # Single-line step scoper
35
+ When /^(.*) within ([^:]+)$/ do |step, parent|
36
+ with_scope(parent) { step step }
37
+ end
38
+
39
+ # Multi-line step scoper
40
+ When /^(.*) within ([^:]+):$/ do |step, parent, table_or_string|
41
+ with_scope(parent) { step "#{step}:", table_or_string }
42
+ end
43
+
44
+ Given /^(?:|I )am on (.+)$/ do |page_name|
45
+ visit path_to(page_name)
46
+ end
47
+
48
+ When /^(?:|I )go to (.+)$/ do |page_name|
49
+ visit path_to(page_name)
50
+ end
51
+
52
+ When /^(?:|I )press "([^"]*)"$/ do |button|
53
+ click_button(button)
54
+ end
55
+
56
+ When /^(?:|I )follow "([^"]*)"$/ do |link|
57
+ click_link(link)
58
+ end
59
+
60
+ When /^(?:|I )fill in "([^"]*)" with "([^"]*)"$/ do |field, value|
61
+ fill_in(field, :with => value)
62
+ end
63
+
64
+ When /^(?:|I )fill in "([^"]*)" for "([^"]*)"$/ do |value, field|
65
+ fill_in(field, :with => value)
66
+ end
67
+
68
+ # Use this to fill in an entire form with data from a table. Example:
69
+ #
70
+ # When I fill in the following:
71
+ # | Account Number | 5002 |
72
+ # | Expiry date | 2009-11-01 |
73
+ # | Note | Nice guy |
74
+ # | Wants Email? | |
75
+ #
76
+ # TODO: Add support for checkbox, select og option
77
+ # based on naming conventions.
78
+ #
79
+ When /^(?:|I )fill in the following:$/ do |fields|
80
+ fields.rows_hash.each do |name, value|
81
+ step %{I fill in "#{name}" with "#{value}"}
82
+ end
83
+ end
84
+
85
+ When /^(?:|I )select "([^"]*)" from "([^"]*)"$/ do |value, field|
86
+ select(value, :from => field)
87
+ end
88
+
89
+ When /^(?:|I )check "([^"]*)"$/ do |field|
90
+ check(field)
91
+ end
92
+
93
+ When /^(?:|I )uncheck "([^"]*)"$/ do |field|
94
+ uncheck(field)
95
+ end
96
+
97
+ When /^(?:|I )choose "([^"]*)"$/ do |field|
98
+ choose(field)
99
+ end
100
+
101
+ When /^(?:|I )attach the file "([^"]*)" to "([^"]*)"$/ do |path, field|
102
+ attach_file(field, File.expand_path(path))
103
+ end
104
+
105
+ Then /^(?:|I )should see "([^"]*)"$/ do |text|
106
+ if page.respond_to? :should
107
+ page.should have_content(text)
108
+ else
109
+ assert page.has_content?(text)
110
+ end
111
+ end
112
+
113
+ Then /^(?:|I )should see \/([^\/]*)\/$/ do |regexp|
114
+ regexp = Regexp.new(regexp)
115
+
116
+ if page.respond_to? :should
117
+ page.should have_xpath('//*', :text => regexp)
118
+ else
119
+ assert page.has_xpath?('//*', :text => regexp)
120
+ end
121
+ end
122
+
123
+ Then /^(?:|I )should not see "([^"]*)"$/ do |text|
124
+ if page.respond_to? :should
125
+ page.should have_no_content(text)
126
+ else
127
+ assert page.has_no_content?(text)
128
+ end
129
+ end
130
+
131
+ Then /^(?:|I )should not see \/([^\/]*)\/$/ do |regexp|
132
+ regexp = Regexp.new(regexp)
133
+
134
+ if page.respond_to? :should
135
+ page.should have_no_xpath('//*', :text => regexp)
136
+ else
137
+ assert page.has_no_xpath?('//*', :text => regexp)
138
+ end
139
+ end
140
+
141
+ Then /^the "([^"]*)" field(?: within (.*))? should contain "([^"]*)"$/ do |field, parent, value|
142
+ with_scope(parent) do
143
+ field = find_field(field)
144
+ field_value = (field.tag_name == 'textarea') ? field.text : field.value
145
+ if field_value.respond_to? :should
146
+ field_value.should =~ /#{value}/
147
+ else
148
+ assert_match(/#{value}/, field_value)
149
+ end
150
+ end
151
+ end
152
+
153
+ Then /^the "([^"]*)" field(?: within (.*))? should not contain "([^"]*)"$/ do |field, parent, value|
154
+ with_scope(parent) do
155
+ field = find_field(field)
156
+ field_value = (field.tag_name == 'textarea') ? field.text : field.value
157
+ if field_value.respond_to? :should_not
158
+ field_value.should_not =~ /#{value}/
159
+ else
160
+ assert_no_match(/#{value}/, field_value)
161
+ end
162
+ end
163
+ end
164
+
165
+ Then /^the "([^"]*)" checkbox(?: within (.*))? should be checked$/ do |label, parent|
166
+ with_scope(parent) do
167
+ field_checked = find_field(label)['checked']
168
+ if field_checked.respond_to? :should
169
+ field_checked.should be_true
170
+ else
171
+ assert field_checked
172
+ end
173
+ end
174
+ end
175
+
176
+ Then /^the "([^"]*)" checkbox(?: within (.*))? should not be checked$/ do |label, parent|
177
+ with_scope(parent) do
178
+ field_checked = find_field(label)['checked']
179
+ if field_checked.respond_to? :should
180
+ field_checked.should be_false
181
+ else
182
+ assert !field_checked
183
+ end
184
+ end
185
+ end
186
+
187
+ Then /^(?:|I )should be on (.+)$/ do |page_name|
188
+ current_path = URI.parse(current_url).path
189
+ if current_path.respond_to? :should
190
+ current_path.should == path_to(page_name)
191
+ else
192
+ assert_equal path_to(page_name), current_path
193
+ end
194
+ end
195
+
196
+ Then /^(?:|I )should have the following query string:$/ do |expected_pairs|
197
+ query = URI.parse(current_url).query
198
+ actual_params = query ? CGI.parse(query) : {}
199
+ expected_params = {}
200
+ expected_pairs.rows_hash.each_pair{|k,v| expected_params[k] = v.split(',')}
201
+
202
+ if actual_params.respond_to? :should
203
+ actual_params.should == expected_params
204
+ else
205
+ assert_equal expected_params, actual_params
206
+ end
207
+ end
208
+
209
+ Then /^show me the page$/ do
210
+ save_and_open_page
211
+ end
@@ -0,0 +1,21 @@
1
+ ENV["RAILS_ENV"] ||= "test"
2
+
3
+ require File.expand_path("../../../config/environment", __FILE__)
4
+
5
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
6
+
7
+ require 'rspec/expectations'
8
+ require 'cucumber/rails'
9
+
10
+ # Remove this line if your app doesn't have a database.
11
+ # For some databases (like MongoDB and CouchDB) you may need to use :truncation instead.
12
+ DatabaseCleaner.strategy = :transaction
13
+
14
+ Cucumber::Rails::World.use_transactional_fixtures = false
15
+
16
+ Before do
17
+ page.driver.options[:resynchronize] = true
18
+ end
19
+
20
+ # load local factories which will be added to the factories from scidea.
21
+ Dir.glob(File.join(File.dirname(__FILE__), '../../spec/factories/*.rb')).each {|f| require f }
@@ -0,0 +1,16 @@
1
+ # see https://github.com/cucumber/cucumber/wiki/Hooks
2
+
3
+ AfterConfiguration do |config| # run once after cucumber configuration load
4
+ end
5
+
6
+ Before do |scenario|
7
+ SeedUserRoles.seed
8
+ end
9
+
10
+ After do |scenario| # each scenario
11
+ SeedUserRoles.clean
12
+ end
13
+
14
+ at_exit do # after all scenarios are finished (global tear-down)
15
+ end
16
+
@@ -0,0 +1,39 @@
1
+ module NavigationHelpers
2
+ # Maps a name to a path. Used by the
3
+ #
4
+ # When /^I go to (.+)$/ do |page_name|
5
+ #
6
+ # step definition in web_steps.rb
7
+ #
8
+ def path_to(page_name)
9
+ case page_name
10
+
11
+ when /the home\s?page/
12
+ '/'
13
+
14
+ when /the registration page/
15
+ '/users/sign_up'
16
+
17
+ when /the qunit tests/
18
+ "/qunit_tests"
19
+
20
+ # Add more mappings here.
21
+ # Here is an example that pulls values out of the Regexp:
22
+ #
23
+ # when /^(.*)'s profile page$/i
24
+ # user_profile_path(User.find_by_login($1))
25
+
26
+ else
27
+ begin
28
+ page_name =~ /the (.*) page/
29
+ path_components = $1.split(/\s+/)
30
+ self.send(path_components.push('path').join('_').to_sym)
31
+ rescue Object => e
32
+ raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
33
+ "Now, go and add a mapping in #{__FILE__}"
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ World(NavigationHelpers)
@@ -0,0 +1,16 @@
1
+ module SeedUserRoles
2
+ def self.seed
3
+ Role.public || Factory( :role_public )
4
+ Role.learner || Factory( :role_learner )
5
+ Role.user_admin || Factory(:role_user_admin)
6
+ Role.course_admin || Factory(:role_course_admin)
7
+ Role.product_admin || Factory(:role_product_admin)
8
+ Role.tech_support || Factory(:role_tech_support)
9
+ Role.scitent_admin || Factory(:role_scitent_admin)
10
+ end
11
+
12
+ def self.clean
13
+ Role.destroy_all
14
+ end
15
+ end
16
+
@@ -0,0 +1,66 @@
1
+ module HtmlSelectorsHelpers
2
+ # Maps a name to a selector. Used primarily by the
3
+ #
4
+ # When /^(.+) within (.+)$/ do |step, scope|
5
+ #
6
+ # step definitions in web_steps.rb
7
+ #
8
+ def selector_for(locator)
9
+ case locator
10
+
11
+ when /the page/
12
+ "html > body"
13
+
14
+ when /manage menu/
15
+ ".manage-menu"
16
+
17
+ when /([^"]*) tab content/
18
+ tab_pane_id = locator.match(/([^"]*) tab content/)[1].downcase.gsub(' ','-')
19
+ "##{tab_pane_id}.tab-pane"
20
+
21
+ when /expandable row for user "([^"]*)"/
22
+ user = User.find_by_email(locator.match(/expandable row for user "([^"]*)"/)[1])
23
+ "#users-found > .table-blue-zebra > table > tbody > tr + tr.expandable section#user-#{user.id}"
24
+
25
+ when /the seminar applications widget/
26
+ "#portlet-seminar-applications"
27
+
28
+ when /^the "([^"]*)" table$/
29
+ table_ancestor_id = locator.match(/the "([^"]*)" table/)[1].downcase.gsub(' ','-')
30
+ "##{table_ancestor_id} table"
31
+
32
+ when /cell (\d+) of row (\d+) of the "([^"]*)" table/
33
+ cell_index, row_index, table_ancestor_id = locator.match(/cell (\d+) of row (\d+) of the "([^"]*)" table/).to_a.drop(1)
34
+ "##{table_ancestor_id.downcase.gsub(' ','-')} table tbody tr:nth-child(#{row_index}) td:nth-child(#{cell_index})"
35
+
36
+ when /cell (\d+) of the header row of the "([^"]*)" table/
37
+ cell_index, table_ancestor_id = locator.match(/cell (\d+) of the header row of the "([^"]*)" table/).to_a.drop(1)
38
+ "##{table_ancestor_id.downcase.gsub(' ','-')} table thead tr:first-child th:nth-child(#{cell_index})"
39
+
40
+
41
+ # Add more mappings here.
42
+ # Here is an example that pulls values out of the Regexp:
43
+ #
44
+ # when /the (notice|error|info) flash/
45
+ # ".flash.#{$1}"
46
+
47
+ # You can also return an array to use a different selector
48
+ # type, like:
49
+ #
50
+ # when /the header/
51
+ # [:xpath, "//header"]
52
+
53
+ # This allows you to provide a quoted selector as the scope
54
+ # for "within" steps as was previously the default for the
55
+ # web steps:
56
+ when /"(.+)"/
57
+ $1
58
+
59
+ else
60
+ raise "Can't find mapping from \"#{locator}\" to a selector.\n" +
61
+ "Now, go and add a mapping in #{__FILE__}"
62
+ end
63
+ end
64
+ end
65
+
66
+ World(HtmlSelectorsHelpers)
@@ -0,0 +1,14 @@
1
+ require 'scidea/plugins/update_migration_generator'
2
+
3
+ module Scidea
4
+ module Schools
5
+ class MigrationsGenerator < Scidea::Plugins::UpdateMigrationGenerator
6
+ MigrationsGenerator.source_root(File.expand_path('templates', File.dirname(__FILE__) ) )
7
+
8
+ def plugin_migrations_path
9
+ MigrationsGenerator.source_root
10
+ end
11
+
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ require 'scidea/plugins/remove_migration_generator'
2
+
3
+ module Scidea
4
+ module Schools
5
+ class RemovalMigrationsGenerator < Scidea::Plugins::RemoveMigrationGenerator
6
+ RemovalMigrationsGenerator.source_root(File.expand_path('templates/removal', File.dirname(__FILE__) ) )
7
+
8
+ def plugin_migrations_path
9
+ RemovalMigrationsGenerator.source_root
10
+ end
11
+
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,35 @@
1
+ class ScideaSchools99Remove < ActiveRecord::Migration
2
+ def up
3
+ drop_table :schools
4
+ remove_column :profiles, :school_id
5
+ execute "delete from menu_elements where display_name = 'Educational Institutions';"
6
+ end
7
+
8
+ def down
9
+ create_table "schools" do |t|
10
+ t.string "name"
11
+ t.string "address_1"
12
+ t.string "address_2"
13
+ t.string "city"
14
+ t.string "state"
15
+ t.string "zipcode"
16
+ t.boolean "approved"
17
+ t.datetime "created_at"
18
+ t.datetime "updated_at"
19
+ t.string "phone"
20
+ end
21
+
22
+ add_column :profiles, :school_id, :integer
23
+
24
+ sql = <<-SQL
25
+ set @course_and_scitent_admins = (select group_concat(id) from roles where symbol in ('course_admin', 'scitent_admin'));
26
+ set @product_and_scitent_admins = (select group_concat(id) from roles where symbol in ('product_admin', 'scitent_admin'));
27
+
28
+ SELECT @admin_nav_secondary_id:=id FROM menus WHERE name = 'Admin Navigation: Secondary' LIMIT 1;
29
+
30
+ INSERT INTO menu_elements (display_name, menu_id, url, view_role_list, edit_role_list, order_sequence) VALUES ('Educational Institutions', @admin_nav_secondary_id, '/admin/schools', @course_and_scitent_admins, @product_and_scitent_admins, 102);
31
+ SQL
32
+
33
+ sql.split("\n").reject{|s| s.strip.start_with?('#') || s.strip.empty? }.each{ |s| execute s.strip }
34
+ end
35
+ end
@@ -0,0 +1,35 @@
1
+ class ScideaSchools01Install < ActiveRecord::Migration
2
+ def up
3
+ create_table "schools" do |t|
4
+ t.string "name"
5
+ t.string "address_1"
6
+ t.string "address_2"
7
+ t.string "city"
8
+ t.string "state"
9
+ t.string "zipcode"
10
+ t.boolean "approved"
11
+ t.datetime "created_at"
12
+ t.datetime "updated_at"
13
+ t.string "phone"
14
+ end
15
+
16
+ add_column :profiles, :school_id, :integer
17
+
18
+ sql = <<-SQL
19
+ set @course_and_scitent_admins = (select group_concat(id) from roles where symbol in ('course_admin', 'scitent_admin'));
20
+ set @product_and_scitent_admins = (select group_concat(id) from roles where symbol in ('product_admin', 'scitent_admin'));
21
+
22
+ SELECT @admin_nav_secondary_id:=id FROM menus WHERE name = 'Admin Navigation: Secondary' LIMIT 1;
23
+
24
+ INSERT INTO menu_elements (display_name, menu_id, url, view_role_list, edit_role_list, order_sequence) VALUES ('Educational Institutions', @admin_nav_secondary_id, '/admin/schools', @course_and_scitent_admins, @product_and_scitent_admins, 102);
25
+ SQL
26
+
27
+ sql.split("\n").reject{|s| s.strip.start_with?('#') || s.strip.empty? }.each{ |s| execute s.strip }
28
+ end
29
+
30
+ def down
31
+ drop_table :schools
32
+ remove_column :profiles, :school_id
33
+ execute "delete from menu_elements where display_name = 'Educational Institutions';"
34
+ end
35
+ end
@@ -0,0 +1,31 @@
1
+ require_relative 'models/profile'
2
+ require_relative 'models/ability'
3
+
4
+ module Scidea
5
+ module Schools
6
+ class Engine < ::Rails::Engine
7
+
8
+ initializer "scidea.schools.register_view_callbacks" do
9
+ Scidea::Plugins::Plugin.on(:admin_user_form_after_profile) { conditional_render('admin/users/school_edit') }
10
+
11
+ Scidea::Plugins::Plugin.on(:registration_new_after_profile) { conditional_render('users/school_edit') }
12
+ Scidea::Plugins::Plugin.on(:user_profile_form_after_profile) { conditional_render('users/school_edit') }
13
+
14
+ Scidea::Plugins::Plugin.on(:admin_user_profile_after_profile) { 'admin/users/profile_show_school' }
15
+
16
+ Scidea::Plugins::Plugin.on(:user_profile_page_js) { 'backbone_apps/school_selector' }
17
+ end
18
+
19
+ config.to_prepare do
20
+ Profile.class_eval { include Scidea::Schools::Models::Profile }
21
+ Ability.class_eval { include Scidea::Schools::Models::Ability }
22
+ end
23
+
24
+ private
25
+ def conditional_render(partial)
26
+ School.render_form? ? partial : nil
27
+ end
28
+
29
+ end # class Engine
30
+ end
31
+ end
@@ -0,0 +1,28 @@
1
+ module Scidea
2
+ module Schools
3
+ module Models
4
+ module Ability
5
+ extend ActiveSupport::Concern
6
+
7
+ module InstanceMethods
8
+ def initialize_namespace_admin(user)
9
+ super
10
+
11
+ can(:manage, [School]) if user.has_role?(Role.course_admin)
12
+ end
13
+
14
+ def initialize_namespace_none(user)
15
+ super
16
+
17
+ # required for registration form
18
+ can([:index, :create, :update], School)
19
+
20
+ # required for profile form
21
+ can([:index, :create, :update], School) if user.has_role? Role.learner
22
+ end
23
+ end
24
+
25
+ end # ability
26
+ end # models
27
+ end
28
+ end
@@ -0,0 +1,25 @@
1
+ module Scidea
2
+ module Schools
3
+ module Models
4
+ module Profile
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ belongs_to :school
9
+ validate :school_present_if_educator_audience
10
+ end
11
+
12
+ module InstanceMethods
13
+ def audience_is_educator?
14
+ audience && audience.name.downcase == 'educator'
15
+ end
16
+
17
+ def school_present_if_educator_audience
18
+ errors.add(:school, "Educational institution required if you are an educator") if audience_is_educator? && school.nil?
19
+ end
20
+ end
21
+
22
+ end # profile
23
+ end # models
24
+ end
25
+ end
@@ -0,0 +1,5 @@
1
+ module Scidea
2
+ module Schools
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Scidea
2
+ module Schools
3
+ require 'scidea/schools/engine'
4
+ end
5
+ end
@@ -0,0 +1 @@
1
+ require 'scidea/schools.rb'
@@ -0,0 +1,5 @@
1
+ namespace :db do
2
+ task :seed do
3
+ Scidea::Schools::Engine.load_seed
4
+ end
5
+ end