typus 3.0.8 → 3.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +8 -1
- data/README.md +2 -2
- data/Rakefile +6 -14
- data/app/controllers/admin/base_controller.rb +1 -1
- data/app/controllers/admin/dashboard_controller.rb +0 -1
- data/app/controllers/admin/resources_controller.rb +8 -11
- data/app/controllers/admin/session_controller.rb +5 -4
- data/app/helpers/admin/base_helper.rb +9 -2
- data/app/helpers/admin/dashboard_helper.rb +0 -6
- data/app/helpers/admin/display_helper.rb +1 -0
- data/app/helpers/admin/file_preview_helper.rb +0 -2
- data/app/helpers/admin/filters_helper.rb +6 -3
- data/app/helpers/admin/form_helper.rb +2 -4
- data/app/helpers/admin/list_helper.rb +1 -3
- data/app/helpers/admin/relationships_helper.rb +2 -4
- data/app/helpers/admin/resources_helper.rb +0 -2
- data/app/helpers/admin/search_helper.rb +0 -2
- data/app/helpers/admin/sidebar_helper.rb +0 -2
- data/app/helpers/admin/table_helper.rb +3 -6
- data/app/views/admin/account/forgot_password.html.erb +2 -2
- data/app/views/admin/account/new.html.erb +3 -7
- data/app/views/admin/{helpers/dashboard → dashboard}/_applications.html.erb +0 -0
- data/app/views/admin/dashboard/_sidebar.html.erb +1 -1
- data/app/views/admin/dashboard/show.html.erb +7 -1
- data/app/views/admin/helpers/base/_apps.html.erb +1 -1
- data/app/views/admin/helpers/base/_login_info.html.erb +2 -2
- data/app/views/admin/helpers/filters/_filters.html.erb +3 -1
- data/app/views/admin/resources/_form.html.erb +5 -2
- data/app/views/admin/resources/edit.html.erb +1 -1
- data/app/views/admin/resources/index.html.erb +1 -1
- data/app/views/admin/resources/show.html.erb +2 -2
- data/app/views/admin/session/new.html.erb +3 -7
- data/app/views/admin/templates/_belongs_to.html.erb +8 -1
- data/app/views/admin/templates/_belongs_to_with_autocomplete.html.erb +1 -1
- data/app/views/admin/templates/_relate_form.html.erb +1 -1
- data/app/views/admin/templates/_relate_form_with_autocomplete.html.erb +3 -1
- data/app/views/admin/templates/_string.html.erb +1 -1
- data/app/views/admin/templates/_text.html.erb +1 -1
- data/app/views/layouts/admin/base.html.erb +2 -0
- data/app/views/layouts/admin/headless.html.erb +2 -0
- data/app/views/layouts/admin/session.html.erb +6 -0
- data/config/routes.rb +4 -1
- data/lib/support/active_record.rb +0 -10
- data/lib/support/fake_user.rb +4 -6
- data/lib/support/object.rb +4 -0
- data/lib/support/string.rb +0 -8
- data/lib/typus.rb +2 -3
- data/lib/typus/authentication/base.rb +0 -1
- data/lib/typus/authentication/session.rb +22 -29
- data/lib/typus/orm/active_record.rb +5 -5
- data/lib/typus/orm/active_record/admin_user_v1.rb +93 -0
- data/lib/typus/orm/active_record/admin_user_v2.rb +49 -0
- data/lib/typus/orm/active_record/class_methods.rb +23 -143
- data/lib/typus/orm/active_record/user/instance_methods.rb +64 -0
- data/lib/typus/orm/base.rb +170 -0
- data/lib/typus/orm/mongo/class_methods.rb +11 -0
- data/lib/typus/resources.rb +2 -1
- data/lib/typus/version.rb +1 -1
- data/test/app/controllers/admin/account_controller_test.rb +4 -2
- data/test/app/controllers/admin/assets_controller_test.rb +12 -12
- data/test/app/controllers/admin/categories_controller_test.rb +5 -12
- data/test/app/controllers/admin/comments_controller_test.rb +1 -1
- data/test/app/controllers/admin/image_holders_controller_test.rb +1 -1
- data/test/app/controllers/admin/invoices_controller_test.rb +1 -1
- data/test/app/controllers/admin/posts_controller_test.rb +32 -32
- data/test/app/controllers/admin/projects_controller_test.rb +1 -1
- data/test/app/controllers/admin/typus_users_controller_test.rb +13 -17
- data/test/app/controllers/admin/users_controller_test.rb +9 -9
- data/test/app/helpers/admin/list_helper_test.rb +17 -0
- data/test/app/models/admin_user_test.rb +5 -0
- data/test/app/models/typus_user_roles_test.rb +1 -0
- data/test/app/models/typus_user_test.rb +45 -11
- data/test/factories.rb +1 -1
- data/test/fixtures/rails_app/app/controllers/admin/hits_controller.rb +40 -0
- data/test/fixtures/rails_app/app/controllers/admin_user.rb +3 -0
- data/test/fixtures/rails_app/app/models/asset.rb +0 -6
- data/test/fixtures/rails_app/app/models/hit.rb +27 -0
- data/test/fixtures/rails_app/app/views/admin/hits/_edit.html.erb +7 -0
- data/test/fixtures/rails_app/app/views/admin/hits/_index.html.erb +3 -0
- data/test/fixtures/rails_app/app/views/admin/hits/index.html.erb +28 -0
- data/test/fixtures/rails_app/config/boot.rb +3 -10
- data/test/fixtures/rails_app/config/deploy.rb +1 -1
- data/test/fixtures/rails_app/config/mongoid.yml +20 -0
- data/test/fixtures/rails_app/config/typus/crud_extended.yml +2 -0
- data/test/fixtures/rails_app/config/typus/mongo_db.yml +4 -0
- data/test/fixtures/rails_app/config/typus/mongo_db_roles.yml +2 -0
- data/test/fixtures/rails_app/db/schema.rb +11 -0
- data/test/lib/support/fake_user_test.rb +4 -0
- data/test/lib/support/string_test.rb +0 -18
- data/test/lib/typus/orm/active_record/class_methods_test.rb +14 -2
- data/test/lib/typus/orm/active_record/search_test.rb +1 -1
- data/test/lib/typus_test.rb +2 -1
- data/typus.gemspec +1 -1
- metadata +32 -45
- data/lib/typus/orm/active_record/instance_methods.rb +0 -13
- data/lib/typus/orm/active_record/user.rb +0 -157
- data/test/fixtures/rails_app/public/javascripts/application.js +0 -2
- data/test/fixtures/rails_app/public/javascripts/controls.js +0 -965
- data/test/fixtures/rails_app/public/javascripts/dragdrop.js +0 -974
- data/test/fixtures/rails_app/public/javascripts/effects.js +0 -1123
- data/test/fixtures/rails_app/public/javascripts/prototype.js +0 -6001
- data/test/fixtures/rails_app/public/javascripts/rails.js +0 -175
@@ -19,7 +19,7 @@ class Admin::UsersControllerTest < ActionController::TestCase
|
|
19
19
|
end
|
20
20
|
|
21
21
|
should_eventually "be able to destroy items" do
|
22
|
-
get :destroy,
|
22
|
+
get :destroy, :id => @user.id, :method => :delete
|
23
23
|
|
24
24
|
assert_response :redirect
|
25
25
|
assert_equal "User successfully removed.", flash[:notice]
|
@@ -36,10 +36,10 @@ class Admin::UsersControllerTest < ActionController::TestCase
|
|
36
36
|
end
|
37
37
|
|
38
38
|
should "filter by projects" do
|
39
|
-
get :index,
|
39
|
+
get :index, :projects => @project_1.id
|
40
40
|
assert_equal [@user_1], assigns(:items)
|
41
41
|
|
42
|
-
get :index,
|
42
|
+
get :index, :projects => @project_2.id
|
43
43
|
assert_not_equal [@user_1], assigns(:items)
|
44
44
|
end
|
45
45
|
|
@@ -61,10 +61,10 @@ class Admin::UsersControllerTest < ActionController::TestCase
|
|
61
61
|
|
62
62
|
should "work" do
|
63
63
|
assert_difference('@project.collaborators.count', -1) do
|
64
|
-
post :unrelate,
|
65
|
-
|
66
|
-
|
67
|
-
|
64
|
+
post :unrelate, :id => @user.id,
|
65
|
+
:resource => 'Project',
|
66
|
+
:resource_id => @project.id,
|
67
|
+
:association_name => "collaborators"
|
68
68
|
end
|
69
69
|
assert_response :redirect
|
70
70
|
assert_redirected_to @request.env['HTTP_REFERER']
|
@@ -92,11 +92,11 @@ class Admin::UsersControllerTest < ActionController::TestCase
|
|
92
92
|
post = User.first
|
93
93
|
post.update_attributes(:name => "fesplugas")
|
94
94
|
|
95
|
-
get :autocomplete,
|
95
|
+
get :autocomplete, :term => "jmeiss"
|
96
96
|
assert_response :success
|
97
97
|
assert_equal 0, assigns(:items).size
|
98
98
|
|
99
|
-
get :autocomplete,
|
99
|
+
get :autocomplete, :term => "fesplugas"
|
100
100
|
assert_response :success
|
101
101
|
assert_equal 1, assigns(:items).size
|
102
102
|
end
|
@@ -25,6 +25,23 @@ class Admin::ListHelperTest < ActiveSupport::TestCase
|
|
25
25
|
assert list_actions.empty?
|
26
26
|
end
|
27
27
|
|
28
|
+
should "not include actions that a role cannot perform" do
|
29
|
+
@resource = mock
|
30
|
+
@resource.stubs(:name).returns("resource")
|
31
|
+
|
32
|
+
self.stubs(:link_to).returns("some_link")
|
33
|
+
sample_action = ["a body", {:action => :some_action}, {}]
|
34
|
+
self.stubs(:resources_actions).returns([sample_action] * 3)
|
35
|
+
|
36
|
+
admin_user = mock
|
37
|
+
admin_user.stubs(:can?).returns(true, false, true)
|
38
|
+
self.stubs(:admin_user).returns(admin_user)
|
39
|
+
self.stubs(:params).returns({:action => 'some_other_action'})
|
40
|
+
|
41
|
+
results = list_actions.split("/")
|
42
|
+
assert_equal 2, results.size
|
43
|
+
end
|
44
|
+
|
28
45
|
should_eventually "return an array with our custom actions"
|
29
46
|
|
30
47
|
end
|
@@ -8,22 +8,38 @@ class TypusUserTest < ActiveSupport::TestCase
|
|
8
8
|
'test@example',
|
9
9
|
'test@example.c',
|
10
10
|
'testexample.com' ].each do |value|
|
11
|
-
|
11
|
+
should "not allow #{value}" do
|
12
|
+
assert !Factory.build(:typus_user, :email => value).valid?
|
13
|
+
end
|
12
14
|
end
|
13
15
|
|
14
16
|
[ 'test+filter@example.com',
|
15
17
|
'test.filter@example.com',
|
16
18
|
'test@example.co.uk',
|
17
19
|
'test@example.es' ].each do |value|
|
18
|
-
should
|
20
|
+
should "allow #{value}" do
|
21
|
+
assert Factory.build(:typus_user, :email => value).valid?
|
22
|
+
end
|
19
23
|
end
|
20
24
|
|
21
|
-
should validate_presence_of :email
|
22
|
-
|
25
|
+
should "validate_presence_of :email" do
|
26
|
+
assert !Factory.build(:typus_user, :email => nil).valid?
|
27
|
+
end
|
23
28
|
|
24
|
-
|
29
|
+
should "validate_presence_of :role" do
|
30
|
+
assert !Factory.build(:typus_user, :role => nil).valid?
|
31
|
+
end
|
25
32
|
|
26
|
-
should
|
33
|
+
should "validate password length" do
|
34
|
+
assert !Factory.build(:typus_user, :password => "0"*5).valid?, "5"
|
35
|
+
assert Factory.build(:typus_user, :password => "0"*6).valid?, "6"
|
36
|
+
assert Factory.build(:typus_user, :password => "0"*40).valid?, "40"
|
37
|
+
assert !Factory.build(:typus_user, :password => "0"*41).valid?, "41"
|
38
|
+
end
|
39
|
+
|
40
|
+
should "not allow_mass_assignment_of :status" do
|
41
|
+
assert TypusUser.attr_protected.include?("status")
|
42
|
+
end
|
27
43
|
|
28
44
|
should "verify columns" do
|
29
45
|
expected = %w(id first_name last_name email role status salt crypted_password token preferences created_at updated_at).sort
|
@@ -52,6 +68,11 @@ class TypusUserTest < ActiveSupport::TestCase
|
|
52
68
|
assert TypusUser.generate(options).valid?
|
53
69
|
end
|
54
70
|
|
71
|
+
should "have set a default locale" do
|
72
|
+
options = { :email => 'demo@example.com', :role => 'admin' }
|
73
|
+
assert_equal :en, TypusUser.generate(options).locale
|
74
|
+
end
|
75
|
+
|
55
76
|
end
|
56
77
|
|
57
78
|
context "TypusUser" do
|
@@ -61,27 +82,27 @@ class TypusUserTest < ActiveSupport::TestCase
|
|
61
82
|
end
|
62
83
|
|
63
84
|
should "return email" do
|
64
|
-
assert_equal @typus_user.email, @typus_user.
|
85
|
+
assert_equal @typus_user.email, @typus_user.to_label
|
65
86
|
end
|
66
87
|
|
67
88
|
should "return first_name" do
|
68
89
|
@typus_user.first_name = "John"
|
69
|
-
assert_equal "John", @typus_user.
|
90
|
+
assert_equal "John", @typus_user.to_label
|
70
91
|
end
|
71
92
|
|
72
93
|
should "return last_name" do
|
73
94
|
@typus_user.last_name = "Locke"
|
74
|
-
assert_equal "Locke", @typus_user.
|
95
|
+
assert_equal "Locke", @typus_user.to_label
|
75
96
|
end
|
76
97
|
|
77
98
|
should "return name when first_name and last_name are set" do
|
78
99
|
@typus_user.first_name, @typus_user.last_name = "John", "Locke"
|
79
|
-
assert_equal "John Locke", @typus_user.
|
100
|
+
assert_equal "John Locke", @typus_user.to_label
|
80
101
|
end
|
81
102
|
|
82
103
|
should "return name when first_name and last_name are set to nil" do
|
83
104
|
@typus_user.first_name, @typus_user.last_name = nil
|
84
|
-
assert_equal @typus_user.email, @typus_user.
|
105
|
+
assert_equal @typus_user.email, @typus_user.to_label
|
85
106
|
end
|
86
107
|
|
87
108
|
should "verify salt never changes" do
|
@@ -191,4 +212,17 @@ class TypusUserTest < ActiveSupport::TestCase
|
|
191
212
|
|
192
213
|
end
|
193
214
|
|
215
|
+
should "owns a resource" do
|
216
|
+
typus_user = Factory(:typus_user)
|
217
|
+
resource = Factory(:post, :typus_user_id => typus_user.id)
|
218
|
+
assert typus_user.owns?(resource)
|
219
|
+
end
|
220
|
+
|
221
|
+
should "not own a resource" do
|
222
|
+
typus_user = Factory(:typus_user)
|
223
|
+
typus_user_2 = Factory(:typus_user)
|
224
|
+
resource = Factory(:post, :typus_user_id => typus_user_2.id)
|
225
|
+
assert !typus_user.owns?(resource)
|
226
|
+
end
|
227
|
+
|
194
228
|
end
|
data/test/factories.rb
CHANGED
@@ -0,0 +1,40 @@
|
|
1
|
+
class Admin::HitsController < Admin::ResourcesController
|
2
|
+
|
3
|
+
def index
|
4
|
+
@items = Hit.paginate(:per_page => 15, :page => params[:page])
|
5
|
+
add_resource_action("Edit", {:action => 'edit'}, {})
|
6
|
+
add_resource_action("Trash", {:action => "destroy"}, {:confirm => "#{Typus::I18n.t("Trash")}?", :method => 'delete'})
|
7
|
+
end
|
8
|
+
|
9
|
+
def new
|
10
|
+
@item = Hit.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def create
|
14
|
+
@item = Hit.new(params[:hit])
|
15
|
+
if @item.save
|
16
|
+
flash[:notice] = Typus::I18n::t("Hit was successfully created.")
|
17
|
+
redirect_to :action => 'edit', :id => @item.id
|
18
|
+
else
|
19
|
+
render :action => 'new'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def edit
|
24
|
+
@item = Hit.find(params[:id])
|
25
|
+
end
|
26
|
+
|
27
|
+
def update
|
28
|
+
@item = Hit.find(params[:id])
|
29
|
+
if @item.update_attributes(params[:entry])
|
30
|
+
flash[:notice] = Typus::I18n::t("Hit was successfully updated.")
|
31
|
+
redirect_to :action => 'edit', :id => @item.id
|
32
|
+
else
|
33
|
+
render :action => "edit"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def set_scope; end
|
38
|
+
private :set_scope
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "typus/orm/mongo/class_methods"
|
2
|
+
|
3
|
+
class Hit
|
4
|
+
|
5
|
+
extend Typus::Orm::Mongo::ClassMethods
|
6
|
+
|
7
|
+
if defined?(Mongoid)
|
8
|
+
include Mongoid::Document
|
9
|
+
|
10
|
+
field :name
|
11
|
+
field :description
|
12
|
+
|
13
|
+
validates_presence_of :name
|
14
|
+
validates_uniqueness_of :name
|
15
|
+
else
|
16
|
+
extend ActiveModel::Naming
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.typus_fields_for(*args)
|
20
|
+
[[:name, :string], [:description, :text]]
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.model_fields
|
24
|
+
[[:name, :string], [:description, :text]]
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
<%
|
2
|
+
page_title = @resource.model_name.human.pluralize
|
3
|
+
title(page_title)
|
4
|
+
%>
|
5
|
+
|
6
|
+
<% content_for :sidebar, build_sidebar %>
|
7
|
+
|
8
|
+
<h2>
|
9
|
+
<%= page_title %>
|
10
|
+
<small><%= list_actions %></small>
|
11
|
+
</h2>
|
12
|
+
|
13
|
+
<%= display_flash_message %>
|
14
|
+
|
15
|
+
<%= render 'index' %>
|
16
|
+
|
17
|
+
<ul class="predefined_filters">
|
18
|
+
<% predefined_filters.each do |filter, action, scope| %>
|
19
|
+
<li><%= link_to Typus::I18n.t(filter), params.dup.cleanup.merge(:action => action) %> (<%= @resource.send(scope).count %>)</li>
|
20
|
+
<% end %>
|
21
|
+
</ul>
|
22
|
+
|
23
|
+
<% if @items.any? -%>
|
24
|
+
<%= build_list(@resource, fields, @items) %>
|
25
|
+
<%= will_paginate(@items, Typus.pagination) %>
|
26
|
+
<% else %>
|
27
|
+
<p><%= Typus::I18n.t("No %{resources} found.", :resources => @resource.model_name.human.downcase.pluralize) %></p>
|
28
|
+
<% end %>
|
@@ -1,13 +1,6 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
|
3
3
|
# Set up gems listed in the Gemfile.
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
require 'bundler'
|
8
|
-
Bundler.setup
|
9
|
-
rescue Bundler::GemNotFound => e
|
10
|
-
STDERR.puts e.message
|
11
|
-
STDERR.puts "Try running `bundle install`."
|
12
|
-
exit!
|
13
|
-
end if File.exist?(gemfile)
|
4
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../../Gemfile', __FILE__)
|
5
|
+
|
6
|
+
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
|
@@ -9,7 +9,7 @@ set :repository, "git://github.com/fesplugas/typus.git"
|
|
9
9
|
set :deploy_via, :remote_cache
|
10
10
|
set :keep_releases, 2
|
11
11
|
|
12
|
-
# Override default
|
12
|
+
# Override default `:bundle_flags` because I don't provide a Gemfile.lock.
|
13
13
|
set :bundle_flags, "--quiet"
|
14
14
|
|
15
15
|
set :domain, "demo.typuscms.com"
|
@@ -0,0 +1,20 @@
|
|
1
|
+
defaults: &defaults
|
2
|
+
host: localhost
|
3
|
+
# slaves:
|
4
|
+
# - host: slave1.local
|
5
|
+
# port: 27018
|
6
|
+
# - host: slave2.local
|
7
|
+
# port: 27019
|
8
|
+
|
9
|
+
development:
|
10
|
+
<<: *defaults
|
11
|
+
database: rails_app_development
|
12
|
+
|
13
|
+
test:
|
14
|
+
<<: *defaults
|
15
|
+
database: rails_app_test
|
16
|
+
|
17
|
+
# set these environment variables on your prod server
|
18
|
+
production:
|
19
|
+
<<: *defaults
|
20
|
+
database: rails_app_production
|
@@ -2,6 +2,8 @@ Asset:
|
|
2
2
|
fields:
|
3
3
|
default: caption, dragonfly, dragonfly_required
|
4
4
|
special: caption, dragonfly, dragonfly_required, original_file_name
|
5
|
+
form: caption, dragonfly, dragonfly_required, original_file_name
|
6
|
+
new: dragonfly_required
|
5
7
|
application: CRUD Extended
|
6
8
|
|
7
9
|
Category:
|
@@ -2,6 +2,17 @@ ActiveRecord::Migration.verbose = false
|
|
2
2
|
|
3
3
|
ActiveRecord::Schema.define do
|
4
4
|
|
5
|
+
create_table :admin_users, :force => true do |t|
|
6
|
+
t.string :first_name
|
7
|
+
t.string :last_name
|
8
|
+
t.string :role, :null => false
|
9
|
+
t.string :email, :null => false
|
10
|
+
t.string :password_digest, :null => false
|
11
|
+
t.string :preferences
|
12
|
+
t.boolean :status, :default => false
|
13
|
+
t.timestamps
|
14
|
+
end
|
15
|
+
|
5
16
|
create_table :articles, :force => true do |t|
|
6
17
|
t.string :title
|
7
18
|
t.text :body
|
@@ -49,24 +49,6 @@ class StringTest < ActiveSupport::TestCase
|
|
49
49
|
|
50
50
|
end
|
51
51
|
|
52
|
-
context "action_mapper" do
|
53
|
-
|
54
|
-
should "return list for index" do
|
55
|
-
assert_equal :list, 'index'.action_mapper
|
56
|
-
end
|
57
|
-
|
58
|
-
should "return form for new, create, edit and update" do
|
59
|
-
%w(new create edit update).each do |action|
|
60
|
-
assert_equal :form, action.action_mapper
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
should "return the same action for everything else" do
|
65
|
-
assert_equal 'undefined', 'undefined'.action_mapper
|
66
|
-
end
|
67
|
-
|
68
|
-
end
|
69
|
-
|
70
52
|
context "acl_action_mapper" do
|
71
53
|
|
72
54
|
should "return create" do
|