typus 1.0.0.pre8 → 1.0.0.pre9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (247) hide show
  1. data/CHANGELOG +4 -6
  2. data/Gemfile +16 -13
  3. data/Gemfile.lock +26 -2
  4. data/Rakefile +2 -3
  5. data/app/controllers/admin/base_controller.rb +3 -5
  6. data/app/controllers/admin/resources_controller.rb +24 -26
  7. data/app/helpers/admin/base_helper.rb +14 -22
  8. data/app/helpers/admin/dashboard_helper.rb +2 -5
  9. data/app/helpers/admin/filters_helper.rb +6 -8
  10. data/app/helpers/admin/form_helper.rb +3 -9
  11. data/app/helpers/admin/preview_helper.rb +4 -6
  12. data/app/helpers/admin/relationships_helper.rb +9 -11
  13. data/app/helpers/admin/resources_helper.rb +6 -24
  14. data/app/helpers/admin/search_helper.rb +1 -1
  15. data/app/helpers/admin/sidebar_helper.rb +12 -15
  16. data/app/helpers/admin/table_helper.rb +13 -13
  17. data/app/views/admin/dashboard/show.html.erb +1 -1
  18. data/app/views/admin/helpers/_apps.html.erb +4 -3
  19. data/app/views/admin/helpers/_header.html.erb +2 -2
  20. data/app/views/admin/helpers/dashboard/_applications.html.erb +3 -3
  21. data/app/views/admin/helpers/dashboard/_resources.html.erb +17 -13
  22. data/app/views/admin/helpers/filters/_filters.html.erb +9 -27
  23. data/app/views/admin/helpers/resources/_pagination.html.erb +8 -9
  24. data/app/views/admin/helpers/search/_search.html.erb +1 -1
  25. data/app/views/admin/mailer/reset_password_link.text.erb +3 -0
  26. data/app/views/admin/resources/_form.html.erb +4 -4
  27. data/app/views/admin/resources/edit.html.erb +2 -3
  28. data/app/views/admin/resources/index.html.erb +15 -13
  29. data/app/views/admin/resources/new.html.erb +2 -2
  30. data/app/views/admin/resources/show.html.erb +1 -2
  31. data/app/views/admin/templates/_boolean.html.erb +1 -1
  32. data/app/views/admin/templates/_has_many.html.erb +2 -4
  33. data/app/views/admin/templates/_has_n.html.erb +1 -1
  34. data/app/views/admin/templates/_selector.html.erb +0 -1
  35. data/app/views/admin/templates/_string.html.erb +1 -1
  36. data/app/views/layouts/admin/session.html.erb +1 -1
  37. data/config/available_locales/ca.yml +3 -5
  38. data/config/available_locales/de.yml +2 -4
  39. data/config/available_locales/es.yml +2 -4
  40. data/config/available_locales/fr.yml +40 -39
  41. data/config/available_locales/fr_models.yml +2 -2
  42. data/config/available_locales/hu.yml +3 -5
  43. data/config/available_locales/it.yml +0 -4
  44. data/config/available_locales/language.yml.template +2 -4
  45. data/config/available_locales/pt-BR.yml +2 -4
  46. data/config/available_locales/ru.yml +2 -4
  47. data/config/routes.rb +1 -0
  48. data/lib/generators/templates/config/initializers/typus.rb +5 -5
  49. data/lib/generators/templates/config/initializers/typus_authentication.rb +5 -5
  50. data/lib/generators/templates/config/initializers/typus_resources.rb +7 -7
  51. data/lib/generators/templates/config/typus/README +11 -13
  52. data/lib/generators/templates/controller.rb +0 -2
  53. data/lib/generators/templates/functional_test.rb +4 -15
  54. data/lib/generators/typus/migration_generator.rb +0 -1
  55. data/lib/support/active_record.rb +18 -9
  56. data/lib/support/fake_user.rb +42 -0
  57. data/lib/support/object.rb +1 -0
  58. data/lib/support/string.rb +0 -32
  59. data/lib/tasks/typus.rake +0 -8
  60. data/lib/typus.rb +34 -18
  61. data/lib/typus/authentication/base.rb +26 -0
  62. data/lib/typus/authentication/http_basic.rb +22 -0
  63. data/lib/typus/authentication/none.rb +19 -0
  64. data/lib/typus/authentication/session.rb +190 -0
  65. data/lib/typus/format.rb +12 -19
  66. data/lib/typus/orm/active_record.rb +13 -51
  67. data/lib/typus/resources.rb +0 -9
  68. data/lib/typus/version.rb +1 -1
  69. data/test/factories.rb +43 -0
  70. data/test/fixtures/rails_app/app/controllers/application_controller.rb +0 -1
  71. data/test/fixtures/rails_app/app/models/page.rb +0 -4
  72. data/test/fixtures/rails_app/config/application.rb +6 -3
  73. data/test/fixtures/rails_app/config/database.yml +12 -20
  74. data/test/fixtures/rails_app/config/typus/application.yml +4 -8
  75. data/test/fixtures/rails_app/db/test.sqlite3 +0 -0
  76. data/test/fixtures/rails_app/log/test.log +227115 -0
  77. data/test/fixtures/rails_app/tmp/export-posts-20101012213057.csv +2 -0
  78. data/test/fixtures/rails_app/tmp/export-posts-20101012213132.csv +2 -0
  79. data/test/fixtures/rails_app/tmp/export-posts-20101012213234.csv +2 -0
  80. data/test/fixtures/rails_app/tmp/export-posts-20101012213506.csv +2 -0
  81. data/test/fixtures/rails_app/tmp/export-posts-20101012215057.csv +2 -0
  82. data/test/fixtures/rails_app/tmp/export-posts-20101012215217.csv +2 -0
  83. data/test/fixtures/rails_app/tmp/export-posts-20101012215415.csv +2 -0
  84. data/test/fixtures/rails_app/tmp/export-posts-20101012215443.csv +2 -0
  85. data/test/fixtures/rails_app/tmp/export-posts-20101012215509.csv +2 -0
  86. data/test/fixtures/rails_app/tmp/export-posts-20101012215528.csv +2 -0
  87. data/test/fixtures/rails_app/tmp/export-posts-20101012215551.csv +2 -0
  88. data/test/fixtures/rails_app/tmp/export-posts-20101012215615.csv +2 -0
  89. data/test/fixtures/rails_app/tmp/export-posts-20101012215640.csv +2 -0
  90. data/test/fixtures/rails_app/tmp/export-posts-20101012215714.csv +2 -0
  91. data/test/fixtures/rails_app/tmp/export-posts-20101012215744.csv +2 -0
  92. data/test/fixtures/rails_app/tmp/export-posts-20101012215814.csv +2 -0
  93. data/test/fixtures/rails_app/tmp/export-posts-20101012215836.csv +2 -0
  94. data/test/fixtures/rails_app/tmp/export-posts-20101012215906.csv +2 -0
  95. data/test/fixtures/rails_app/tmp/export-posts-20101012220659.csv +2 -0
  96. data/test/fixtures/rails_app/tmp/export-posts-20101012221043.csv +2 -0
  97. data/test/fixtures/rails_app/tmp/export-posts-20101012221258.csv +2 -0
  98. data/test/fixtures/rails_app/tmp/export-posts-20101012222558.csv +2 -0
  99. data/test/fixtures/rails_app/tmp/export-posts-20101012222752.csv +2 -0
  100. data/test/fixtures/rails_app/tmp/export-posts-20101012222848.csv +2 -0
  101. data/test/fixtures/rails_app/tmp/export-posts-20101012223433.csv +2 -0
  102. data/test/fixtures/rails_app/tmp/export-posts-20101012223535.csv +2 -0
  103. data/test/fixtures/rails_app/tmp/export-posts-20101012224003.csv +2 -0
  104. data/test/fixtures/rails_app/tmp/export-posts-20101012224052.csv +2 -0
  105. data/test/fixtures/rails_app/tmp/export-posts-20101012224109.csv +2 -0
  106. data/test/fixtures/rails_app/tmp/export-posts-20101012224139.csv +2 -0
  107. data/test/fixtures/rails_app/tmp/export-posts-20101012224205.csv +2 -0
  108. data/test/fixtures/rails_app/tmp/export-posts-20101012224243.csv +2 -0
  109. data/test/fixtures/rails_app/tmp/export-posts-20101012225119.csv +2 -0
  110. data/test/fixtures/rails_app/tmp/export-posts-20101013063215.csv +2 -0
  111. data/test/fixtures/rails_app/tmp/export-posts-20101013063300.csv +2 -0
  112. data/test/fixtures/rails_app/tmp/export-posts-20101013063352.csv +2 -0
  113. data/test/fixtures/rails_app/tmp/export-posts-20101013063427.csv +2 -0
  114. data/test/fixtures/rails_app/tmp/export-posts-20101013063448.csv +2 -0
  115. data/test/fixtures/rails_app/tmp/export-posts-20101013063530.csv +2 -0
  116. data/test/fixtures/rails_app/tmp/export-posts-20101013063559.csv +2 -0
  117. data/test/fixtures/rails_app/tmp/export-posts-20101013063646.csv +2 -0
  118. data/test/fixtures/rails_app/tmp/export-posts-20101013063737.csv +2 -0
  119. data/test/fixtures/rails_app/tmp/export-posts-20101013063822.csv +2 -0
  120. data/test/fixtures/rails_app/tmp/export-posts-20101013063837.csv +2 -0
  121. data/test/fixtures/rails_app/tmp/export-posts-20101013063919.csv +2 -0
  122. data/test/fixtures/rails_app/tmp/export-posts-20101013063939.csv +2 -0
  123. data/test/fixtures/rails_app/tmp/export-posts-20101013063952.csv +2 -0
  124. data/test/fixtures/rails_app/tmp/export-posts-20101013064220.csv +2 -0
  125. data/test/fixtures/rails_app/tmp/export-posts-20101013064253.csv +2 -0
  126. data/test/fixtures/rails_app/tmp/export-posts-20101013064318.csv +2 -0
  127. data/test/fixtures/rails_app/tmp/export-posts-20101013064404.csv +2 -0
  128. data/test/fixtures/rails_app/tmp/export-posts-20101013064452.csv +2 -0
  129. data/test/fixtures/rails_app/tmp/export-posts-20101013064536.csv +2 -0
  130. data/test/fixtures/rails_app/tmp/export-posts-20101013064652.csv +2 -0
  131. data/test/fixtures/rails_app/tmp/export-posts-20101013064845.csv +2 -0
  132. data/test/fixtures/rails_app/tmp/export-posts-20101013065023.csv +2 -0
  133. data/test/fixtures/rails_app/tmp/export-posts-20101013065137.csv +2 -0
  134. data/test/fixtures/rails_app/tmp/export-posts-20101013065713.csv +2 -0
  135. data/test/fixtures/rails_app/tmp/export-posts-20101013065954.csv +2 -0
  136. data/test/fixtures/rails_app/tmp/export-posts-20101013070057.csv +2 -0
  137. data/test/fixtures/rails_app/tmp/export-posts-20101013070116.csv +2 -0
  138. data/test/fixtures/rails_app/tmp/export-posts-20101013070156.csv +2 -0
  139. data/test/fixtures/rails_app/tmp/export-posts-20101013070349.csv +2 -0
  140. data/test/fixtures/rails_app/tmp/export-posts-20101013070429.csv +2 -0
  141. data/test/fixtures/rails_app/tmp/export-posts-20101013070448.csv +2 -0
  142. data/test/fixtures/rails_app/tmp/export-posts-20101013070514.csv +2 -0
  143. data/test/fixtures/rails_app/tmp/export-posts-20101013070709.csv +2 -0
  144. data/test/fixtures/rails_app/tmp/export-posts-20101013070745.csv +2 -0
  145. data/test/fixtures/rails_app/tmp/export-posts-20101013070809.csv +2 -0
  146. data/test/fixtures/rails_app/tmp/export-posts-20101013070905.csv +2 -0
  147. data/test/fixtures/rails_app/tmp/export-posts-20101013070955.csv +2 -0
  148. data/test/fixtures/rails_app/tmp/export-posts-20101013071116.csv +2 -0
  149. data/test/fixtures/rails_app/tmp/export-posts-20101013071209.csv +2 -0
  150. data/test/fixtures/rails_app/tmp/export-posts-20101013071335.csv +2 -0
  151. data/test/fixtures/rails_app/tmp/export-posts-20101013071632.csv +2 -0
  152. data/test/fixtures/rails_app/tmp/export-posts-20101013071643.csv +2 -0
  153. data/test/fixtures/rails_app/tmp/export-posts-20101013071735.csv +2 -0
  154. data/test/fixtures/rails_app/tmp/export-posts-20101013071749.csv +2 -0
  155. data/test/fixtures/rails_app/tmp/export-posts-20101013072030.csv +2 -0
  156. data/test/fixtures/rails_app/tmp/export-posts-20101013072050.csv +2 -0
  157. data/test/fixtures/rails_app/tmp/export-posts-20101013072108.csv +2 -0
  158. data/test/fixtures/rails_app/tmp/export-posts-20101013072713.csv +2 -0
  159. data/test/fixtures/rails_app/tmp/export-posts-20101013072751.csv +2 -0
  160. data/test/fixtures/rails_app/tmp/export-posts-20101013072912.csv +2 -0
  161. data/test/fixtures/rails_app/tmp/export-posts-20101013074546.csv +2 -0
  162. data/test/fixtures/rails_app/tmp/export-posts-20101018180512.csv +2 -0
  163. data/test/fixtures/rails_app/tmp/export-posts-20101018183359.csv +2 -0
  164. data/test/fixtures/rails_app/tmp/export-posts-20101018183608.csv +2 -0
  165. data/test/fixtures/rails_app/tmp/export-posts-20101018183759.csv +2 -0
  166. data/test/functional/admin/account_controller_test.rb +1 -1
  167. data/test/functional/admin/{resources_controller_assets_relationships.rb → assets_controller_test.rb} +12 -16
  168. data/test/functional/admin/categories_controller_test.rb +62 -0
  169. data/test/functional/admin/{resources_controller_comments_toggle_test.rb → comments_controller_test.rb} +0 -0
  170. data/test/functional/admin/dashboard_controller_test.rb +34 -2
  171. data/test/functional/admin/posts_controller_test.rb +548 -0
  172. data/test/functional/admin/session_controller_test.rb +2 -2
  173. data/test/functional/admin/{resources_controller_tableless_resource_test.rb → status_controller_test.rb} +0 -0
  174. data/test/functional/admin/{resources_controller_typus_users_test.rb → typus_users_controller_test.rb} +2 -2
  175. data/test/helpers/admin/base_helper_test.rb +35 -37
  176. data/test/helpers/admin/dashboard_helper_test.rb +4 -8
  177. data/test/helpers/admin/form_helper_test.rb +9 -34
  178. data/test/helpers/admin/resources_helper_test.rb +28 -16
  179. data/test/helpers/admin/sidebar_helper_test.rb +14 -27
  180. data/test/helpers/admin/table_helper_test.rb +24 -68
  181. data/test/integration/login_test.rb +13 -0
  182. data/test/integration_test_helper.rb +21 -0
  183. data/test/lib/support/active_record_test.rb +72 -21
  184. data/test/lib/support/array_test.rb +2 -6
  185. data/test/lib/support/string_test.rb +21 -30
  186. data/test/lib/typus/active_record_test.rb +162 -100
  187. data/test/lib/typus/resource_test.rb +2 -3
  188. data/test/lib/typus_test.rb +25 -22
  189. data/test/test_helper.rb +4 -17
  190. data/test/unit/admin/mailer_test.rb +2 -2
  191. data/test/unit/typus_user_roles_test.rb +23 -23
  192. data/test/unit/typus_user_test.rb +30 -24
  193. data/typus.gemspec +0 -1
  194. metadata +111 -60
  195. data/app/models/admin/fake_user.rb +0 -46
  196. data/lib/generators/templates/model.yml +0 -10
  197. data/lib/typus/authentication.rb +0 -241
  198. data/lib/vendor/paginator.rb +0 -143
  199. data/test/factories/assets.rb +0 -5
  200. data/test/factories/categories.rb +0 -3
  201. data/test/factories/comments.rb +0 -6
  202. data/test/factories/pages.rb +0 -5
  203. data/test/factories/pictures.rb +0 -7
  204. data/test/factories/posts.rb +0 -6
  205. data/test/factories/typus_users.rb +0 -8
  206. data/test/fixtures/rails_app/README +0 -244
  207. data/test/fixtures/rails_app/app/helpers/application_helper.rb +0 -2
  208. data/test/fixtures/rails_app/app/views/layouts/application.html.erb +0 -14
  209. data/test/fixtures/rails_app/config/environments/development.rb +0 -19
  210. data/test/fixtures/rails_app/config/environments/production.rb +0 -42
  211. data/test/fixtures/rails_app/config/initializers/acts_as_list.rb +0 -258
  212. data/test/fixtures/rails_app/config/initializers/acts_as_tree.rb +0 -98
  213. data/test/fixtures/rails_app/config/initializers/backtrace_silencers.rb +0 -7
  214. data/test/fixtures/rails_app/config/initializers/inflections.rb +0 -10
  215. data/test/fixtures/rails_app/config/initializers/mime_types.rb +0 -5
  216. data/test/fixtures/rails_app/config/locales/en.yml +0 -5
  217. data/test/fixtures/rails_app/db/seeds.rb +0 -7
  218. data/test/fixtures/rails_app/public/404.html +0 -26
  219. data/test/fixtures/rails_app/public/422.html +0 -26
  220. data/test/fixtures/rails_app/public/500.html +0 -26
  221. data/test/fixtures/rails_app/public/favicon.ico +0 -0
  222. data/test/fixtures/rails_app/public/images/rails.png +0 -0
  223. data/test/fixtures/rails_app/public/index.html +0 -279
  224. data/test/fixtures/rails_app/public/javascripts/application.js +0 -2
  225. data/test/fixtures/rails_app/public/javascripts/controls.js +0 -965
  226. data/test/fixtures/rails_app/public/javascripts/dragdrop.js +0 -974
  227. data/test/fixtures/rails_app/public/javascripts/effects.js +0 -1123
  228. data/test/fixtures/rails_app/public/javascripts/prototype.js +0 -4874
  229. data/test/fixtures/rails_app/public/javascripts/rails.js +0 -118
  230. data/test/fixtures/rails_app/public/robots.txt +0 -5
  231. data/test/fixtures/rails_app/script/rails +0 -9
  232. data/test/functional/admin/dashboard_controller_http_basic_test.rb +0 -24
  233. data/test/functional/admin/dashboard_controller_none_test.rb +0 -18
  234. data/test/functional/admin/resources_controller_categories_before_test.rb +0 -10
  235. data/test/functional/admin/resources_controller_categories_lists_test.rb +0 -44
  236. data/test/functional/admin/resources_controller_categories_views_test.rb +0 -10
  237. data/test/functional/admin/resources_controller_posts_before_test.rb +0 -10
  238. data/test/functional/admin/resources_controller_posts_crud_custom_test.rb +0 -27
  239. data/test/functional/admin/resources_controller_posts_crud_test.rb +0 -44
  240. data/test/functional/admin/resources_controller_posts_formats_test.rb +0 -39
  241. data/test/functional/admin/resources_controller_posts_forms_test.rb +0 -58
  242. data/test/functional/admin/resources_controller_posts_permissions_test.rb +0 -100
  243. data/test/functional/admin/resources_controller_posts_relationships_test.rb +0 -91
  244. data/test/functional/admin/resources_controller_posts_roles.rb +0 -52
  245. data/test/functional/admin/resources_controller_posts_views_test.rb +0 -143
  246. data/test/lib/vendor/paginator_test.rb +0 -141
  247. data/typus-1.0.0.pre7.gem +0 -0
