iugusdk 1.0.0.alpha.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (207) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.rdoc +3 -0
  3. data/Rakefile +39 -0
  4. data/app/assets/images/application_logo.png +0 -0
  5. data/app/assets/javascripts/settings.js +10 -0
  6. data/app/assets/javascripts/settings_code.js.coffee.erb +0 -0
  7. data/app/assets/stylesheets/settings.sass +120 -0
  8. data/app/controllers/iugu/account_controller.rb +63 -0
  9. data/app/controllers/iugu/account_domains_controller.rb +64 -0
  10. data/app/controllers/iugu/account_roles_controller.rb +20 -0
  11. data/app/controllers/iugu/account_settings_controller.rb +17 -0
  12. data/app/controllers/iugu/account_users_controller.rb +43 -0
  13. data/app/controllers/iugu/application_domain_controller.rb +11 -0
  14. data/app/controllers/iugu/confirmations_controller.rb +2 -0
  15. data/app/controllers/iugu/invitations_controller.rb +49 -0
  16. data/app/controllers/iugu/omniauth_callbacks_controller.rb +23 -0
  17. data/app/controllers/iugu/passwords_controller.rb +2 -0
  18. data/app/controllers/iugu/profile_controller.rb +44 -0
  19. data/app/controllers/iugu/registrations_controller.rb +3 -0
  20. data/app/controllers/iugu/sessions_controller.rb +2 -0
  21. data/app/controllers/iugu/settings_controller.rb +11 -0
  22. data/app/controllers/iugu/unlocks_controller.rb +2 -0
  23. data/app/mailers/iugu_mailer.rb +16 -0
  24. data/app/models/account.rb +53 -0
  25. data/app/models/account_domain.rb +69 -0
  26. data/app/models/account_role.rb +24 -0
  27. data/app/models/account_user.rb +55 -0
  28. data/app/models/available_language.rb +10 -0
  29. data/app/models/social_account.rb +14 -0
  30. data/app/models/user.rb +107 -0
  31. data/app/models/user_invitation.rb +39 -0
  32. data/app/validators/email_validator.rb +17 -0
  33. data/app/views/iugu-old/account_settings.html.haml +17 -0
  34. data/app/views/iugu-old/login.html.haml +28 -0
  35. data/app/views/iugu-old/mails/confirmation_instructions.html.erb +5 -0
  36. data/app/views/iugu-old/mails/reset_password_instructions.html.erb +8 -0
  37. data/app/views/iugu-old/mails/unlock_instructions.html.erb +7 -0
  38. data/app/views/iugu-old/profile_settings.html.haml +76 -0
  39. data/app/views/iugu-old/signup.html.haml +36 -0
  40. data/app/views/iugu/account_domains/index.html.haml +33 -0
  41. data/app/views/iugu/account_domains/instructions.html.haml +0 -0
  42. data/app/views/iugu/account_roles/edit.html.haml +17 -0
  43. data/app/views/iugu/account_roles/update.html.haml +0 -0
  44. data/app/views/iugu/account_users/index.html.haml +23 -0
  45. data/app/views/iugu/account_users/view.html.haml +0 -0
  46. data/app/views/iugu/confirmations/new.html.haml +8 -0
  47. data/app/views/iugu/invitations/edit.html.haml +8 -0
  48. data/app/views/iugu/invitations/new.html.haml +13 -0
  49. data/app/views/iugu/mailer/confirmation_instructions.html.haml +4 -0
  50. data/app/views/iugu/mailer/invitation.html.haml +1 -0
  51. data/app/views/iugu/mailer/reset_password_instructions.html.haml +4 -0
  52. data/app/views/iugu/mailer/unlock_instructions.html.haml +5 -0
  53. data/app/views/iugu/passwords/edit.html.haml +11 -0
  54. data/app/views/iugu/passwords/new.html.haml +8 -0
  55. data/app/views/iugu/registrations/edit.html.haml +15 -0
  56. data/app/views/iugu/registrations/new.html.haml +11 -0
  57. data/app/views/iugu/sessions/new.html.haml +9 -0
  58. data/app/views/iugu/settings/account.html.haml +48 -0
  59. data/app/views/iugu/settings/accounts.html.haml +33 -0
  60. data/app/views/iugu/settings/profile.html.haml +96 -0
  61. data/app/views/iugu/shared/_links.haml +19 -0
  62. data/app/views/iugu/unlocks/new.html.haml +8 -0
  63. data/app/views/layouts/settings.html.haml +46 -0
  64. data/config/initializers/account_roles.rb +5 -0
  65. data/config/initializers/devise.rb +242 -0
  66. data/config/initializers/social_accounts.rb +16 -0
  67. data/config/locales/devise.en.yml +57 -0
  68. data/config/locales/devise.pt-BR.yml +55 -0
  69. data/config/locales/iugu.en.yml +73 -0
  70. data/config/locales/iugu.pt-BR.yml +73 -0
  71. data/config/routes.rb +77 -0
  72. data/db/migrate/20120528164634_create_account.rb +11 -0
  73. data/db/migrate/20120529134109_add_devise_to_users.rb +53 -0
  74. data/db/migrate/20120529162901_add_birthdate_and_name_to_user.rb +12 -0
  75. data/db/migrate/20120529174755_add_name_and_subscription_id_and_user_id_to_account.rb +13 -0
  76. data/db/migrate/20120529180814_create_account_users.rb +12 -0
  77. data/db/migrate/20120530114709_remove_user_id_from_accounts.rb +9 -0
  78. data/db/migrate/20120531171438_create_account_roles.rb +12 -0
  79. data/db/migrate/20120604131034_add_locale_to_user.rb +9 -0
  80. data/db/migrate/20120605142527_create_social_account.rb +15 -0
  81. data/db/migrate/20120612141130_set_locale.rb +6 -0
  82. data/db/migrate/20120613173114_remove_unique_from_user_email.rb +11 -0
  83. data/db/migrate/20120615180728_create_delayed_jobs.rb +22 -0
  84. data/db/migrate/20120629154429_create_user_invitations.rb +14 -0
  85. data/db/migrate/20120629195345_add_token_to_user_invitations.rb +8 -0
  86. data/db/migrate/20120705202827_add_roles_to_user_invitations.rb +8 -0
  87. data/db/migrate/20120716145846_create_account_domain.rb +14 -0
  88. data/db/migrate/20120719162426_add_subdomain_to_account.rb +9 -0
  89. data/lib/iugusdk.rb +73 -0
  90. data/lib/iugusdk/controllers/helpers.rb +45 -0
  91. data/lib/iugusdk/engine.rb +13 -0
  92. data/lib/iugusdk/locale_filter.rb +12 -0
  93. data/lib/iugusdk/root_tenancy_url.rb +22 -0
  94. data/lib/iugusdk/valid_tenancy_urls.rb +27 -0
  95. data/lib/iugusdk/version.rb +3 -0
  96. data/lib/tasks/iugusdk_tasks.rake +4 -0
  97. data/spec/controller_macros.rb +41 -0
  98. data/spec/controllers/account_controller_spec.rb +155 -0
  99. data/spec/controllers/account_domains_controller_spec.rb +173 -0
  100. data/spec/controllers/account_roles_controller_spec.rb +48 -0
  101. data/spec/controllers/account_settings_controller_spec.rb +42 -0
  102. data/spec/controllers/account_users_controller_spec.rb +145 -0
  103. data/spec/controllers/application_domain_controller_spec.rb +29 -0
  104. data/spec/controllers/invitations_controller_spec.rb +102 -0
  105. data/spec/controllers/profile_controller_spec.rb +125 -0
  106. data/spec/controllers/settings_controller_spec.rb +14 -0
  107. data/spec/dummy/Rakefile +7 -0
  108. data/spec/dummy/app/assets/javascripts/application.js +9 -0
  109. data/spec/dummy/app/assets/stylesheets/application.css +7 -0
  110. data/spec/dummy/app/assets/stylesheets/default.sass +111 -0
  111. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  112. data/spec/dummy/app/controllers/dashboard_controller.rb +8 -0
  113. data/spec/dummy/app/controllers/my_dummy_controller.rb +9 -0
  114. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  115. data/spec/dummy/app/views/dashboard/index.html.haml +5 -0
  116. data/spec/dummy/app/views/dashboard/splash.html.haml +10 -0
  117. data/spec/dummy/app/views/layouts/application.html.erb +29 -0
  118. data/spec/dummy/app/views/layouts/dummy.html.erb +22 -0
  119. data/spec/dummy/app/views/my_dummy/index.html.haml +5 -0
  120. data/spec/dummy/config.ru +4 -0
  121. data/spec/dummy/config/account_roles.yml +3 -0
  122. data/spec/dummy/config/application.rb +66 -0
  123. data/spec/dummy/config/boot.rb +10 -0
  124. data/spec/dummy/config/database.yml +37 -0
  125. data/spec/dummy/config/environment.rb +5 -0
  126. data/spec/dummy/config/environments/development.rb +37 -0
  127. data/spec/dummy/config/environments/production.rb +60 -0
  128. data/spec/dummy/config/environments/test.rb +40 -0
  129. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  130. data/spec/dummy/config/initializers/inflections.rb +10 -0
  131. data/spec/dummy/config/initializers/iugusdk.rb +4 -0
  132. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  133. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  134. data/spec/dummy/config/initializers/session_store.rb +8 -0
  135. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  136. data/spec/dummy/config/locales/en.yml +5 -0
  137. data/spec/dummy/config/routes.rb +69 -0
  138. data/spec/dummy/config/social_accounts.yml +6 -0
  139. data/spec/dummy/db/schema.rb +95 -0
  140. data/spec/dummy/public/404.html +26 -0
  141. data/spec/dummy/public/422.html +26 -0
  142. data/spec/dummy/public/500.html +26 -0
  143. data/spec/dummy/public/favicon.ico +0 -0
  144. data/spec/dummy/script/rails +6 -0
  145. data/spec/dummy/tmp/cache/sass/1f198e4a81e57d6c86c6fff1f0e13592b233ebc2/prettify.cssc +0 -0
  146. data/spec/dummy/tmp/cache/sass/40796b6ca2cf9112b889007328d8a4c5fdc634d8/_css3.scssc +0 -0
  147. data/spec/dummy/tmp/cache/sass/40796b6ca2cf9112b889007328d8a4c5fdc634d8/_support.scssc +0 -0
  148. data/spec/dummy/tmp/cache/sass/589e829967f8e21bd017e2d6a46ea53360f10fe0/components.sassc +0 -0
  149. data/spec/dummy/tmp/cache/sass/589e829967f8e21bd017e2d6a46ea53360f10fe0/iugu-ux.sassc +0 -0
  150. data/spec/dummy/tmp/cache/sass/589e829967f8e21bd017e2d6a46ea53360f10fe0/mixins.sassc +0 -0
  151. data/spec/dummy/tmp/cache/sass/589e829967f8e21bd017e2d6a46ea53360f10fe0/reset.sassc +0 -0
  152. data/spec/dummy/tmp/cache/sass/589e829967f8e21bd017e2d6a46ea53360f10fe0/typography.sassc +0 -0
  153. data/spec/dummy/tmp/cache/sass/589e829967f8e21bd017e2d6a46ea53360f10fe0/utilities.sassc +0 -0
  154. data/spec/dummy/tmp/cache/sass/589e829967f8e21bd017e2d6a46ea53360f10fe0/variables.sassc +0 -0
  155. data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_appearance.scssc +0 -0
  156. data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_background-clip.scssc +0 -0
  157. data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_background-origin.scssc +0 -0
  158. data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_background-size.scssc +0 -0
  159. data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_border-radius.scssc +0 -0
  160. data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_box-shadow.scssc +0 -0
  161. data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_box-sizing.scssc +0 -0
  162. data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_box.scssc +0 -0
  163. data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_columns.scssc +0 -0
  164. data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_font-face.scssc +0 -0
  165. data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_images.scssc +0 -0
  166. data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_inline-block.scssc +0 -0
  167. data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_opacity.scssc +0 -0
  168. data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_shared.scssc +0 -0
  169. data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_text-shadow.scssc +0 -0
  170. data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_transform.scssc +0 -0
  171. data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_transition.scssc +0 -0
  172. data/spec/dummy/tmp/cache/sass/9da4e62a062dae83baa33f29455be2ba30cf5dce/_sprites.scssc +0 -0
  173. data/spec/dummy/tmp/cache/sass/db2a23483187bf5625185da2d6f47de2a6de4989/_base.scssc +0 -0
  174. data/spec/dummy/tmp/cache/sass/db2a23483187bf5625185da2d6f47de2a6de4989/_sprite-img.scssc +0 -0
  175. data/spec/dummy/tmp/cache/sass/e5be18dde92936a4632e65289dad5788ed73dd60/base_settings.sassc +0 -0
  176. data/spec/dummy/tmp/cache/sass/e5be18dde92936a4632e65289dad5788ed73dd60/settings.sassc +0 -0
  177. data/spec/dummy/tmp/cache/sass/e764476e9a85279ad82622591ce49983ed21c149/application.sassc +0 -0
  178. data/spec/dummy/tmp/cache/sass/e764476e9a85279ad82622591ce49983ed21c149/base_settings.sassc +0 -0
  179. data/spec/dummy/tmp/cache/sass/e764476e9a85279ad82622591ce49983ed21c149/default.sassc +0 -0
  180. data/spec/dummy/tmp/cache/sass/eab9c0816f626278a6731ce2928de6fdbe99322b/_hacks.scssc +0 -0
  181. data/spec/dummy/tmp/restart.txt +0 -0
  182. data/spec/fabricators/account_domain_fabricator.rb +4 -0
  183. data/spec/fabricators/account_fabricator.rb +4 -0
  184. data/spec/fabricators/account_role_fabricator.rb +3 -0
  185. data/spec/fabricators/account_user_fabricator.rb +4 -0
  186. data/spec/fabricators/social_account_fabricator.rb +10 -0
  187. data/spec/fabricators/user_fabricator.rb +10 -0
  188. data/spec/fabricators/user_invitation_fabricator.rb +4 -0
  189. data/spec/mailers/iugu_mailer_spec.rb +22 -0
  190. data/spec/models/account_domain_spec.rb +111 -0
  191. data/spec/models/account_role_spec.rb +24 -0
  192. data/spec/models/account_spec.rb +155 -0
  193. data/spec/models/account_user_spec.rb +158 -0
  194. data/spec/models/social_account_spec.rb +36 -0
  195. data/spec/models/user_invitation_spec.rb +92 -0
  196. data/spec/models/user_spec.rb +187 -0
  197. data/spec/requests/account_domain_spec.rb +77 -0
  198. data/spec/requests/account_roles_spec.rb +45 -0
  199. data/spec/requests/account_spec.rb +97 -0
  200. data/spec/requests/account_users_spec.rb +129 -0
  201. data/spec/requests/omniauth_spec.rb +79 -0
  202. data/spec/requests/settings_spec.rb +53 -0
  203. data/spec/requests/user_invitation_spec.rb +40 -0
  204. data/spec/requests/user_spec.rb +34 -0
  205. data/spec/spec_helper.rb +116 -0
  206. data/spec/validators/email_validator_spec.rb +21 -0
  207. metadata +729 -0
