voluntary 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +48 -0
- data/Rakefile +27 -0
- data/app/assets/javascripts/voluntary/application.js +6 -0
- data/app/assets/javascripts/voluntary/base.js.coffee +34 -0
- data/app/assets/javascripts/voluntary/bootstrap.js.coffee +4 -0
- data/app/assets/javascripts/voluntary/functions.js +24 -0
- data/app/assets/javascripts/voluntary/users.js.coffee +12 -0
- data/app/assets/stylesheets/voluntary/application.css +15 -0
- data/app/assets/stylesheets/voluntary/base.css.scss +40 -0
- data/app/assets/stylesheets/voluntary/bootstrap_and_overrides.css.less +67 -0
- data/app/controllers/areas_controller.rb +66 -0
- data/app/controllers/candidatures_controller.rb +79 -0
- data/app/controllers/comments_controller.rb +70 -0
- data/app/controllers/devise_extensions/registrations_controller.rb +37 -0
- data/app/controllers/home_controller.rb +7 -0
- data/app/controllers/organizations_controller.rb +67 -0
- data/app/controllers/pages_controller.rb +54 -0
- data/app/controllers/products_controller.rb +62 -0
- data/app/controllers/professions_controller.rb +66 -0
- data/app/controllers/projects_controller.rb +56 -0
- data/app/controllers/results_controller.rb +93 -0
- data/app/controllers/stories_controller.rb +96 -0
- data/app/controllers/tasks_controller.rb +88 -0
- data/app/controllers/users_controller.rb +52 -0
- data/app/controllers/vacancies_controller.rb +79 -0
- data/app/controllers/voluntary/application_controller.rb +92 -0
- data/app/controllers/workflow/candidatures_controller.rb +20 -0
- data/app/controllers/workflow/products_controller.rb +6 -0
- data/app/controllers/workflow/project_owner_controller.rb +33 -0
- data/app/controllers/workflow/stories_controller.rb +6 -0
- data/app/controllers/workflow/tasks_controller.rb +147 -0
- data/app/controllers/workflow/user_controller.rb +6 -0
- data/app/controllers/workflow/vacancies_controller.rb +17 -0
- data/app/controllers/workflow_controller.rb +7 -0
- data/app/helpers/application_helper.rb +65 -0
- data/app/helpers/collection_helper.rb +31 -0
- data/app/helpers/comments_helper.rb +11 -0
- data/app/helpers/form_helper.rb +39 -0
- data/app/helpers/language_helper.rb +15 -0
- data/app/helpers/layout_helper.rb +24 -0
- data/app/helpers/product_helper.rb +32 -0
- data/app/helpers/show_helper.rb +65 -0
- data/app/helpers/wizard_helper.rb +27 -0
- data/app/models/area.rb +19 -0
- data/app/models/area_user.rb +19 -0
- data/app/models/candidature.rb +35 -0
- data/app/models/comment.rb +16 -0
- data/app/models/history_tracker.rb +3 -0
- data/app/models/mongo_db_document.rb +11 -0
- data/app/models/organization.rb +19 -0
- data/app/models/page.rb +30 -0
- data/app/models/product.rb +99 -0
- data/app/models/product/new_product.rb +3 -0
- data/app/models/product/project_management.rb +29 -0
- data/app/models/profession.rb +13 -0
- data/app/models/project.rb +66 -0
- data/app/models/project_user.rb +13 -0
- data/app/models/result.rb +55 -0
- data/app/models/role.rb +8 -0
- data/app/models/role/admin.rb +2 -0
- data/app/models/role/master.rb +2 -0
- data/app/models/role/project_owner.rb +2 -0
- data/app/models/role/user.rb +2 -0
- data/app/models/state_machines/candidature.rb +42 -0
- data/app/models/state_machines/page.rb +18 -0
- data/app/models/state_machines/story.rb +51 -0
- data/app/models/state_machines/task.rb +46 -0
- data/app/models/state_machines/vacancy.rb +41 -0
- data/app/models/story.rb +82 -0
- data/app/models/task.rb +85 -0
- data/app/models/user.rb +95 -0
- data/app/models/user_role.rb +6 -0
- data/app/models/vacancy.rb +41 -0
- data/app/observers/candidature_observer.rb +29 -0
- data/app/observers/story_observer.rb +6 -0
- data/app/observers/task_observer.rb +34 -0
- data/app/presenters/layout/application_presenter.rb +3 -0
- data/app/presenters/layout_presenter.rb +9 -0
- data/app/presenters/presenter.rb +46 -0
- data/app/presenters/resource_presenter.rb +30 -0
- data/app/presenters/resources/general/wizard_presenter.rb +17 -0
- data/app/presenters/resources/general/wizards/story/steps/activate_presenter.rb +3 -0
- data/app/presenters/resources/general/wizards/story/steps/setup_tasks_presenter.rb +5 -0
- data/app/presenters/resources/general/wizards/story_presenter.rb +3 -0
- data/app/presenters/resources/user/form_presenter.rb +16 -0
- data/app/presenters/shared/collection/table_presenter.rb +33 -0
- data/app/views/areas/_form.html.erb +11 -0
- data/app/views/areas/edit.html.erb +3 -0
- data/app/views/areas/index.html.erb +5 -0
- data/app/views/areas/new.html.erb +3 -0
- data/app/views/areas/show.html.erb +6 -0
- data/app/views/candidatures/_form.html.erb +13 -0
- data/app/views/candidatures/edit.html.erb +3 -0
- data/app/views/candidatures/index.html.erb +11 -0
- data/app/views/candidatures/new.html.erb +3 -0
- data/app/views/candidatures/show.html.erb +18 -0
- data/app/views/comments/_form.html.erb +16 -0
- data/app/views/comments/_resource.html.erb +16 -0
- data/app/views/comments/edit.html.erb +3 -0
- data/app/views/comments/new.html.erb +3 -0
- data/app/views/devise/mailer/confirmation_instructions.html.erb +10 -0
- data/app/views/devise/registrations/new.html.erb +5 -0
- data/app/views/general/wizard.html.erb +16 -0
- data/app/views/kaminari/_first_page.html.erb +13 -0
- data/app/views/kaminari/_gap.html.erb +8 -0
- data/app/views/kaminari/_last_page.html.erb +13 -0
- data/app/views/kaminari/_next_page.html.erb +13 -0
- data/app/views/kaminari/_page.html.erb +12 -0
- data/app/views/kaminari/_paginator.html.erb +25 -0
- data/app/views/kaminari/_prev_page.html.erb +13 -0
- data/app/views/layouts/application.html.erb +48 -0
- data/app/views/layouts/shared/_flash_messages.html.erb +7 -0
- data/app/views/layouts/shared/_navigation.html.erb +7 -0
- data/app/views/organizations/_form.html.erb +11 -0
- data/app/views/organizations/edit.html.erb +3 -0
- data/app/views/organizations/index.html.erb +5 -0
- data/app/views/organizations/new.html.erb +3 -0
- data/app/views/organizations/show.html.erb +6 -0
- data/app/views/pages/_form.html.erb +12 -0
- data/app/views/pages/edit.html.erb +3 -0
- data/app/views/pages/index.html.erb +5 -0
- data/app/views/pages/new.html.erb +3 -0
- data/app/views/pages/show.html.erb +10 -0
- data/app/views/products/_form.html.erb +28 -0
- data/app/views/products/edit.html.erb +3 -0
- data/app/views/products/index.html.erb +5 -0
- data/app/views/products/mixins/_keywords.html.erb +4 -0
- data/app/views/products/new.html.erb +3 -0
- data/app/views/products/show.html.erb +11 -0
- data/app/views/products/types/text_creation/stories/_form.html.erb +19 -0
- data/app/views/products/types/text_creation/stories/_task_fields.html.erb +7 -0
- data/app/views/projects/_form.html.erb +16 -0
- data/app/views/projects/edit.html.erb +3 -0
- data/app/views/projects/index.html.erb +5 -0
- data/app/views/projects/new.html.erb +3 -0
- data/app/views/projects/show.html.erb +13 -0
- data/app/views/shared/_comments.html.erb +7 -0
- data/app/views/shared/collection/_list.html.erb +37 -0
- data/app/views/shared/collection/_table.html.erb +36 -0
- data/app/views/shared/form/_error_messages.html.erb +10 -0
- data/app/views/shared/resource/_actions.html.erb +26 -0
- data/app/views/shared/resource/_event_elements.html.erb +7 -0
- data/app/views/stories/_collection.html.erb +8 -0
- data/app/views/stories/_form.html.erb +19 -0
- data/app/views/stories/_task_fields.html.erb +11 -0
- data/app/views/stories/index.html.erb +1 -0
- data/app/views/stories/show.html.erb +13 -0
- data/app/views/stories/steps/_activate.html.erb +17 -0
- data/app/views/stories/steps/_setup_tasks.html.erb +35 -0
- data/app/views/stories/tasks.html.erb +0 -0
- data/app/views/tasks/_collection.html.erb +12 -0
- data/app/views/users/_form.html.erb +43 -0
- data/app/views/users/edit.html.erb +3 -0
- data/app/views/users/index.html.erb +6 -0
- data/app/views/users/new.html.erb +3 -0
- data/app/views/users/preferences.html.erb +11 -0
- data/app/views/users/show.html.erb +6 -0
- data/app/views/vacancies/_form.html.erb +15 -0
- data/app/views/vacancies/edit.html.erb +3 -0
- data/app/views/vacancies/index.html.erb +7 -0
- data/app/views/vacancies/new.html.erb +3 -0
- data/app/views/vacancies/show.html.erb +17 -0
- data/app/views/workflow/index.html.erb +0 -0
- data/app/views/workflow/products/show.html.erb +34 -0
- data/app/views/workflow/project_owner/_candidatures.html.erb +31 -0
- data/app/views/workflow/project_owner/_stories.html.erb +29 -0
- data/app/views/workflow/project_owner/_tasks.html.erb +34 -0
- data/app/views/workflow/project_owner/_vacancies.html.erb +27 -0
- data/app/views/workflow/project_owner/index.html.erb +24 -0
- data/app/views/workflow/tasks/_work_form.html.erb +8 -0
- data/app/views/workflow/tasks/_work_head.html.erb +15 -0
- data/app/views/workflow/tasks/edit.html.erb +3 -0
- data/app/views/workflow/tasks/index.html.erb +31 -0
- data/app/views/workflow/tasks/next.html.erb +0 -0
- data/app/views/workflow/tasks/steps/_complete.html.erb +11 -0
- data/app/views/workflow/tasks/steps/_review.html.erb +13 -0
- data/app/views/workflow/tasks/steps/_work.html.erb +17 -0
- data/app/views/workflow/user/_tasks.html.erb +30 -0
- data/app/views/workflow/user/index.html.erb +14 -0
- data/config/initializers/1_initialize_app_config.rb +5 -0
- data/config/initializers/devise.rb +193 -0
- data/config/initializers/locale_settings.rb +42 -0
- data/config/initializers/mongoid-history.rb +2 -0
- data/config/initializers/recaptcha.rb +7 -0
- data/config/initializers/simple_form.rb +178 -0
- data/config/initializers/simple_navigation.rb +2 -0
- data/config/locales/devise.en.yml +59 -0
- data/config/locales/en.yml +26 -0
- data/config/locales/general/en.yml +71 -0
- data/config/locales/resources/area/en.yml +12 -0
- data/config/locales/resources/candidature/en.yml +19 -0
- data/config/locales/resources/comment/en.yml +11 -0
- data/config/locales/resources/organization/en.yml +11 -0
- data/config/locales/resources/page/en.yml +11 -0
- data/config/locales/resources/product/en.yml +23 -0
- data/config/locales/resources/project/en.yml +9 -0
- data/config/locales/resources/result/en.yml +9 -0
- data/config/locales/resources/story/en.yml +34 -0
- data/config/locales/resources/task/en.yml +36 -0
- data/config/locales/resources/user/en.yml +14 -0
- data/config/locales/resources/vacancy/en.yml +29 -0
- data/config/locales/simple_form.en.yml +26 -0
- data/config/locales/workflow/en.yml +37 -0
- data/config/routes.rb +188 -0
- data/db/migrate/20120907144853_create_schema.rb +217 -0
- data/db/migrate/20120911093743_remove_timestamps_from_habtm_tables.rb +21 -0
- data/db/migrate/20120919161831_add_unique_index_for_one_user_candidature_per_vacancy.rb +9 -0
- data/db/migrate/20120922201955_create_mongo_db_documents.rb +13 -0
- data/db/migrate/20120923140109_add_product_to_project.rb +6 -0
- data/db/migrate/20121004061413_add_extra_user_attributes.rb +9 -0
- data/db/migrate/20121004132105_create_professions.rb +13 -0
- data/db/migrate/20121006162913_add_public_attribute_to_roles.rb +6 -0
- data/db/migrate/20121006170407_add_type_attribute_to_roles.rb +5 -0
- data/db/migrate/20121007071543_add_foreign_languages_to_user.rb +6 -0
- data/db/migrate/20121028073712_create_organizations.rb +13 -0
- data/db/seeds.rb +14 -0
- data/lib/applicat/mvc/controller.rb +171 -0
- data/lib/applicat/mvc/controller/error_handling.rb +40 -0
- data/lib/applicat/mvc/controller/resource.rb +19 -0
- data/lib/applicat/mvc/controller/transition_actions.rb +43 -0
- data/lib/applicat/mvc/model/resource/base.rb +56 -0
- data/lib/applicat/mvc/model/tokenable.rb +24 -0
- data/lib/applicat/mvc/model/tree.rb +82 -0
- data/lib/db_seed.rb +150 -0
- data/lib/environment_configuration.rb +54 -0
- data/lib/generators/voluntary/install/install_generator.rb +118 -0
- data/lib/generators/voluntary/install/templates/app/controllers/application_controller.rb +3 -0
- data/lib/generators/voluntary/install/templates/app/models/ability.rb +49 -0
- data/lib/generators/voluntary/install/templates/app/models/app_config.rb +32 -0
- data/lib/generators/voluntary/install/templates/app/views/layouts/application.html.erb +50 -0
- data/lib/generators/voluntary/install/templates/config/application.yml +147 -0
- data/lib/generators/voluntary/install/templates/config/cucumber.yml +8 -0
- data/lib/generators/voluntary/install/templates/config/database.example.yml +28 -0
- data/lib/generators/voluntary/install/templates/config/deploy.rb +59 -0
- data/lib/generators/voluntary/install/templates/config/email.example.yml +9 -0
- data/lib/generators/voluntary/install/templates/config/initializers/recaptcha_example +4 -0
- data/lib/generators/voluntary/install/templates/config/locale_settings.yml +121 -0
- data/lib/generators/voluntary/install/templates/config/main_navigation.rb +262 -0
- data/lib/generators/voluntary/install/templates/config/mongoid.yml +78 -0
- data/lib/generators/voluntary/install/templates/config/nginx.conf +27 -0
- data/lib/generators/voluntary/install/templates/config/unicorn.rb +9 -0
- data/lib/generators/voluntary/install/templates/config/unicorn_init.sh +84 -0
- data/lib/generators/voluntary/install/templates/db/seeds.rb +14 -0
- data/lib/generators/voluntary/install/templates/features/step_definitions/email_steps.rb +89 -0
- data/lib/generators/voluntary/install/templates/features/step_definitions/factory_steps.rb +120 -0
- data/lib/generators/voluntary/install/templates/features/step_definitions/javascript_steps.rb +15 -0
- data/lib/generators/voluntary/install/templates/features/step_definitions/navigation_steps.rb +3 -0
- data/lib/generators/voluntary/install/templates/features/step_definitions/resources_steps.rb +8 -0
- data/lib/generators/voluntary/install/templates/features/step_definitions/session_steps.rb +35 -0
- data/lib/generators/voluntary/install/templates/features/step_definitions/web_steps.rb +271 -0
- data/lib/generators/voluntary/install/templates/features/support/database_cleaner_patches.rb +24 -0
- data/lib/generators/voluntary/install/templates/features/support/env.rb +83 -0
- data/lib/generators/voluntary/install/templates/features/support/integration_sessions_controller.rb +32 -0
- data/lib/generators/voluntary/install/templates/features/support/integration_sessions_form.html.erb +1 -0
- data/lib/generators/voluntary/install/templates/features/support/paths.rb +98 -0
- data/lib/generators/voluntary/install/templates/features/support/selectors.rb +44 -0
- data/lib/generators/voluntary/install/templates/features/support/spork_env +72 -0
- data/lib/generators/voluntary/install/templates/features/support/user_cuke_helpers.rb +78 -0
- data/lib/generators/voluntary/install/templates/lib/volontariat_seed.rb +36 -0
- data/lib/generators/voluntary/install/templates/spec/spec_helper.rb +72 -0
- data/lib/generators/voluntary/install/templates/spec/support/deferred_garbage_collector.rb +45 -0
- data/lib/generators/voluntary/install/templates/spec/support/devise.rb +3 -0
- data/lib/generators/voluntary/install/templates/spec/support/mongo_database_cleaner.rb +19 -0
- data/lib/generators/voluntary/install/templates/vendor/assets/javascripts/jquery.tokeninput.js +915 -0
- data/lib/generators/voluntary/install/templates/vendor/assets/stylesheets/token-input-facebook.css +122 -0
- data/lib/generators/voluntary/install/templates/vendor/assets/stylesheets/token-input-mac.css +204 -0
- data/lib/generators/voluntary/install/templates/vendor/assets/stylesheets/token-input.css +127 -0
- data/lib/i18n_interpolation_fallbacks.rb +21 -0
- data/lib/model/mongo_db/commentable.rb +17 -0
- data/lib/model/mongo_db/core_extensions.rb +10 -0
- data/lib/model/mongo_db/customizable.rb +23 -0
- data/lib/model/mongo_db/product/keywords.rb +31 -0
- data/lib/model/mongo_db/state_version_attributes.rb +15 -0
- data/lib/tasks/cucumber.rake +65 -0
- data/lib/tasks/voluntary_tasks.rake +4 -0
- data/lib/vendors/active_model/naming.rb +14 -0
- data/lib/vendors/simple_navigation/renderer/breadcrumbs_without_method_links.rb +30 -0
- data/lib/vendors/simple_navigation/renderer/twitter_sidenav.rb +34 -0
- data/lib/voluntary.rb +87 -0
- data/lib/voluntary/engine.rb +11 -0
- data/lib/voluntary/helpers/application.rb +69 -0
- data/lib/voluntary/helpers/collection.rb +35 -0
- data/lib/voluntary/helpers/comments.rb +15 -0
- data/lib/voluntary/helpers/form.rb +43 -0
- data/lib/voluntary/helpers/language.rb +19 -0
- data/lib/voluntary/helpers/layout.rb +28 -0
- data/lib/voluntary/helpers/product.rb +36 -0
- data/lib/voluntary/helpers/show.rb +69 -0
- data/lib/voluntary/helpers/wizard.rb +31 -0
- data/lib/voluntary/version.rb +3 -0
- data/lib/wizard.rb +58 -0
- data/lib/wizard/controller/concerns/paths.rb +31 -0
- data/lib/wizard/controller/concerns/steps.rb +142 -0
- metadata +1217 -0
@@ -0,0 +1,40 @@
|
|
1
|
+
module Applicat
|
2
|
+
module Mvc
|
3
|
+
module Controller
|
4
|
+
module ErrorHandling
|
5
|
+
#include Applicat::Errors
|
6
|
+
|
7
|
+
def self.included(base)
|
8
|
+
if Rails.env != 'development'
|
9
|
+
base.class_eval do
|
10
|
+
rescue_from Applicat::Mvc::Controller::ErrorHandling::NoPermissionError do |e|
|
11
|
+
response_for_error 403
|
12
|
+
end
|
13
|
+
|
14
|
+
rescue_from ActiveRecord::RecordNotFound do |e|
|
15
|
+
response_for_error 404
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def response_for_error(status)
|
21
|
+
respond_to do |f|
|
22
|
+
# Show a neat html page inside the app's layout for web users
|
23
|
+
f.html { render :template => "errors/#{status}", :status => status }
|
24
|
+
|
25
|
+
# Everything else (JSON, XML, YAML, Whatnot) gets a blank page with status
|
26
|
+
# which can then be understood and processed by the API client,
|
27
|
+
# JavaScript library (on Ajax) etc.
|
28
|
+
f.all { render :nothing => true, :status => status }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class NoPermissionError < StandardError
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Applicat::Mvc::Controller::Resource
|
2
|
+
def self.included(base)
|
3
|
+
base.class_eval do
|
4
|
+
helper_method :parent, :resource
|
5
|
+
|
6
|
+
include InstanceMethods
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
module InstanceMethods
|
11
|
+
def autocomplete
|
12
|
+
render json: (
|
13
|
+
controller_name.classify.constantize.
|
14
|
+
select(:name).order(:name).where("name LIKE ?", "%#{params[:term]}%").
|
15
|
+
map(&:name)
|
16
|
+
)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Applicat::Mvc::Controller::TransitionActions
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
private
|
5
|
+
|
6
|
+
def fire_event(event, pass_event_to_assignment = false)
|
7
|
+
authorize! event, resource
|
8
|
+
|
9
|
+
#if params[resource.class.name.underscore.to_sym]
|
10
|
+
# resource.trigger = params[resource.class.name.underscore.to_sym][:trigger]
|
11
|
+
#end
|
12
|
+
|
13
|
+
resource.send(event)
|
14
|
+
|
15
|
+
if resource.errors.full_messages.any?
|
16
|
+
redirect_to :back, alert: resource.errors.full_messages.join(',')
|
17
|
+
else
|
18
|
+
redirect_to :back, notice: I18n.t('general.form.successfully_updated')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
module ClassMethods
|
23
|
+
private
|
24
|
+
|
25
|
+
def transition_actions(*actions)
|
26
|
+
actions = actions.first.is_a?(Symbol) ? actions : actions.first
|
27
|
+
|
28
|
+
actions.each do |action|
|
29
|
+
define_method action do
|
30
|
+
alternative_transition = nil
|
31
|
+
|
32
|
+
alternative_transition = send "before_#{action}" if self.respond_to?("before_#{action}")
|
33
|
+
|
34
|
+
alternative_transition = alternative_transition.is_a?(Symbol) ? alternative_transition : nil
|
35
|
+
|
36
|
+
fire_event(alternative_transition || action) and return
|
37
|
+
|
38
|
+
send "after_#{action}" if self.respond_to?("after_#{action}")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Applicat
|
2
|
+
module Mvc
|
3
|
+
module Model
|
4
|
+
module Resource
|
5
|
+
module Base
|
6
|
+
def self.included(base)
|
7
|
+
base.class_eval do
|
8
|
+
#has_many :role_assignments, :class_name => 'Role', :as => :authorizable
|
9
|
+
|
10
|
+
cattr_reader :per_page
|
11
|
+
@@per_page = 20
|
12
|
+
|
13
|
+
attr_accessor :current_user
|
14
|
+
|
15
|
+
if self.table_exists?
|
16
|
+
#reflections.values.select{|r| [:has_one, :has_many].include?(r.macro)}.map(&:name)
|
17
|
+
|
18
|
+
columns.map(&:name).select{|c| c.match('_id')}.each do |column|
|
19
|
+
association = column.split('_id').first.classify
|
20
|
+
|
21
|
+
define_method "#{association.underscore}_name" do
|
22
|
+
self.send("#{association.underscore}").try(:name)
|
23
|
+
end
|
24
|
+
|
25
|
+
accessible_attributes << "#{association.underscore}_name"
|
26
|
+
|
27
|
+
define_method "#{association.underscore}_name=" do |name|
|
28
|
+
return if name.blank?
|
29
|
+
|
30
|
+
association_type = association
|
31
|
+
|
32
|
+
if self.class.columns.map(&:name).include?("#{association.underscore}_type")
|
33
|
+
association_type = self.send("#{association.underscore}_type")
|
34
|
+
end
|
35
|
+
|
36
|
+
self.send("#{association.underscore}=", association_type.constantize.find_or_initialize_by_name(name))
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
#def role_for?(role_name, user)
|
42
|
+
# return true if new_record?
|
43
|
+
#
|
44
|
+
# role_assignments.joins(:users).where('roles.name = ? AND users.id = ?', role_name, user.id).any?
|
45
|
+
#end
|
46
|
+
|
47
|
+
def to_s
|
48
|
+
self.name rescue self.class.name.humanize
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Applicat::Mvc::Model::Tokenable
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
|
6
|
+
end
|
7
|
+
|
8
|
+
module ClassMethods
|
9
|
+
def tokens(query)
|
10
|
+
collection = where("name like ?", "%#{query}%")
|
11
|
+
|
12
|
+
if collection.empty?
|
13
|
+
[{id: "<<<#{query}>>>", name: "#{I18n.t('general.new')}: \"#{query}\""}]
|
14
|
+
else
|
15
|
+
collection
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def ids_from_tokens(tokens)
|
20
|
+
tokens.gsub!(/<<<(.+?)>>>/) { create!(name: $1).id }
|
21
|
+
tokens.split(',')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
module Applicat
|
2
|
+
module Mvc
|
3
|
+
module Model
|
4
|
+
module Tree
|
5
|
+
def self.included(base)
|
6
|
+
base.class_eval do
|
7
|
+
has_ancestry :cache_depth => true, :orphan_strategy => :rootify
|
8
|
+
|
9
|
+
acts_as_list
|
10
|
+
|
11
|
+
default_scope :order => 'position'
|
12
|
+
|
13
|
+
def add_child(element,position=nil)
|
14
|
+
#need to add errors to @element.errors and return something
|
15
|
+
temp = element.children
|
16
|
+
element.ancestry = self.child_ancestry
|
17
|
+
element.position = position || siblings.to_i + 1
|
18
|
+
element.save
|
19
|
+
return element.update_children(temp)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Accepts the typical array of ids from a scriptaculous sortable. It is called on the instance being moved
|
23
|
+
def sort(array_of_ids)
|
24
|
+
if array_of_ids.first == id.to_s
|
25
|
+
move_to_left_of siblings.find(array_of_ids.second)
|
26
|
+
else
|
27
|
+
move_to_right_of siblings.find(array_of_ids[array_of_ids.index(id.to_s) - 1])
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def move_to_child_of(reference_instance)
|
32
|
+
transaction do
|
33
|
+
remove_from_list
|
34
|
+
self.update_attributes!(:parent => reference_instance)
|
35
|
+
add_to_list_bottom
|
36
|
+
save!
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def move_to_left_of(reference_instance)
|
41
|
+
transaction do
|
42
|
+
remove_from_list
|
43
|
+
reference_instance.reload # Things have possibly changed in this list
|
44
|
+
self.update_attributes!(:parent_id => reference_instance.parent_id)
|
45
|
+
reference_item_position = reference_instance.position
|
46
|
+
increment_positions_on_lower_items(reference_item_position)
|
47
|
+
self.update_attribute(:position, reference_item_position)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def move_to_right_of(reference_instance)
|
52
|
+
transaction do
|
53
|
+
remove_from_list
|
54
|
+
reference_instance.reload # Things have possibly changed in this list
|
55
|
+
self.update_attributes!(:parent_id => reference_instance.parent_id)
|
56
|
+
if reference_instance.lower_item
|
57
|
+
lower_item_position = reference_instance.lower_item.position
|
58
|
+
increment_positions_on_lower_items(lower_item_position)
|
59
|
+
self.update_attribute(:position, lower_item_position)
|
60
|
+
else
|
61
|
+
add_to_list_bottom
|
62
|
+
save!
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
protected
|
68
|
+
|
69
|
+
def update_children(children)
|
70
|
+
children.each do |child|
|
71
|
+
temp = child.children
|
72
|
+
child.ancestry = self.child_ancestry
|
73
|
+
child.save!
|
74
|
+
return child.update_children(temp)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
data/lib/db_seed.rb
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
require 'faker'
|
2
|
+
|
3
|
+
class DbSeed
|
4
|
+
USER_ROLES = {}
|
5
|
+
|
6
|
+
attr_accessor :logger, :user_roles
|
7
|
+
|
8
|
+
def initialize(options = {logger: nil})
|
9
|
+
self.logger = options[:logger]
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_fixtures
|
13
|
+
create_roles
|
14
|
+
create_users
|
15
|
+
create_user_roles
|
16
|
+
end
|
17
|
+
|
18
|
+
protected
|
19
|
+
|
20
|
+
def users
|
21
|
+
return @users if @users
|
22
|
+
|
23
|
+
@users = {}
|
24
|
+
|
25
|
+
self.class::USER_ROLES.each do |role,attributes|
|
26
|
+
@users[role] = attributes
|
27
|
+
@users[role][:id] = User.find_by_name(role.to_s.humanize).id
|
28
|
+
end
|
29
|
+
|
30
|
+
@users
|
31
|
+
end
|
32
|
+
|
33
|
+
# roles
|
34
|
+
# TODO: define methods through USER_ROLES
|
35
|
+
def user
|
36
|
+
@user ||= User.find(user_id)
|
37
|
+
end
|
38
|
+
|
39
|
+
def user_id
|
40
|
+
@user_id ||= users[:user][:id]
|
41
|
+
end
|
42
|
+
|
43
|
+
def tenant
|
44
|
+
@tenant ||= User.find(tenant_id)
|
45
|
+
end
|
46
|
+
|
47
|
+
def tenant_id
|
48
|
+
@tenant_id ||= users[:tenant][:id]
|
49
|
+
end
|
50
|
+
|
51
|
+
def log(message, type = :info)
|
52
|
+
if logger
|
53
|
+
logger.send(type, message)
|
54
|
+
else
|
55
|
+
puts message
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def create_roles
|
60
|
+
Role.import([:name], self.class::USER_ROLES.keys.map{|role| [role.to_s.humanize]})
|
61
|
+
|
62
|
+
self.class::USER_ROLES.keys.each do |role|
|
63
|
+
attributes = { name: role.to_s.humanize, public: [:project_owner, :user].include?(role) }
|
64
|
+
|
65
|
+
"Role::#{role.to_s.classify}".constantize.create(attributes)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def create_users
|
70
|
+
self.class::USER_ROLES.each do |role, settings|
|
71
|
+
attributes = {
|
72
|
+
name: role.to_s.humanize, first_name: 'Mister', last_name: role.to_s.humanize, email: "#{role}@volontari.at",
|
73
|
+
password: "#{role}2012", language: 'en', country: 'Germany', interface_language: 'en'
|
74
|
+
}
|
75
|
+
attributes[:password_confirmation] = attributes[:password]
|
76
|
+
create_record(User, attributes, events: ['skip_confirmation!'])
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def create_user_roles
|
81
|
+
UserRole.import(
|
82
|
+
[:role_id, :user_id], users.keys.map{|r| [Role.find_by_name(r.to_s.humanize).id, users[r][:id]]}
|
83
|
+
)
|
84
|
+
end
|
85
|
+
|
86
|
+
private
|
87
|
+
|
88
|
+
def create_record(klass, attributes, options = {})
|
89
|
+
options.assert_valid_keys(:events)
|
90
|
+
|
91
|
+
klass = klass.constantize if klass.is_a?(String)
|
92
|
+
events = options[:events] || []
|
93
|
+
|
94
|
+
record = klass.new
|
95
|
+
|
96
|
+
(attributes || {}).each {|attribute,value| record.send("#{attribute}=", value) }
|
97
|
+
|
98
|
+
send_events(record, events) if events.any?
|
99
|
+
|
100
|
+
record.save! if record.new_record?
|
101
|
+
|
102
|
+
record
|
103
|
+
end
|
104
|
+
|
105
|
+
def send_events(object, events = [])
|
106
|
+
events.each {|event| send_event(object, event) }
|
107
|
+
end
|
108
|
+
|
109
|
+
def send_event(object, event)
|
110
|
+
object_was = object
|
111
|
+
event_condition_class = "::DbSeed::EventConditions::#{object.class.table_name.classify}".constantize rescue nil
|
112
|
+
arguments = nil
|
113
|
+
|
114
|
+
if event.is_a?(Array)
|
115
|
+
arguments = event
|
116
|
+
event = arguments.shift
|
117
|
+
|
118
|
+
if event == 'assignment'
|
119
|
+
# TODO: YAGNI?
|
120
|
+
object_was = object
|
121
|
+
object = object.send(event)
|
122
|
+
event = arguments.shift
|
123
|
+
arguments = nil if arguments.none?
|
124
|
+
end
|
125
|
+
elsif event.is_a?(Proc)
|
126
|
+
event.call(object)
|
127
|
+
|
128
|
+
return
|
129
|
+
end
|
130
|
+
|
131
|
+
if event_condition_class && event_condition_class.respond_to?("before_#{event.gsub('!', '')}")
|
132
|
+
conditions_arguments = arguments.is_a?(Array) ? [object] + arguments : [object]
|
133
|
+
event_condition_class.send("before_#{event.gsub('!', '')}", *conditions_arguments)
|
134
|
+
end
|
135
|
+
|
136
|
+
if event_condition_class && event_condition_class.respond_to?(event.gsub('!', ''))
|
137
|
+
# override event method through event condition class
|
138
|
+
event_condition_class.send(event.gsub('!', ''), object)
|
139
|
+
else
|
140
|
+
arguments ? object.send(event, *arguments) : object.send(event)
|
141
|
+
end
|
142
|
+
|
143
|
+
if event_condition_class && event_condition_class.respond_to?("after_#{event.gsub('!', '')}")
|
144
|
+
conditions_arguments = arguments.is_a?(Array) ? [object] + arguments : [object]
|
145
|
+
event_condition_class.send("after_#{event.gsub('!', '')}", *conditions_arguments)
|
146
|
+
end
|
147
|
+
|
148
|
+
object = object_was
|
149
|
+
end
|
150
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# Copyright (c) 2010-2011, Diaspora Inc. This file is
|
2
|
+
# licensed under the Affero General Public License version 3 or later. See
|
3
|
+
# the COPYRIGHT file.
|
4
|
+
|
5
|
+
module EnvironmentConfiguration
|
6
|
+
|
7
|
+
def self.heroku?
|
8
|
+
ENV['HEROKU']
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.secret_token_initializer_is_not_present?
|
12
|
+
!File.exists?( Rails.root.join('config', 'initializers', 'secret_token.rb'))
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.prevent_fetching_community_spotlight?
|
16
|
+
return true if heroku?
|
17
|
+
!ActiveRecord::Base.connection.table_exists?('projects') || Rails.env == 'test'
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.cache_git_version?
|
21
|
+
!self.heroku?
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.ensure_secret_token!
|
25
|
+
if heroku?
|
26
|
+
puts 'heroku app detected; using session secret from config vars...'
|
27
|
+
Rails.application.config.secret_token = ENV['SECRET_TOKEN']
|
28
|
+
elsif secret_token_initializer_is_not_present?
|
29
|
+
`rake generate:secret_token`
|
30
|
+
require Rails.root.join('config', 'initializers', 'secret_token.rb')
|
31
|
+
else
|
32
|
+
#do nothing
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.enforce_ssl?
|
37
|
+
return false unless Rails.env == 'production'
|
38
|
+
return false if ENV['NO_SSL']
|
39
|
+
return false if AppConfig[:circumvent_ssl_requirement].present?
|
40
|
+
true
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.ca_cert_file_location
|
44
|
+
if self.heroku?
|
45
|
+
"/usr/lib/ssl/certs/ca-certificates.crt"
|
46
|
+
else
|
47
|
+
AppConfig[:ca_file]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.using_new_relic?
|
52
|
+
defined?(NewRelic) && AppConfig['NEW_RELIC_LICENSE_KEY'].present?
|
53
|
+
end
|
54
|
+
end
|