data/lib/tasks/typus.rake CHANGED
@@ -8,12 +8,4 @@ namespace :typus do
8
8
  end
9
9
  end
10
10
 
11
- desc "Install acts_as_list, acts_as_tree and paperclip."
12
- task :misc do
13
- plugins = [ "git://github.com/thoughtbot/paperclip.git",
14
- "git://github.com/rails/acts_as_list.git",
15
- "git://github.com/rails/acts_as_tree.git" ]
16
- system "rails plugin install #{plugins.join(" ")} --force"
17
- end
18
-
19
11
  end
data/lib/typus.rb CHANGED
@@ -5,67 +5,83 @@ require "support/array"
5
5
  require "support/hash"
6
6
  require "support/object"
7
7
  require "support/string"
8
+
8
9
  require "typus/engine"
9
- require "typus/configuration"
10
- require "typus/resources"
11
10
  require "typus/orm/active_record"
12
11
  require "typus/user"
13
- require "vendor/paginator"
12
+
13
+ autoload :FakeUser, "support/fake_user"
14
14
 
15
15
  module Typus
16
16
 
17
- # Define the application name.
17
+ autoload :Configuration, "typus/configuration"
18
+ autoload :Resources, "typus/resources"
19
+
20
+ module Authentication
21
+ autoload :Base, "typus/authentication/base"
22
+ autoload :None, "typus/authentication/none"
23
+ autoload :HttpBasic, "typus/authentication/http_basic"
24
+ autoload :Session, "typus/authentication/session"
25
+ end
26
+
18
27
  mattr_accessor :admin_title