@@ -0,0 +1,12 @@
1
+ class CreateAccountUsers < ActiveRecord::Migration
2
+ def up
3
+ create_table :account_users do |t|
4
+ t.column :account_id, :integer
5
+ t.column :user_id, :integer
6
+ end
7
+ end
8
+
9
+ def down
10
+ drop_table :account_users
11
+ end
12
+ end
@@ -0,0 +1,9 @@
1
+ class RemoveUserIdFromAccounts < ActiveRecord::Migration
2
+ def up
3
+ remove_column :accounts, :user_id
4
+ end
5
+
6
+ def down
7
+ add_column :accounts, :user_id, :integer
8
+ end
9
+ end
@@ -0,0 +1,12 @@
1
+ class CreateAccountRoles < ActiveRecord::Migration
2
+ def up
3
+ create_table :account_roles do |t|
4
+ t.column :name, :string
5
+ t.column :account_user_id, :integer
6
+ end
7
+ end
8
+
9
+ def down
10
+ drop_table :account_roles
11
+ end
12
+ end
@@ -0,0 +1,9 @@
1
+ class AddLocaleToUser < ActiveRecord::Migration
2
+ def up
3
+ add_column :users, :locale, :string
4
+ end
5
+
6
+ def down
7
+ remove_column :users, :locale
8
+ end
9
+ end
@@ -0,0 +1,15 @@
1
+ class CreateSocialAccount < ActiveRecord::Migration
2
+ def up
3
+ create_table :social_accounts do |t|
4
+ t.column :social_id, :integer
5
+ t.column :user_id, :integer
6
+ t.column :provider, :string
7
+ t.column :token, :string
8
+ t.column :secret, :string
9
+ end
10
+ end
11
+
12
+ def down
13
+ drop_table :social_accounts
14
+ end
15
+ end
@@ -0,0 +1,6 @@
1
+ class SetLocale < ActiveRecord::Migration
2
+ def change
3
+ User.where(:locale => nil).update_all("locale = 'en'")
4
+ end
5
+
6
+ end
@@ -0,0 +1,11 @@
1
+ class RemoveUniqueFromUserEmail < ActiveRecord::Migration
2
+ def up
3
+ remove_index "users", :name => "index_users_on_email"
4
+ add_index "users", ["email"], :name => "index_users_on_email"
5
+ end
6
+
7
+ def down
8
+ remove_index "users", :name => "index_users_on_email"
9
+ add_index "users", ["email"], :name => "index_users_on_email", :unique => true
10
+ end
11
+ end
@@ -0,0 +1,22 @@
1
+ class CreateDelayedJobs < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :delayed_jobs, :force => true do |table|
4
+ table.integer :priority, :default => 0 # Allows some jobs to jump to the front of the queue
5
+ table.integer :attempts, :default => 0 # Provides for retries, but still fail eventually.
6
+ table.text :handler # YAML-encoded string of the object that will do work
7
+ table.text :last_error # reason for last failure (See Note below)
8
+ table.datetime :run_at # When to run. Could be Time.zone.now for immediately, or sometime in the future.
9
+ table.datetime :locked_at # Set when a client is working on this object
10
+ table.datetime :failed_at # Set when all retries have failed (actually, by default, the record is deleted instead)
11
+ table.string :locked_by # Who is working on this object (if locked)
12
+ table.string :queue # The name of the queue this job is in
13
+ table.timestamps
14
+ end
15
+
16
+ add_index :delayed_jobs, [:priority, :run_at], :name => 'delayed_jobs_priority'
17
+ end
18
+
19
+ def self.down
20
+ drop_table :delayed_jobs
21
+ end
22
+ end
@@ -0,0 +1,14 @@
1
+ class CreateUserInvitations < ActiveRecord::Migration
2
+ def up
3
+ create_table :user_invitations do |t|
4
+ t.column :invited_by, :integer
5
+ t.column :email, :string
6
+ t.column :sent_at, :datetime
7
+ t.column :account_id, :integer
8
+ end
9
+ end
10
+
11
+ def down
12
+ drop_table :user_invitations
13
+ end
14
+ end
@@ -0,0 +1,8 @@
1
+ class AddTokenToUserInvitations < ActiveRecord::Migration
2
+ def up
3
+ add_column :user_invitations, :token, :string
4
+ end
5
+ def down
6
+ remove_column :user_invitations, :token
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ class AddRolesToUserInvitations < ActiveRecord::Migration
2
+ def up
3
+ add_column :user_invitations, :roles, :string
4
+ end
5
+ def down
6
+ remove_column :user_invitations, :roles
7
+ end
8
+ end
@@ -0,0 +1,14 @@
1
+ class CreateAccountDomain < ActiveRecord::Migration
2
+ def up
3
+ create_table :account_domains do |t|
4
+ t.column :account_id, :integer
5
+ t.column :url, :string
6
+ t.column :verified, :boolean
7
+ t.column :primary, :boolean
8
+ end
9
+ end
10
+
11
+ def down
12
+ drop_table :account_domains
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ class AddSubdomainToAccount < ActiveRecord::Migration
2
+ def up
3
+ add_column :accounts, :subdomain, :string
4
+ end
5
+
6
+ def down
7
+ remove_column :accounts, :subdomain
8
+ end
9
+ end
@@ -0,0 +1,73 @@
1
+ require 'haml'
2
+ require 'haml-rails'
3
+ require 'simple_form'
4
+ require 'iugusdk/controllers/helpers'
5
+ require 'iugusdk/valid_tenancy_urls'
6
+ require 'iugusdk/root_tenancy_url'
7
+ require "iugusdk/engine"
8
+ require "iugusdk/locale_filter"
9
+ require "http_accept_language"
10
+ require 'devise'
11
+ require 'omniauth'
12
+ require 'omniauth-twitter'
13
+ require 'omniauth-facebook'
14
+ require 'delayed_job'
15
+ require 'delayed_job_active_record'
16
+ # TODO: ALE - Acho q vai precisar disto
17
+ # require 'oauth2'
18
+
19
+ module IuguSDK
20
+
21
+ mattr_accessor :app_root
22
+
23
+ mattr_accessor :application_title
24
+ mattr_accessor :no_signup_form
25
+ mattr_accessor :app_main_url
26
+ mattr_accessor :app_root_url
27
+ mattr_accessor :default_subscription_name
28
+ mattr_accessor :guest_user_prefix
29
+ mattr_accessor :multiple_accounts_per_user
30
+ mattr_accessor :custom_domain_for_accounts
31
+ mattr_accessor :default_layout
32
+
33
+ mattr_accessor :allow_create_account
34
+ self.allow_create_account = false
35
+
36
+ mattr_accessor :application_main_host
37
+ self.application_main_host = "iugusdk.dev"
38
+
39
+ mattr_accessor :custom_domain_invalid_prefixes
40
+ self.custom_domain_invalid_prefixes = ['www','blog','help','api']
41
+
42
+ mattr_accessor :custom_domain_invalid_hosts
43
+ self.custom_domain_invalid_hosts = ['localhost']
44
+
45
+ mattr_accessor :delay_account_exclusion
46
+ self.delay_account_exclusion = 0
47
+
48
+ mattr_accessor :delay_account_user_exclusion
49
+ self.delay_account_user_exclusion = 0
50
+
51
+ mattr_accessor :delay_user_exclusion
52
+ self.delay_user_exclusion = 0
53
+
54
+ self.application_title = 'Application Name'
55
+
56
+ self.no_signup_form = false
57
+ self.app_main_url = '/'
58
+ self.app_root_url = '/'
59
+ self.default_subscription_name = 'free'
60
+ self.guest_user_prefix = 'appuser'
61
+ self.multiple_accounts_per_user = false
62
+ self.custom_domain_for_accounts = false
63
+
64
+ self.default_layout = "settings"
65
+
66
+ def initialize
67
+ end
68
+
69
+ def self.setup
70
+ yield self
71
+ end
72
+
73
+ end
@@ -0,0 +1,45 @@
1
+ module IuguSDK
2
+ module Controllers
3
+ module Helpers
4
+ extend ActiveSupport::Concern
5
+
6
+ def search_user_account( account_id )
7
+ return false unless signed_in? and current_user
8
+ current_user.account_users.where( :account_id => account_id ).try(:first)
9
+ end
10
+
11
+ def current_user_account
12
+ @current_user_account ||= search_user_account( session[:current_account_id] )
13
+ end
14
+
15
+ def select_account( resource, account_id=nil )
16
+ if account_id == nil
17
+ account_id = cookies[:last_used_account_id] if cookies[:last_used_account_id]
18
+ end
19
+ selected_account = resource.default_account( account_id )
20
+ if selected_account
21
+ cookies[:last_used_account_id] = { :value => selected_account.id, :expires => 365.days.from_now }
22
+ session[ :current_account_id ] = selected_account.id
23
+ end
24
+ selected_account
25
+ end
26
+
27
+ def is_active?(control, action="", id="")
28
+ if id == ""
29
+ if action == ""
30
+ return true if controller_name == control.gsub("/", "")
31
+ else
32
+ return true if controller_name == control.gsub("/", "") && action_name == action
33
+ end
34
+ else
35
+ return true if controller_name == control.gsub("/", "") && action_name == action && id == params[:id]
36
+ end
37
+ return false
38
+ end
39
+
40
+ def body_classes
41
+ [controller_name,action_name,'page-' + controller_name + '-' + action_name]
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,13 @@
1
+ module IuguSDK
2
+ class Engine < Rails::Engine
3
+
4
+ initializer 'iugusdk.action_controller' do |app|
5
+ ActiveSupport.on_load(:action_controller) do
6
+ include IuguSDK::Controllers::Helpers
7
+ helper_method "search_user_account", "current_user_account", "is_active?", "body_classes"
8
+ ActionController::Base.send(:include, LocaleFilter)
9
+ end
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+ module LocaleFilter
2
+
3
+ def self.included(receiver)
4
+ receiver.append_before_filter :set_locale
5
+ end
6
+
7
+ def set_locale
8
+ @matched_locale_from_browser = request.preferred_language_from(AvailableLanguage.all)
9
+ I18n.locale = current_user.locale || "en" if signed_in?
10
+ end
11
+
12
+ end
@@ -0,0 +1,22 @@
1
+ # RootTenancyUrl will lookup configuration hash and
2
+
3
+ # TODO: Write Tests (PN)
4
+ module IuguSDK
5
+ class RootTenancyUrl
6
+
7
+ # +matches?+ will check a request.host against a set of invalid urls
8
+ #
9
+ # * *Args*:
10
+ # - +request+ -> An ActionDispatch::Request object
11
+ # * *Success*
12
+ # - Return true if request.host is found in the invalid array
13
+ # * *False*
14
+ # - Return true if request.host is not found in the invalid array
15
+ def self.matches?(request)
16
+ application_domain = IuguSDK::application_main_host
17
+ valids = [ application_domain, ['www.',application_domain].join ]
18
+ valids.include?( request.host )
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,27 @@
1
+ # ValidTenancyUrls will lookup configuration hash and
2
+ # deal with invalid urls. Its used by routing to constrain
3
+ # multi tenancy controllers
4
+ # SAAS: File related to SAAS with Custom Domains functionality
5
+
6
+ # TODO: Write Tests (PN)
7
+ module IuguSDK
8
+ class ValidTenancyUrls
9
+
10
+ # +matches?+ will check a request.host against a set of invalid urls
11
+ #
12
+ # * *Args*:
13
+ # - +request+ -> An ActionDispatch::Request object
14
+ # * *Success*
15
+ # - Return true if request.host is found in the invalid array
16
+ # * *False*
17
+ # - Return true if request.host is not found in the invalid array
18
+ def self.matches?(request)
19
+ application_domain = IuguSDK::application_main_host
20
+ invalids = [ application_domain, ['www.',application_domain].join ]
21
+ invalids |= IuguSDK::custom_domain_invalid_prefixes.map { |prefix| [prefix,application_domain].join }
22
+ invalids |= IuguSDK::custom_domain_invalid_hosts
23
+ !invalids.include?( request.host )
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module IuguSDK
2
+ VERSION = "1.0.0.alpha.0"
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :iugusdk do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,41 @@
1
+ module ControllerMacros
2
+ def self.included(base)
3
+ base.extend(ClassMethods)
4
+ end
5
+
6
+ module ClassMethods
7
+ def it_should_require_login_for_actions(*actions)
8
+ actions.each do |action|
9
+ it "#{action} should redirect if no user signed in" do
10
+ get action
11
+ response.should_not be_success
12
+ end
13
+ end
14
+ end
15
+
16
+ def it_should_redirect_to_app_main_for_actions(*actions)
17
+ actions.each do |action|
18
+ it "#{action} should redirect if no user signed in" do
19
+ get action
20
+ response.should redirect_to IuguSDK::app_main_url
21
+ end
22
+ end
23
+ end
24
+
25
+ def login_as_user
26
+ before(:each) do
27
+ @request.env["devise.mapping"] = Devise.mappings[:user]
28
+ user = @user if @user
29
+ if user.nil?
30
+ user = Fabricate(:user, :email => "teste@teste.com", :password => "123456", :password_confirmation => "123456" )
31
+ @user = user
32
+ end
33
+ account = Fabricate(:account)
34
+ account.account_users << Fabricate(:account_user, :user => user)
35
+ sign_in user
36
+ # select_account
37
+ end
38
+ end
39
+ end
40
+
41
+ end
@@ -0,0 +1,155 @@
1
+ require 'spec_helper'
2
+
3
+ describe Iugu::AccountController do
4
+ context "index" do
5
+ login_as_user
6
+ before do
7
+ get :index
8
+ end
9
+
10
+ it { response.should render_template 'iugu/settings/accounts' }
11
+
12
+ end
13
+
14
+ context "show" do
15
+
16
+ context "with id param" do
17
+ login_as_user
18
+ before do
19
+ get :view, :id => @user.accounts.first.id
20
+ end
21
+
22
+ it { response.should render_template 'iugu/settings/account' }
23
+ end
24
+
25
+ context "without id param" do
26
+ login_as_user
27
+ before do
28
+ get :view
29
+ end
30
+
31
+ it { response.should render_template 'iugu/settings/account' }
32
+ end
33
+
34
+ end
35
+
36
+ context "destroy" do
37
+ login_as_user
38
+ context "when using right id" do
39
+ before do
40
+ get :destroy, :id => @user.accounts.first.id
41
+ end
42
+
43
+ it { response.should redirect_to account_settings_path }
44
+
45
+ it 'should start destruction job' do
46
+ @user.accounts.first.destroying?.should be_true
47
+ end
48
+ end
49
+
50
+ context "when using right id" do
51
+ before do
52
+ get :destroy, :id => 31241
53
+ end
54
+
55
+ it { response.should redirect_to account_settings_path }
56
+
57
+ end
58
+
59
+ context "when user is not the owner" do
60
+ before(:each) do
61
+ @account_user = @user.accounts.first.account_users.find_by_user_id(@user.id)
62
+ @account = @user.accounts.first
63
+ @account.account_users << Fabricate(:account_user) { user Fabricate(:user) { email "notowner@account.test" } }
64
+ @account_user.roles.destroy_all
65
+ @account_user.roles << AccountRole.create(:name => "user")
66
+ get :destroy, :id => @user.accounts.first.id
67
+ end
68
+
69
+ it { response.should redirect_to account_settings_path }
70
+
71
+ it 'should not destroy the account' do
72
+ @user.accounts.first.destroying?.should be_false
73
+ end
74
+
75
+ end
76
+
77
+ end
78
+
79
+ context "cancel_destruction" do
80
+ login_as_user
81
+ before do
82
+ @user.accounts.first.destroy
83
+ end
84
+
85
+ context "when using right id" do
86
+ before do
87
+ get :cancel_destruction, :id => @user.accounts.first.id
88
+ end
89
+
90
+ it { response.should redirect_to account_settings_path }
91
+
92
+ it 'should start destruction job' do
93
+ @user.accounts.first.destroying?.should be_false
94
+ end
95
+ end
96
+
97
+ context "when using wrong id" do
98
+ before do
99
+ get :cancel_destruction, :id => 987213
100
+ end
101
+
102
+ it { response.should redirect_to account_settings_path }
103
+
104
+ end
105
+ end
106
+
107
+ context "select" do
108
+ login_as_user
109
+ before do
110
+ get :select, :id => @user.accounts.first.id
111
+ end
112
+
113
+ it { response.should redirect_to account_settings_path }
114
+
115
+ end
116
+
117
+ context "update" do
118
+ login_as_user
119
+ before(:each) do
120
+ put :update, :id => @user.accounts.first.id, :account => { :name => "fudum" }
121
+ end
122
+
123
+ it { response.should redirect_to account_view_path(@user.accounts.first.id) }
124
+
125
+ it 'should update account name' do
126
+ @user.accounts.first.name.should == "fudum"
127
+ end
128
+
129
+ it 'should raise error if receive an invalid id' do
130
+ lambda {
131
+ put :update, :id => 892738912731893719237, :account => { :name => "fudum" }
132
+ }.should raise_error ActionController::RoutingError
133
+ end
134
+
135
+ end
136
+
137
+ context "create" do
138
+ login_as_user
139
+ before(:each) do
140
+ post :create
141
+ end
142
+
143
+ it { response.should redirect_to account_settings_path }
144
+
145
+ it 'should create an account to current_user' do
146
+ lambda do
147
+ post :create
148
+ end.should change(@user.accounts, :count).by(1)
149
+ end
150
+
151
+
152
+ end
153
+
154
+
155
+ end