19
28
  @@admin_title = "Typus"
20
29
 
21
- # Define a subtitle
22
30
  mattr_accessor :admin_sub_title
23
31
  @@admin_sub_title = <<-CODE
24
32
  <a href="http://core.typuscms.com/">typus</a> by <a href="http://intraducibles.com">intraducibles.com</a>
25
33
  CODE
26
34
 
27
- # Authentication mechanism: none, basic, advanced
35
+ ##
36
+ # Available Authentication Mechanisms are:
37
+ #
38
+ # - none
39
+ # - basic: Uses http authentication
40
+ # - session
41
+ #
28
42
  mattr_accessor :authentication
29
43
  @@authentication = :none
30
44
 
31
- # Define the configuration folder.
32
45
  mattr_accessor :config_folder
33
46
  @@config_folder = "config/typus"
34
47
 
35
- # Define the username
36
48
  mattr_accessor :username
37
49
  @@username = "admin"
38
50
 
39
- # Define the password: Used as a default password and for the http
40
- # authentication.
51
+ ##
52
+ # Define a password.
53
+ #
54
+ # Used as default password for http and advances authentication.
55
+ #
41
56
  mattr_accessor :password
42
57
  @@password = "columbia"
43
58
 
59
+ ##
44
60
  # Configure the e-mail address which will be shown in Admin::Mailer.
61
+ #
62
+ # When `nil`, the `forgot_password` will be disabled.
63
+ #
45
64
  mattr_accessor :mailer_sender
46
65
  @@mailer_sender = nil
47
66
 
48
- # Define the file preview.
49
67
  mattr_accessor :file_preview
50
68
  @@file_preview = :medium
51
69
 
52
- # Define the file thumbnail.
53
70
  mattr_accessor :file_thumbnail
54
71
  @@file_thumbnail = :thumb
55
72
 
73
+ ##
56
74
  # Defines the default relationship table.
75
+ #
57
76
  mattr_accessor :relationship
58
77
  @@relationship = "typus_users"
59
78
 
60
- # Defines the default master role.
61
79
  mattr_accessor :master_role
62
80
  @@master_role = "admin"
63
81
 
64
- # Defines the default user_class_name.
65
82
  mattr_accessor :user_class_name
66
83
  @@user_class_name = "TypusUser"
67
84
 
68
- # Defines the default user_fk.
69
85
  mattr_accessor :user_fk
70
86
  @@user_fk = "typus_user_id"
71
87
 
@@ -74,8 +90,8 @@ module Typus
74
90
 
75
91
  class << self
76
92
 
77
- # Default way to setup typus. Run rails generate typus to create
78
- # a fresh initializer with all configuration values.
93
+ # Default way to setup typus. Run `rails generate typus` to create a fresh
94
+ # initializer with all configuration values.
79
95
  def setup
80
96
  yield self
81
97
  end
@@ -115,7 +131,7 @@ module Typus
115
131
 
116
132
  def locales
117
133
  human = available_locales.map { |i| locales_mapping[i.to_s] }
118
- available_locales.map { |i| i.to_s }.to_hash_with(human)
134
+ available_locales.map { |i| i.to_s }.to_hash_with(human).invert
119
135
  end
120
136
 
121
137
  def locales_mapping
@@ -0,0 +1,26 @@
1
+ module Typus
2
+
3
+ module Authentication
4
+
5
+ module Base
6
+
7
+ def current_user
8
+ @current_user
9
+ end
10
+
11
+ def authenticate; end
12
+ def check_if_user_can_perform_action_on_user; end
13
+ def check_if_user_can_perform_action_on_resources; end
14
+ def check_if_user_can_perform_action_on_resource; end
15
+ def check_resource_ownership; end
16
+ def check_resource_ownerships; end
17
+ def check_ownership_of_referal_item; end
18
+ def set_attributes_on_create; end
19
+ def set_attributes_on_update; end
20
+ def reload_locales; end
21
+
22
+ end
23
+
24
+ end
25
+
26
+ end
@@ -0,0 +1,22 @@
1
+ module Typus
2
+
3
+ module Authentication
4
+
5
+ module HttpBasic
6
+
7
+ protected
8
+
9
+ include Base
10
+
11
+ def authenticate
12
+ @current_user = FakeUser.new
13
+ authenticate_or_request_with_http_basic(Typus.admin_title) do |user_name, password|
14
+ user_name == Typus.username && password == Typus.password
15
+ end
16
+ end
17
+
18
+ end
19
+
20
+ end
21
+
22
+ end
@@ -0,0 +1,19 @@
1
+ module Typus
2
+
3
+ module Authentication
4
+
5
+ module None
6
+
7
+ protected
8
+
9
+ include Base
10
+
11
+ def authenticate
12
+ @current_user = FakeUser.new
13
+ end
14
+
15
+ end
16
+
17
+ end
18
+
19
+ end
@@ -0,0 +1,190 @@
1
+ module Typus
2
+
3
+ module Authentication
4
+
5
+ module Session
6
+
7
+ protected
8
+
9
+ include Base
10
+
11
+ def authenticate
12
+ if session[:typus_user_id]
13
+ current_user
14
+ else
15
+ back_to = request.env['PATH_INFO'] unless [admin_dashboard_path, admin_path].include?(request.env['PATH_INFO'])
16
+ redirect_to new_admin_session_path(:back_to => back_to)
17
+ end
18
+ end
19
+
20
+ #--
21
+ # Return the current user. If role does not longer exist on the
22
+ # system current_user will be signed out from Typus.
23
+ #++
24
+ def current_user
25
+
26
+ user = Typus.user_class.find(session[:typus_user_id])
27
+
28
+ unless Typus::Configuration.roles.has_key?(user.role)
29
+ raise _t("Role does no longer exists.")
30
+ end
31
+
32
+ unless user.status
33
+ back_to = (request.env['REQUEST_URI'] == admin_dashboard_path) ? nil : request.env['REQUEST_URI']
34
+ raise _t("Typus user has been disabled.")
35
+ end
36
+
37
+ I18n.locale = user.preferences[:locale]
38
+
39
+ return user
40
+
41
+ rescue Exception => error
42
+ session[:typus_user_id] = nil
43
+ redirect_to new_admin_session_path(:back_to => back_to), :notice => error.message
44
+ end
45
+
46
+ #--
47
+ # Action is available on: edit, update, toggle and destroy
48
+ #++
49
+ def check_if_user_can_perform_action_on_user
50
+ return unless @item.kind_of?(Typus.user_class)
51
+
52
+ message = case params[:action]
53
+ when 'edit'
54
+ # Only admin and owner of Typus User can edit.
55
+ if current_user.is_not_root? && (current_user != @item)
56
+ _t("As you're not the admin or the owner of this record you cannot edit it.")
57
+ end
58
+ when 'update'
59
+ # current_user cannot change her role.
60
+ if current_user && !(@item.role == params[@object_name][:role])
61
+ _t("You can't change your role.")
62
+ end
63
+ when 'toggle'
64
+ # Only admin can toggle typus user status, but not herself.
65
+ if current_user.is_root? && (current_user == @item)
66
+ _t("You can't toggle your status.")
67
+ elsif current_user.is_not_root?
68
+ _t("You're not allowed to toggle status.")
69
+ end
70
+ when 'destroy'
71
+ # Admin can remove anything except herself.
72
+ if current_user.is_root? && (current_user == @item)
73
+ _t("You can't remove yourself.")
74
+ elsif current_user.is_not_root?
75
+ _t("You're not allowed to remove Typus Users.")
76
+ end
77
+ end
78
+
79
+ redirect_to set_path, :notice => message if message
80
+ end
81
+
82
+ #--
83
+ # This method checks if the user can perform the requested action.
84
+ # It works on models, so its available on the `resources_controller`.
85
+ #++
86
+ def check_if_user_can_perform_action_on_resources
87
+
88
+ message = case params[:action]
89
+ when 'index', 'show'
90
+ "%{current_user_role} can't display items."
91
+ when 'destroy'
92
+ "%{current_user_role} can't delete this item."
93
+ else
94
+ "%{current_user_role} can't perform action. (%{action})"
95
+ end
96
+
97
+ message = _t(message,
98
+ :current_user_role => current_user.role.capitalize,
99
+ :action => params[:action])
100
+
101
+ unless current_user.can?(params[:action], @resource)
102
+ redirect_to set_path, :notice => message
103
+ end
104
+
105
+ end
106
+
107
+ #--
108
+ # This method checks if the user can perform the requested action.
109
+ # It works on a resource: git, memcached, syslog ...
110
+ #++
111
+ def check_if_user_can_perform_action_on_resource
112
+ controller = params[:controller].remove_prefix
113
+ action = params[:action]
114
+ unless current_user.can?(action, controller.camelize, { :special => true })
115
+ render :text => "Not allowed!", :status => :unprocessable_entity
116
+ end
117
+ end
118
+
119
+ #--
120
+ # If item is owned by another user, we only can perform a
121
+ # show action on the item. Updated item is also blocked.
122
+ #
123
+ # before_filter :check_resource_ownership, :only => [ :edit, :update, :destroy,
124
+ # :toggle, :position,
125
+ # :relate, :unrelate ]
126
+ #++
127
+ def check_resource_ownership
128
+
129
+ # By-pass if current_user is root.
130
+ return if current_user.is_root?
131
+
132
+ condition_typus_users = @item.respond_to?(Typus.relationship) && !@item.send(Typus.relationship).include?(current_user)
133
+ condition_typus_user_id = @item.respond_to?(Typus.user_fk) && !@item.owned_by?(current_user)
134
+
135
+ if condition_typus_users || condition_typus_user_id
136
+ alert = _t("You don't have permission to access this item.")
137
+ redirect_to set_path, :alert => alert
138
+ end
139
+
140
+ end
141
+
142
+ def check_resource_ownerships
143
+
144
+ # By-pass if current_user is root.
145
+ return if current_user.is_root?
146
+
147
+ # Show only related items it @resource has a foreign_key (Typus.user_fk)
148
+ # related to the logged user.
149
+ if @resource.typus_user_id?
150
+ condition = { Typus.user_fk => current_user }
151
+ @conditions = @resource.merge_conditions(@conditions, condition)
152
+ end
153
+
154
+ end
155
+
156
+ def check_ownership_of_referal_item
157
+ return unless params[:resource] && params[:resource_id]
158
+ klass = params[:resource].classify.constantize
159
+ return if !klass.typus_user_id?
160
+ item = klass.find(params[:resource_id])
161
+ raise "You're not owner of this record." unless item.owned_by?(current_user) || current_user.is_root?
162
+ end
163
+
164
+ def set_attributes_on_create
165
+ if @resource.typus_user_id?
166
+ @item.attributes = { Typus.user_fk => current_user.id }
167
+ end
168
+ end
169
+
170
+ def set_attributes_on_update
171
+ if @resource.typus_user_id? && current_user.is_not_root?
172
+ @item.update_attributes(Typus.user_fk => current_user.id)
173
+ end
174
+ end
175
+
176
+ #--
177
+ # Reload current_user when updating to see flash message in the
178
+ # correct locale.
179
+ #++
180
+ def reload_locales
181
+ if @resource.eql?(Typus.user_class)
182
+ I18n.locale = current_user.reload.preferences[:locale]
183
+ end
184
+ end
185
+
186
+ end
187
+
188
+ end
189
+
190
+ end
data/lib/typus/format.rb CHANGED
@@ -1,3 +1,8 @@
1
+ if RUBY_VERSION >= '1.9'
2
+ require 'csv'
3
+ FasterCSV = CSV
4
+ end
5
+
1
6
  module Typus
2
7
 
3
8
  module Format
@@ -5,7 +10,6 @@ module Typus
5
10
  protected
6
11
 
7
12
  def generate_html
8
-
9
13
  items_count = @resource.count(:joins => @joins, :conditions => @conditions)
10
14
  items_per_page = @resource.typus_options_for(:per_page)
11
15
 
@@ -14,7 +18,6 @@ module Typus
14
18
  end
15
19
 
16
20
  @items = @pager.page(params[:page])
17
-
18
21
  end
19
22
 
20
23
  #--
@@ -23,27 +26,13 @@ module Typus
23
26
  # We should find a way to be able to process data.
24
27
  #++
25
28
  def generate_csv
26
-
27
29
  fields = @resource.typus_fields_for(:csv)
28
30
 
29
- require 'csv'
30
- if CSV.const_defined?(:Reader)
31
- # Old CSV version so we enable faster CSV.
32
- begin
33
- require 'fastercsv'
34
- rescue Exception => error
35
- raise error.message
36
- end
37
- csv = FasterCSV
38
- else
39
- csv = CSV
40
- end
41
-
42
31
  filename = Rails.root.join("tmp", "export-#{@resource.to_resource}-#{Time.zone.now.to_s(:number)}.csv")
43
32
 
44
33
  options = { :conditions => @conditions, :batch_size => 1000 }
45
34
 
46
- csv.open(filename, 'w', :col_sep => ';') do |csv|
35
+ FasterCSV.open(filename, 'w', :col_sep => ';') do |csv|
47
36
  csv << fields.keys
48
37
  @resource.find_in_batches(options) do |records|
49
38
  records.each do |record|
@@ -63,11 +52,15 @@ module Typus
63
52
  end
64
53
 
65
54
  send_file filename
55
+ end
66
56
 
57
+ def generate_json
58
+ export(:json)
67
59
  end
68
60
 
69
- def generate_json; export(:json); end
70
- def generate_xml; export(:xml); end
61
+ def generate_xml
62
+ export(:xml)
63
+ end
71
64
 
72
65
  def export(format)
73
66
  fields = @resource.typus_fields_for(format).collect { |i| i.first }