spontaneous 0.2.0.beta1 → 0.2.0.beta2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +24 -0
- data/.locat +42 -0
- data/.travis/gemfiles/Gemfile.empty +7 -0
- data/.travis.yml +18 -0
- data/Gemfile +12 -8
- data/LICENSE +1 -1
- data/Rakefile +15 -157
- data/Readme.markdown +1 -1
- data/application/css/core.css.scss +22 -146
- data/application/css/definitions.css.scss +7 -3
- data/application/css/dialogue.css.scss +26 -1
- data/application/css/editing.css.scss +70 -28
- data/application/css/font.css.scss +1 -1
- data/application/css/popover.css.scss +2 -0
- data/application/css/top.css.scss +231 -0
- data/application/js/add_alias_dialogue.js +1 -1
- data/application/js/add_home_dialogue.js +1 -1
- data/application/js/ajax.js +61 -31
- data/application/js/box.js +4 -4
- data/application/js/conflicted_field_dialogue.js +1 -1
- data/application/js/content.js +5 -5
- data/application/js/dom.js +5 -0
- data/application/js/edit_panel.js +1 -0
- data/application/js/editing.js +1 -1
- data/application/js/extensions.js +8 -0
- data/application/js/field/boolean.js +31 -0
- data/application/js/field/file.js +32 -4
- data/application/js/field/image.js +24 -9
- data/application/js/field/markdown.js +87 -59
- data/application/js/field/select.js +1 -1
- data/application/js/field/webvideo.js +6 -1
- data/application/js/init.js +2 -2
- data/application/js/jquery-selection-position.js +130 -0
- data/application/js/location.js +4 -25
- data/application/js/meta_view/user_admin.js +2 -2
- data/application/js/metadata.js +2 -2
- data/application/js/page_browser.js +1 -1
- data/application/js/panel/root_menu.js +0 -1
- data/application/js/popover.js +27 -12
- data/application/js/popover_view.js +20 -4
- data/application/js/preview.js +31 -16
- data/application/js/progress.js +22 -21
- data/application/js/publish.js +18 -7
- data/application/js/sharded_upload.js +9 -6
- data/application/js/spontaneous.js +3 -1
- data/application/js/top_bar.js +264 -173
- data/application/js/upload.js +12 -5
- data/application/js/upload_manager.js +4 -3
- data/application/js/user.js +1 -2
- data/application/js/views/box_view.js +1 -1
- data/application/js/views/page_view.js +16 -5
- data/application/js/views/piece_view.js +5 -4
- data/application/static/font/fontawesome-webfont-1c66a4738b40ef0f6b1abca0ba9a796d.ttf +0 -0
- data/application/views/index.erb +6 -14
- data/application/views/login.erb +6 -25
- data/application/views/schema_modification_error.html.erb +3 -7
- data/db/migrations/20130114120000_create_revision_tables.rb +2 -2
- data/db/migrations/20130813111009_increase_path_length.rb +14 -0
- data/gem-public_cert.pem +20 -0
- data/lib/spontaneous/asset/app_compiler.rb +44 -0
- data/lib/spontaneous/asset/environment.rb +225 -0
- data/lib/spontaneous/asset.rb +2 -67
- data/lib/spontaneous/box.rb +0 -1
- data/lib/spontaneous/capistrano/deploy.rb +2 -2
- data/lib/spontaneous/capistrano/sync.rb +1 -1
- data/lib/spontaneous/cli/init.rb +36 -13
- data/lib/spontaneous/cli/server.rb +0 -1
- data/lib/spontaneous/cli/site.rb +2 -1
- data/lib/spontaneous/cli.rb +3 -1
- data/lib/spontaneous/collections/entry_set.rb +4 -12
- data/lib/spontaneous/collections/hash_with_fallback.rb +20 -0
- data/lib/spontaneous/collections/prototype_set.rb +6 -5
- data/lib/spontaneous/crypt.rb +2 -2
- data/lib/spontaneous/data_mapper/content_model/associations.rb +115 -63
- data/lib/spontaneous/data_mapper.rb +1 -1
- data/lib/spontaneous/errors.rb +6 -0
- data/lib/spontaneous/extensions/object_space.rb +6 -0
- data/lib/spontaneous/facet.rb +1 -0
- data/lib/spontaneous/field/base.rb +86 -13
- data/lib/spontaneous/field/boolean.rb +65 -0
- data/lib/spontaneous/field/file.rb +17 -6
- data/lib/spontaneous/field/html.rb +13 -0
- data/lib/spontaneous/field/image/size.rb +76 -0
- data/lib/spontaneous/field/image.rb +99 -414
- data/lib/spontaneous/field/tags.rb +36 -0
- data/lib/spontaneous/field/update.rb +1 -1
- data/lib/spontaneous/field/webvideo/fallback.rb +41 -0
- data/lib/spontaneous/field/webvideo/vimeo.rb +113 -0
- data/lib/spontaneous/field/webvideo/vine.rb +94 -0
- data/lib/spontaneous/field/webvideo/youtube.rb +133 -0
- data/lib/spontaneous/field/webvideo.rb +100 -250
- data/lib/spontaneous/field.rb +1 -1
- data/lib/spontaneous/generators/site/Gemfile.tt +5 -14
- data/lib/spontaneous/generators/site/assets/README.md +20 -0
- data/lib/spontaneous/generators/site/assets/css/site.scss +8 -0
- data/lib/spontaneous/generators/site/assets/js/site.js +6 -0
- data/lib/spontaneous/generators/site/config/deploy.rb.tt +9 -0
- data/lib/spontaneous/generators/site/config/user_levels.yml +14 -3
- data/lib/spontaneous/generators/site/public/README.md +12 -0
- data/lib/spontaneous/generators/site/templates/layouts/standard.html.cut.tt +2 -2
- data/lib/spontaneous/generators/site.rb +77 -35
- data/lib/spontaneous/layout.rb +6 -7
- data/lib/spontaneous/loader.rb +21 -13
- data/lib/spontaneous/media/file.rb +22 -9
- data/lib/spontaneous/media/image/attributes.rb +33 -0
- data/lib/spontaneous/media/image/format/gif.rb +4 -0
- data/lib/spontaneous/media/image/format/jpg.rb +17 -0
- data/lib/spontaneous/media/image/format/png.rb +4 -0
- data/lib/spontaneous/media/image/format/webp.rb +26 -0
- data/lib/spontaneous/media/image/format.rb +79 -0
- data/lib/spontaneous/media/image/optimizer.rb +69 -0
- data/lib/spontaneous/media/image/processor.rb +17 -0
- data/lib/spontaneous/media/image/renderable.rb +52 -0
- data/lib/spontaneous/media/image/skeptick.rb +70 -0
- data/lib/spontaneous/media/image.rb +50 -0
- data/lib/spontaneous/media/temp_file.rb +4 -0
- data/lib/spontaneous/media.rb +1 -0
- data/lib/spontaneous/model/core/aliases.rb +14 -8
- data/lib/spontaneous/model/core/boxes.rb +5 -2
- data/lib/spontaneous/model/core/entries.rb +4 -0
- data/lib/spontaneous/model/core/entry.rb +1 -0
- data/lib/spontaneous/model/core/fields.rb +5 -2
- data/lib/spontaneous/model/core/locks.rb +16 -0
- data/lib/spontaneous/model/core/media.rb +1 -15
- data/lib/spontaneous/model/core.rb +31 -1
- data/lib/spontaneous/model/page/controllers.rb +2 -2
- data/lib/spontaneous/model/page/formats.rb +1 -4
- data/lib/spontaneous/model/page/layouts.rb +6 -2
- data/lib/spontaneous/model/page/locks.rb +8 -2
- data/lib/spontaneous/model/page/page_tree.rb +2 -2
- data/lib/spontaneous/model/page/paths.rb +74 -9
- data/lib/spontaneous/model/page.rb +11 -3
- data/lib/spontaneous/model.rb +6 -6
- data/lib/spontaneous/output/context/render_cache.rb +23 -0
- data/lib/spontaneous/output/context.rb +56 -30
- data/lib/spontaneous/output/helpers/script_helper.rb +9 -53
- data/lib/spontaneous/output/helpers/stylesheet_helper.rb +8 -40
- data/lib/spontaneous/output/template/renderer.rb +17 -5
- data/lib/spontaneous/output.rb +0 -1
- data/lib/spontaneous/paths.rb +6 -2
- data/lib/spontaneous/permissions/access_key.rb +18 -0
- data/lib/spontaneous/permissions/user.rb +1 -1
- data/lib/spontaneous/permissions.rb +4 -1
- data/lib/spontaneous/plugins/application/state.rb +19 -12
- data/lib/spontaneous/prototypes/field_prototype.rb +14 -8
- data/lib/spontaneous/published_revision.rb +7 -0
- data/lib/spontaneous/publishing/immediate.rb +43 -34
- data/lib/spontaneous/publishing/revision.rb +9 -6
- data/lib/spontaneous/rack/asset_server.rb +20 -0
- data/lib/spontaneous/rack/back/alias.rb +46 -0
- data/lib/spontaneous/rack/back/application_assets.rb +28 -0
- data/lib/spontaneous/rack/back/base.rb +34 -0
- data/lib/spontaneous/rack/back/changes.rb +19 -0
- data/lib/spontaneous/rack/back/content.rb +54 -0
- data/lib/spontaneous/rack/back/events.rb +38 -0
- data/lib/spontaneous/rack/back/field.rb +37 -0
- data/lib/spontaneous/rack/back/file.rb +118 -0
- data/lib/spontaneous/rack/back/helpers.rb +71 -0
- data/lib/spontaneous/rack/back/index.rb +16 -0
- data/lib/spontaneous/rack/back/login.rb +47 -0
- data/lib/spontaneous/rack/back/map.rb +24 -0
- data/lib/spontaneous/rack/back/page.rb +46 -0
- data/lib/spontaneous/rack/back/preview.rb +43 -0
- data/lib/spontaneous/rack/back/schema.rb +30 -0
- data/lib/spontaneous/rack/back/site.rb +25 -0
- data/lib/spontaneous/rack/back/site_assets.rb +13 -0
- data/lib/spontaneous/rack/back/unsupported_browser.rb +7 -0
- data/lib/spontaneous/rack/{user_admin.rb → back/user_admin.rb} +2 -5
- data/lib/spontaneous/rack/back.rb +85 -764
- data/lib/spontaneous/rack/cacheable_file.rb +3 -3
- data/lib/spontaneous/rack/front.rb +16 -9
- data/lib/spontaneous/rack/middleware/authenticate.rb +65 -0
- data/lib/spontaneous/rack/middleware/csrf.rb +66 -0
- data/lib/spontaneous/rack/middleware/reloader.rb +52 -0
- data/lib/spontaneous/rack/middleware/scope.rb +60 -0
- data/lib/spontaneous/rack/middleware.rb +6 -0
- data/lib/spontaneous/rack/page_controller.rb +18 -5
- data/lib/spontaneous/rack/public.rb +17 -11
- data/lib/spontaneous/rack.rb +34 -24
- data/lib/spontaneous/revision.rb +29 -2
- data/lib/spontaneous/schema/uid.rb +4 -3
- data/lib/spontaneous/schema/uid_map.rb +5 -24
- data/lib/spontaneous/schema.rb +1 -0
- data/lib/spontaneous/search/database.rb +8 -0
- data/lib/spontaneous/search/field.rb +1 -1
- data/lib/spontaneous/search/index.rb +3 -5
- data/lib/spontaneous/server.rb +1 -1
- data/lib/spontaneous/simultaneous.rb +1 -1
- data/lib/spontaneous/site/features.rb +4 -5
- data/lib/spontaneous/site/helpers.rb +22 -5
- data/lib/spontaneous/site/instance.rb +2 -2
- data/lib/spontaneous/site/selectors.rb +22 -3
- data/lib/spontaneous/storage/cloud.rb +13 -9
- data/lib/spontaneous/storage/local.rb +11 -6
- data/lib/spontaneous/style.rb +40 -23
- data/lib/spontaneous/utils/database/mysql_dumper.rb +1 -1
- data/lib/spontaneous/utils/smush_it.rb +1 -1
- data/lib/spontaneous/version.rb +1 -1
- data/lib/spontaneous.rb +35 -33
- data/spontaneous.gemspec +53 -787
- data/test/experimental/test_crypt.rb +56 -56
- data/test/experimental/test_features.rb +16 -27
- data/test/fixtures/assets/public1/css/data.css.scss +3 -0
- data/test/fixtures/assets/public1/css/image1.css.scss +4 -0
- data/test/fixtures/assets/public1/css/import.css.scss +1 -0
- data/test/fixtures/assets/public1/css/urlhash.css.scss +3 -0
- data/test/fixtures/assets/public1/js/a.js +1 -1
- data/test/fixtures/assets/public1/js/all.js +4 -0
- data/test/fixtures/assets/public1/js/{m.coffee → m.js.coffee} +1 -0
- data/test/fixtures/assets/public1/x.js +1 -0
- data/test/fixtures/assets/public2/css/all.css +4 -0
- data/test/fixtures/assets/public2/css/missing.css.scss +3 -0
- data/test/fixtures/assets/public2/i/y.png +0 -0
- data/test/fixtures/assets/public2/js/b.js +1 -1
- data/test/fixtures/assets/public2/js/c.js +1 -1
- data/test/fixtures/images/size.extended.webp +0 -0
- data/test/fixtures/images/size.lossless.webp +0 -0
- data/test/fixtures/images/size.lossy.webp +0 -0
- data/test/fixtures/schema/before.yml +4 -4
- data/test/fixtures/schema/schema.yml +1 -1
- data/test/fixtures/templates/aliases/aaa.html.cut +0 -0
- data/test/fixtures/templates/extended/partial_with_renderer.html.cut +1 -0
- data/test/fixtures/templates/extended/with_includes_and_renderer.html.cut +2 -0
- data/test/functional/test_application.rb +108 -106
- data/test/functional/test_back.rb +924 -930
- data/test/functional/test_front.rb +285 -238
- data/test/functional/test_user_manager.rb +75 -100
- data/test/integration/test_installation.rb +1 -1
- data/test/support/matchers.rb +12 -0
- data/test/support/minitest.rb +121 -0
- data/test/support/rack.rb +45 -0
- data/test/support/test_start_finish.rb +103 -0
- data/test/test_helper.rb +21 -68
- data/test/test_integration_helper.rb +1 -3
- data/test/unit/test_alias.rb +432 -408
- data/test/unit/test_asset_bundler.rb +58 -58
- data/test/unit/test_assets.rb +485 -155
- data/test/unit/test_async.rb +16 -37
- data/test/unit/test_authentication.rb +425 -457
- data/test/unit/test_boxes.rb +191 -191
- data/test/unit/test_changesets.rb +244 -254
- data/test/unit/test_config.rb +128 -142
- data/test/unit/test_content.rb +313 -359
- data/test/unit/test_content_inheritance.rb +29 -30
- data/test/unit/test_datamapper.rb +1205 -1080
- data/test/unit/test_datamapper_content.rb +49 -51
- data/test/unit/test_extensions.rb +23 -23
- data/test/unit/test_fields.rb +1488 -1180
- data/test/unit/test_formats.rb +158 -158
- data/test/unit/test_generators.rb +98 -40
- data/test/unit/test_helpers.rb +73 -76
- data/test/unit/test_image_size.rb +53 -22
- data/test/unit/test_images.rb +164 -165
- data/test/unit/test_layouts.rb +133 -122
- data/test/unit/test_logger.rb +14 -17
- data/test/unit/test_media.rb +69 -84
- data/test/unit/test_modifications.rb +513 -525
- data/test/unit/test_page.rb +462 -361
- data/test/unit/test_permissions.rb +379 -364
- data/test/unit/test_piece.rb +67 -75
- data/test/unit/test_plugins.rb +82 -89
- data/test/unit/test_prototype_set.rb +215 -216
- data/test/unit/test_prototypes.rb +114 -124
- data/test/unit/test_publishing.rb +252 -289
- data/test/unit/test_render.rb +167 -115
- data/test/unit/test_revisions.rb +436 -444
- data/test/unit/test_schema.rb +339 -309
- data/test/unit/test_search.rb +577 -574
- data/test/unit/test_serialisation.rb +136 -147
- data/test/unit/test_site.rb +252 -227
- data/test/unit/test_skeptick.rb +130 -0
- data/test/unit/test_storage.rb +46 -40
- data/test/unit/test_structure.rb +57 -66
- data/test/unit/test_styles.rb +104 -104
- data/test/unit/test_templates.rb +72 -57
- data/test/unit/test_type_hierarchy.rb +15 -16
- data/test/unit/test_visibility.rb +239 -257
- metadata +455 -326
- data/application/js/vendor/JS.Class-2.1.5/CHANGELOG +0 -283
- data/application/js/vendor/JS.Class-2.1.5/MIT-LICENSE +0 -30
- data/application/js/vendor/JS.Class-2.1.5/README +0 -30
- data/application/js/vendor/JS.Class-2.1.5/min/command.js +0 -1
- data/application/js/vendor/JS.Class-2.1.5/min/comparable.js +0 -1
- data/application/js/vendor/JS.Class-2.1.5/min/constant_scope.js +0 -1
- data/application/js/vendor/JS.Class-2.1.5/min/decorator.js +0 -1
- data/application/js/vendor/JS.Class-2.1.5/min/enumerable.js +0 -1
- data/application/js/vendor/JS.Class-2.1.5/min/forwardable.js +0 -1
- data/application/js/vendor/JS.Class-2.1.5/min/hash.js +0 -1
- data/application/js/vendor/JS.Class-2.1.5/min/linked_list.js +0 -1
- data/application/js/vendor/JS.Class-2.1.5/min/loader.js +0 -1
- data/application/js/vendor/JS.Class-2.1.5/min/method_chain.js +0 -1
- data/application/js/vendor/JS.Class-2.1.5/min/observable.js +0 -1
- data/application/js/vendor/JS.Class-2.1.5/min/package.js +0 -1
- data/application/js/vendor/JS.Class-2.1.5/min/proxy.js +0 -1
- data/application/js/vendor/JS.Class-2.1.5/min/ruby.js +0 -1
- data/application/js/vendor/JS.Class-2.1.5/min/set.js +0 -1
- data/application/js/vendor/JS.Class-2.1.5/min/stack_trace.js +0 -1
- data/application/js/vendor/JS.Class-2.1.5/min/state.js +0 -1
- data/application/js/vendor/JS.Class-2.1.5/min/stdlib.js +0 -16
- data/application/js/vendor/jquery-1.6.2.min.js +0 -18
- data/application/js/vendor/jquery-ui-1.8.16.custom.min.js +0 -791
- data/application/js/vendor/jquery-ui-1.8.9.custom.min.js +0 -415
- data/application/static/font/fontawesome-webfont-5c5c21100a346972a82c34c5e96ffcfe.ttf +0 -0
- data/application/static/select-arrow-6e7dd3745b00e934b0d7a3250c46558b.png +0 -0
- data/bin/limit-upload +0 -5
- data/bin/unlimit-upload +0 -3
- data/lib/spontaneous/asset/file.rb +0 -25
- data/lib/spontaneous/asset/source.rb +0 -28
- data/lib/spontaneous/image_size.rb +0 -123
- data/lib/spontaneous/output/assets/compression.rb +0 -58
- data/lib/spontaneous/output/assets.rb +0 -32
- data/lib/spontaneous/rack/around_back.rb +0 -20
- data/lib/spontaneous/rack/around_front.rb +0 -27
- data/lib/spontaneous/rack/around_preview.rb +0 -22
- data/lib/spontaneous/rack/assets.rb +0 -126
- data/lib/spontaneous/rack/authentication.rb +0 -20
- data/lib/spontaneous/rack/cookie_authentication.rb +0 -38
- data/lib/spontaneous/rack/helpers.rb +0 -52
- data/lib/spontaneous/rack/http.rb +0 -18
- data/lib/spontaneous/rack/media.rb +0 -30
- data/lib/spontaneous/rack/query_authentication.rb +0 -35
- data/lib/spontaneous/rack/reloader.rb +0 -45
- data/lib/spontaneous/rack/user_helpers.rb +0 -28
- /data/{README → application/js/field/markdown/text_command.js} +0 -0
- /data/application/js/vendor/{JS.Class-2.1.5/min/core.js → js.class-2.1.5.min.js} +0 -0
- /data/test/fixtures/assets/public1/css/{a.scss → a.css.scss} +0 -0
- /data/{lib/spontaneous/generators/site/public/css/site.scss → test/fixtures/assets/public1/x.css} +0 -0
- /data/{lib/spontaneous/generators/site/public/js/.empty_directory → test/fixtures/assets/public1/x.png} +0 -0
- /data/test/fixtures/assets/public2/css/{b.scss → b.css.scss} +0 -0
- /data/test/fixtures/assets/public2/js/{n.coffee → n.js.coffee} +0 -0
- /data/test/fixtures/back/{public → assets}/css/sass_include.scss +0 -0
- /data/test/fixtures/back/{public → assets}/css/sass_template.scss +0 -0
- /data/test/fixtures/back/{public → assets}/js/coffeescript.coffee +0 -0
- /data/{lib/spontaneous/generators/site/public/js/site.js → test/fixtures/templates/aliases/aa_alias.html.cut} +0 -0
@@ -2,113 +2,116 @@
|
|
2
2
|
|
3
3
|
require File.expand_path('../../test_helper', __FILE__)
|
4
4
|
|
5
|
+
describe "Permissions" do
|
5
6
|
|
6
|
-
|
7
|
+
Permissions = Spontaneous::Permissions unless defined?(Permissions)
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
def setup
|
9
|
+
before do
|
11
10
|
@site = setup_site
|
12
11
|
::Content.delete
|
13
12
|
Permissions::UserLevel.reset!
|
14
|
-
|
13
|
+
@level_file = File.expand_path('../../fixtures/permissions/config/user_levels.yml', __FILE__)
|
14
|
+
Permissions::UserLevel.stubs(:level_file).returns(@level_file)
|
15
15
|
end
|
16
16
|
|
17
|
-
|
17
|
+
after do
|
18
18
|
teardown_site
|
19
|
+
begin
|
19
20
|
Permissions::AccessGroup.delete
|
20
21
|
Permissions::AccessKey.delete
|
21
22
|
Permissions::User.delete
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
s1 = Permissions.random_string(length)
|
28
|
-
s2 = Permissions.random_string(length)
|
29
|
-
s1.length.should == length
|
30
|
-
s2.length.should == length
|
31
|
-
s1.should_not == s2
|
23
|
+
rescue => e
|
24
|
+
# My uniqueness constraint test raises a db error which then causes
|
25
|
+
# a pg transaction error that I can safely ignore
|
26
|
+
unless e.class == Sequel::DatabaseError && e.message =~ /current transaction is aborted/
|
27
|
+
raise
|
32
28
|
end
|
33
29
|
end
|
34
30
|
end
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
31
|
+
|
32
|
+
it "can generate random strings of any length" do
|
33
|
+
(2..256).each do |length|
|
34
|
+
s1 = Permissions.random_string(length)
|
35
|
+
s2 = Permissions.random_string(length)
|
36
|
+
s1.length.must_equal length
|
37
|
+
s2.length.must_equal length
|
38
|
+
s1.wont_equal s2
|
39
39
|
end
|
40
|
+
end
|
40
41
|
|
41
|
-
|
42
|
-
|
43
|
-
Permissions::UserLevel
|
44
|
-
Permissions::UserLevel[
|
42
|
+
describe "UserLevel" do
|
43
|
+
it "always has a level of :none/0" do
|
44
|
+
Permissions::UserLevel.none.must_equal Permissions::UserLevel::None
|
45
|
+
Permissions::UserLevel[:none].must_equal Permissions::UserLevel.none
|
46
|
+
Permissions::UserLevel['none'].must_equal Permissions::UserLevel.none
|
45
47
|
end
|
46
48
|
|
47
|
-
|
49
|
+
it "are loaded from the config/user_levels.yml file" do
|
48
50
|
Permissions::UserLevel[:editor].must_be_instance_of(Permissions::UserLevel::Level)
|
49
51
|
Permissions::UserLevel['editor'].must_be_instance_of(Permissions::UserLevel::Level)
|
50
52
|
Permissions::UserLevel['admin'].must_be_instance_of(Permissions::UserLevel::Level)
|
51
53
|
Permissions::UserLevel['designer'].must_be_instance_of(Permissions::UserLevel::Level)
|
52
54
|
end
|
53
55
|
|
54
|
-
|
55
|
-
Permissions::UserLevel.all.map(&:to_sym).
|
56
|
+
it "provides a sorted list of all levels" do
|
57
|
+
Permissions::UserLevel.all.map(&:to_sym).must_equal [:none, :editor, :admin, :designer, :root]
|
56
58
|
end
|
57
59
|
|
58
|
-
|
59
|
-
Permissions::UserLevel.all(:editor).map(&:to_sym).
|
60
|
-
Permissions::UserLevel.all(:designer).map(&:to_sym).
|
60
|
+
it "provides a list of all levels <= provided level" do
|
61
|
+
Permissions::UserLevel.all(:editor).map(&:to_sym).must_equal [:none, :editor]
|
62
|
+
Permissions::UserLevel.all(:designer).map(&:to_sym).must_equal [:none, :editor, :admin, :designer]
|
61
63
|
end
|
62
64
|
|
63
|
-
|
64
|
-
Permissions::UserLevel.root.
|
65
|
+
it "has a root level" do
|
66
|
+
Permissions::UserLevel.root.must_equal Permissions::UserLevel::Root
|
65
67
|
end
|
66
68
|
|
67
|
-
|
68
|
-
Permissions::UserLevel.root.
|
69
|
-
Permissions::UserLevel.root.
|
70
|
-
Permissions::UserLevel.root.
|
71
|
-
Permissions::UserLevel.root.
|
72
|
-
Permissions::UserLevel[:root].
|
69
|
+
it "has a root level that is always greater than other levels except root" do
|
70
|
+
Permissions::UserLevel.root.must_be :>, Permissions::UserLevel['designer']
|
71
|
+
Permissions::UserLevel.root.must_be :>=, Permissions::UserLevel['designer']
|
72
|
+
Permissions::UserLevel.root.wont_be :>, Permissions::UserLevel::Root
|
73
|
+
Permissions::UserLevel.root.must_be :>=, Permissions::UserLevel::Root
|
74
|
+
Permissions::UserLevel[:root].must_equal Permissions::UserLevel::Root
|
73
75
|
end
|
74
76
|
|
75
|
-
|
76
|
-
Permissions::UserLevel[:admin].
|
77
|
-
Permissions::UserLevel[:editor].
|
77
|
+
it "works with > operator" do
|
78
|
+
Permissions::UserLevel[:admin].must_be :>, Permissions::UserLevel[:editor]
|
79
|
+
Permissions::UserLevel[:editor].must_be :>, Permissions::UserLevel[:none]
|
78
80
|
end
|
79
|
-
|
80
|
-
Permissions::UserLevel[:admin].
|
81
|
-
Permissions::UserLevel[:editor].
|
81
|
+
it "works with >= operator" do
|
82
|
+
Permissions::UserLevel[:admin].must_be :>=, Permissions::UserLevel[:admin]
|
83
|
+
Permissions::UserLevel[:editor].must_be :>=, Permissions::UserLevel[:editor]
|
82
84
|
end
|
83
85
|
|
84
|
-
|
85
|
-
Permissions::UserLevel.minimum.
|
86
|
+
it "returns a minimum level > none" do
|
87
|
+
Permissions::UserLevel.minimum.must_equal Permissions::UserLevel.editor
|
86
88
|
end
|
87
|
-
|
88
|
-
Permissions::UserLevel[:editor].to_s.
|
89
|
-
Permissions::UserLevel[:none].to_s.
|
90
|
-
Permissions::UserLevel[:root].to_s.
|
91
|
-
Permissions::UserLevel[:designer].to_s.
|
89
|
+
it "has a valid string representation" do
|
90
|
+
Permissions::UserLevel[:editor].to_s.must_equal 'editor'
|
91
|
+
Permissions::UserLevel[:none].to_s.must_equal 'none'
|
92
|
+
Permissions::UserLevel[:root].to_s.must_equal 'root'
|
93
|
+
Permissions::UserLevel[:designer].to_s.must_equal 'designer'
|
92
94
|
end
|
93
95
|
|
94
|
-
|
95
|
-
Permissions::UserLevel[:none].can_publish
|
96
|
-
Permissions::UserLevel[:editor].can_publish
|
97
|
-
Permissions::UserLevel[:admin].can_publish
|
98
|
-
Permissions::UserLevel[:designer].can_publish
|
99
|
-
Permissions::UserLevel[:root].can_publish
|
96
|
+
it "has configurable level above which you have access to the publishing mechanism" do
|
97
|
+
refute Permissions::UserLevel[:none].can_publish?
|
98
|
+
refute Permissions::UserLevel[:editor].can_publish?
|
99
|
+
refute Permissions::UserLevel[:admin].can_publish?
|
100
|
+
assert Permissions::UserLevel[:designer].can_publish?
|
101
|
+
assert Permissions::UserLevel[:root].can_publish?
|
100
102
|
end
|
101
|
-
|
102
|
-
|
103
|
-
Permissions::UserLevel[:
|
104
|
-
Permissions::UserLevel[:
|
105
|
-
Permissions::UserLevel[:
|
106
|
-
Permissions::UserLevel[:
|
103
|
+
|
104
|
+
it "has a developer flag" do
|
105
|
+
refute Permissions::UserLevel[:none].developer?
|
106
|
+
refute Permissions::UserLevel[:editor].developer?
|
107
|
+
refute Permissions::UserLevel[:admin].developer?
|
108
|
+
assert Permissions::UserLevel[:designer].developer?
|
109
|
+
assert Permissions::UserLevel[:root].developer?
|
107
110
|
end
|
108
111
|
end
|
109
112
|
|
110
|
-
|
111
|
-
|
113
|
+
describe "User" do
|
114
|
+
before do
|
112
115
|
@now = Time.now
|
113
116
|
Time.stubs(:now).returns(@now)
|
114
117
|
@valid = {
|
@@ -125,21 +128,18 @@ class PermissionsTest < MiniTest::Spec
|
|
125
128
|
}
|
126
129
|
end
|
127
130
|
|
128
|
-
|
129
|
-
end
|
130
|
-
|
131
|
-
should "be retrievable as a list" do
|
131
|
+
it "are retrievable as a list" do
|
132
132
|
user1 = Permissions::User.create(@valid.merge(:level => S::Permissions[:editor]))
|
133
133
|
user2 = Permissions::User.create(@valid2.merge(:level => S::Permissions[:admin]))
|
134
134
|
user1.logged_in!("196.168.1.11")
|
135
135
|
exported = Permissions::User.export(nil)
|
136
|
-
exported[:users].
|
136
|
+
exported[:users].must_equal [
|
137
137
|
{ :id => user1.id, :name => "A Person", :email => "person@example.org", :login => "person", :level => "editor",
|
138
138
|
:keys => [:last_access_at => @now.httpdate, :last_access_ip => "196.168.1.11"], :disabled => false },
|
139
139
|
{ :id => user2.id, :name => "Another Person", :email => "person2@example.org", :login => "person2", :level => "admin", :disabled => false,
|
140
140
|
:keys => [] }
|
141
141
|
]
|
142
|
-
exported[:levels].
|
142
|
+
exported[:levels].must_equal [
|
143
143
|
{ :level => "none", :can_publish => false, :is_admin => false },
|
144
144
|
{ :level => "editor", :can_publish => false, :is_admin => false },
|
145
145
|
{ :level => "admin", :can_publish => false, :is_admin => true },
|
@@ -148,226 +148,226 @@ class PermissionsTest < MiniTest::Spec
|
|
148
148
|
]
|
149
149
|
end
|
150
150
|
|
151
|
-
|
151
|
+
it "filters exported user list to remove users with a higher level" do
|
152
152
|
user1 = Permissions::User.create(@valid.merge(:level => S::Permissions[:editor]))
|
153
153
|
user2 = Permissions::User.create(@valid2.merge(:level => S::Permissions[:admin]))
|
154
154
|
user3 = Permissions::User.create(@valid.merge(:login => "person3", :email => "person3@example.com", :level => S::Permissions[:root]))
|
155
155
|
user1.logged_in!("196.168.1.11")
|
156
156
|
exported = Permissions::User.export(user2)
|
157
|
-
exported[:users].
|
157
|
+
exported[:users].must_equal [
|
158
158
|
{ :id => user1.id, :name => "A Person", :email => "person@example.org", :login => "person", :level => "editor", :disabled => false,
|
159
159
|
:keys => [:last_access_at => @now.httpdate, :last_access_ip => "196.168.1.11"] },
|
160
160
|
{ :id => user2.id, :name => "Another Person", :email => "person2@example.org", :login => "person2", :level => "admin", :disabled => false,
|
161
161
|
:keys => [] }
|
162
162
|
]
|
163
|
-
exported[:levels].
|
163
|
+
exported[:levels].must_equal [
|
164
164
|
{ :level => "none", :can_publish => false, :is_admin => false },
|
165
165
|
{ :level => "editor", :can_publish => false, :is_admin => false },
|
166
166
|
{ :level => "admin", :can_publish => false, :is_admin => true },
|
167
167
|
]
|
168
168
|
end
|
169
169
|
|
170
|
-
|
170
|
+
it "is creatable with valid params" do
|
171
171
|
user = Permissions::User.new(@valid)
|
172
172
|
user.save.must_be_instance_of(Permissions::User)
|
173
|
-
user.valid
|
173
|
+
assert user.valid?
|
174
174
|
end
|
175
175
|
|
176
|
-
|
176
|
+
it "validates names" do
|
177
177
|
user = Permissions::User.new(@valid.merge(:name => ""))
|
178
|
-
user.save.
|
179
|
-
user.valid
|
180
|
-
user.errors[:name].
|
178
|
+
user.save.must_be_nil
|
179
|
+
refute user.valid?
|
180
|
+
user.errors[:name].wont_be_empty
|
181
181
|
end
|
182
182
|
|
183
|
-
|
183
|
+
it "validates presence of email addresses" do
|
184
184
|
user = Permissions::User.new(@valid.merge(:email => ""))
|
185
185
|
user.save
|
186
|
-
user.valid
|
187
|
-
user.errors[:email].
|
186
|
+
refute user.valid?
|
187
|
+
user.errors[:email].wont_be_empty
|
188
188
|
end
|
189
189
|
|
190
|
-
|
190
|
+
it "validates format of email addresses" do
|
191
191
|
user = Permissions::User.new(@valid.merge(:email => "invalid.email.address"))
|
192
192
|
user.save
|
193
|
-
user.valid
|
194
|
-
user.errors[:email].
|
193
|
+
refute user.valid?
|
194
|
+
user.errors[:email].wont_be_empty
|
195
195
|
end
|
196
196
|
|
197
|
-
|
197
|
+
it "validates presence of logins" do
|
198
198
|
user = Permissions::User.new(@valid.merge(:login => ""))
|
199
199
|
user.save
|
200
|
-
user.valid
|
201
|
-
user.errors[:login].
|
200
|
+
refute user.valid?
|
201
|
+
user.errors[:login].wont_be_empty
|
202
202
|
end
|
203
203
|
|
204
|
-
|
204
|
+
it "validates length of logins" do
|
205
205
|
user = Permissions::User.new(@valid.merge(:login => "xx"))
|
206
206
|
user.save
|
207
|
-
user.valid
|
208
|
-
user.errors[:login].
|
207
|
+
refute user.valid?
|
208
|
+
user.errors[:login].wont_be_empty
|
209
209
|
end
|
210
210
|
|
211
|
-
|
211
|
+
it "rejects duplicate logins on creation" do
|
212
212
|
user1 = Permissions::User.create(@valid)
|
213
213
|
user2 = Permissions::User.new(@valid)
|
214
214
|
user2.save
|
215
|
-
user2.valid
|
216
|
-
user2.errors[:login].
|
215
|
+
refute user2.valid?
|
216
|
+
user2.errors[:login].wont_be_empty
|
217
217
|
end
|
218
218
|
|
219
|
-
|
219
|
+
it "rejects duplicate logins on update" do
|
220
220
|
user1 = Permissions::User.create(@valid)
|
221
221
|
user2 = Permissions::User.create(@valid.merge(:login => "other"))
|
222
222
|
user2.update_fields({:login => @valid[:login]}, [:login])
|
223
|
-
user2.valid
|
224
|
-
user2.errors[:login].
|
223
|
+
refute user2.valid?
|
224
|
+
user2.errors[:login].wont_be_empty
|
225
225
|
end
|
226
226
|
|
227
|
-
|
227
|
+
it "requires non-blank passwords" do
|
228
228
|
user = Permissions::User.new(@valid.merge(:password => ""))
|
229
229
|
user.save
|
230
|
-
user.valid
|
231
|
-
user.errors[:password].
|
230
|
+
refute user.valid?
|
231
|
+
user.errors[:password].wont_be_empty
|
232
232
|
end
|
233
233
|
|
234
|
-
|
234
|
+
it "requires passwords to be at least 8 characters" do
|
235
235
|
user = Permissions::User.new(@valid.merge(:password => "1234567"))
|
236
236
|
user.save
|
237
|
-
user.valid
|
238
|
-
user.errors[:password].
|
237
|
+
refute user.valid?
|
238
|
+
user.errors[:password].wont_be_empty
|
239
239
|
end
|
240
240
|
|
241
|
-
|
242
|
-
|
241
|
+
describe "Valid" do
|
242
|
+
before do
|
243
243
|
@user = Permissions::User.create(@valid)
|
244
244
|
@user.reload
|
245
245
|
end
|
246
246
|
|
247
|
-
|
248
|
-
@user.created_at.to_i.
|
247
|
+
it "have a created_at date" do
|
248
|
+
@user.created_at.to_i.must_equal @now.to_i
|
249
249
|
end
|
250
250
|
|
251
|
-
|
251
|
+
it "have an associated 'invisible' group" do
|
252
252
|
@user.group.must_be_instance_of(Permissions::AccessGroup)
|
253
|
-
@user.group.invisible
|
254
|
-
@user.group.level.
|
253
|
+
assert @user.group.invisible?
|
254
|
+
@user.group.level.must_equal Permissions::UserLevel::None
|
255
255
|
end
|
256
256
|
|
257
257
|
# the following actually works on the associated silent group
|
258
|
-
|
259
|
-
@user.level.
|
258
|
+
it "default to a user level of Permissions::UserLevel.minimum" do
|
259
|
+
@user.level.must_equal Permissions::UserLevel.none
|
260
260
|
end
|
261
261
|
|
262
|
-
|
262
|
+
it "have a settable user level" do
|
263
263
|
@user.update(:level => Permissions::UserLevel[:root])
|
264
|
-
@user.reload.level.
|
264
|
+
@user.reload.level.must_equal Permissions::UserLevel.root
|
265
265
|
end
|
266
266
|
|
267
|
-
|
268
|
-
@user.memberships.
|
267
|
+
it "have a list of groups it belongs to" do
|
268
|
+
@user.memberships.must_equal [@user.group]
|
269
269
|
end
|
270
270
|
|
271
|
-
|
271
|
+
it "be able to login with right login/password combination" do
|
272
272
|
key = Permissions::User.authenticate(@user.login, @user.password)
|
273
|
-
key.user.id.
|
273
|
+
key.user.id.must_equal @user.id
|
274
274
|
key = Permissions::User.authenticate(@user.login, "wrong password")
|
275
|
-
key.
|
275
|
+
key.must_be_nil
|
276
276
|
end
|
277
277
|
|
278
|
-
|
279
|
-
@user.last_login_at.
|
278
|
+
it "have a last login date" do
|
279
|
+
@user.last_login_at.must_be_nil
|
280
280
|
key = Permissions::User.authenticate(@user.login, @user.password)
|
281
|
-
@user.reload.last_login_at.to_i.
|
281
|
+
@user.reload.last_login_at.to_i.must_equal @now.to_i
|
282
282
|
end
|
283
283
|
|
284
|
-
|
285
|
-
@user.access_keys.
|
284
|
+
it "generate a new access key on successful login" do
|
285
|
+
@user.access_keys.must_be_empty
|
286
286
|
key = Permissions::User.authenticate(@user.login, @user.password)
|
287
|
-
@user.reload.access_keys.length.
|
288
|
-
@user.access_keys.first.created_at.to_i.
|
289
|
-
@user.access_keys.first.last_access_at.to_i.
|
287
|
+
@user.reload.access_keys.length.must_equal 1
|
288
|
+
@user.access_keys.first.created_at.to_i.must_equal @now.to_i
|
289
|
+
@user.access_keys.first.last_access_at.to_i.must_equal @now.to_i
|
290
290
|
end
|
291
291
|
|
292
|
-
|
292
|
+
it "have a list of access keys" do
|
293
293
|
@user.access_keys.must_be_instance_of(Array)
|
294
294
|
end
|
295
295
|
|
296
|
-
|
296
|
+
it "be blockable" do
|
297
297
|
@user.update(:disabled => true)
|
298
298
|
key = Permissions::User.authenticate(@user.login, @user.password)
|
299
|
-
key.
|
299
|
+
key.must_be_nil
|
300
300
|
end
|
301
301
|
|
302
|
-
|
302
|
+
it "be able to belong to more than one group" do
|
303
303
|
group1 = Permissions::AccessGroup.create(:name => "Group 1")
|
304
304
|
group2 = Permissions::AccessGroup.create(:name => "Group 2")
|
305
305
|
@user.add_group(group1)
|
306
306
|
@user.add_group(group2)
|
307
|
-
@user.groups.length.
|
308
|
-
group1.members.
|
309
|
-
group2.members.
|
307
|
+
@user.groups.length.must_equal 2
|
308
|
+
group1.members.must_equal [@user]
|
309
|
+
group2.members.must_equal [@user]
|
310
310
|
end
|
311
311
|
|
312
|
-
|
312
|
+
it "return the right user level for a piece of content" do
|
313
313
|
page = Page.create
|
314
314
|
@user.update(:level => Permissions::UserLevel.admin)
|
315
|
-
@user.access_selector.
|
316
|
-
@user.level_for(page).
|
315
|
+
@user.access_selector.must_equal "*"
|
316
|
+
@user.level_for(page).must_equal Permissions::UserLevel.admin
|
317
317
|
end
|
318
318
|
|
319
|
-
|
319
|
+
it "return the highest access level when multiple exist" do
|
320
320
|
page = Page.create
|
321
321
|
@user.update(:level => Permissions::UserLevel.none)
|
322
322
|
group1 = Permissions::AccessGroup.create(:name => "Group 1", :level => Permissions::UserLevel.admin)
|
323
323
|
group2 = Permissions::AccessGroup.create(:name => "Group 1", :level => Permissions::UserLevel.editor)
|
324
324
|
group1.add_member(@user)
|
325
325
|
group2.add_member(@user)
|
326
|
-
@user.level_for(page).
|
326
|
+
@user.level_for(page).must_equal Permissions::UserLevel.admin
|
327
327
|
end
|
328
328
|
|
329
|
-
|
329
|
+
it "have a test for developer status" do
|
330
330
|
@user.update(:level => Permissions::UserLevel.editor)
|
331
|
-
@user.developer
|
331
|
+
refute @user.developer?
|
332
332
|
@user.update(:level => Permissions::UserLevel.designer)
|
333
|
-
@user.developer
|
333
|
+
assert @user.developer?
|
334
334
|
end
|
335
335
|
|
336
|
-
|
336
|
+
it "be testable for ability to publish depending on their user level" do
|
337
337
|
@user.update(:level => Permissions::UserLevel.editor)
|
338
|
-
@user.can_publish
|
338
|
+
refute @user.can_publish?
|
339
339
|
@user.update(:level => Permissions::UserLevel.designer)
|
340
|
-
@user.can_publish
|
340
|
+
assert @user.can_publish?
|
341
341
|
end
|
342
342
|
|
343
|
-
|
343
|
+
it "be testable for admin privileges" do
|
344
344
|
@user.update(:level => Permissions::UserLevel.none)
|
345
|
-
@user.admin
|
345
|
+
refute @user.admin?
|
346
346
|
@user.update(:level => Permissions::UserLevel.editor)
|
347
|
-
@user.admin
|
347
|
+
refute @user.admin?
|
348
348
|
@user.update(:level => Permissions::UserLevel.designer)
|
349
|
-
@user.admin
|
349
|
+
refute @user.admin?
|
350
350
|
@user.update(:level => Permissions::UserLevel.admin)
|
351
|
-
@user.admin
|
351
|
+
assert @user.admin?
|
352
352
|
@user.update(:level => Permissions::UserLevel.root)
|
353
|
-
@user.admin
|
353
|
+
assert @user.admin?
|
354
354
|
end
|
355
355
|
|
356
|
-
|
357
|
-
@user.export.
|
356
|
+
it "serialise to JSON" do
|
357
|
+
@user.export.must_equal({
|
358
358
|
:name => "A Person",
|
359
359
|
:email => "person@example.org",
|
360
360
|
:login => "person",
|
361
361
|
:can_publish => false,
|
362
362
|
:admin => false,
|
363
363
|
:developer => false
|
364
|
-
}
|
364
|
+
})
|
365
365
|
end
|
366
366
|
end
|
367
367
|
end
|
368
368
|
|
369
|
-
|
370
|
-
|
369
|
+
describe "access keys" do
|
370
|
+
before do
|
371
371
|
@now = Time.now
|
372
372
|
Time.stubs(:now).returns(@now)
|
373
373
|
@valid = {
|
@@ -378,113 +378,128 @@ class PermissionsTest < MiniTest::Spec
|
|
378
378
|
}
|
379
379
|
end
|
380
380
|
|
381
|
-
|
381
|
+
after do
|
382
382
|
end
|
383
383
|
|
384
|
-
|
384
|
+
it "have a generated key_id" do
|
385
385
|
key1 = Permissions::AccessKey.create
|
386
|
-
key1.key_id.length.
|
386
|
+
key1.key_id.length.must_equal 44
|
387
387
|
key2 = Permissions::AccessKey.create
|
388
|
-
key2.key_id.length.
|
389
|
-
key1.key_id.
|
388
|
+
key2.key_id.length.must_equal 44
|
389
|
+
key1.key_id.wont_equal key2.key_id
|
390
390
|
end
|
391
391
|
|
392
|
-
|
392
|
+
it "allow authentication of a user" do
|
393
393
|
key1 = Permissions::AccessKey.create
|
394
394
|
key2 = Permissions::AccessKey.authenticate(key1.key_id)
|
395
|
-
key1.id.
|
395
|
+
key1.id.must_equal key2.id
|
396
396
|
end
|
397
397
|
|
398
|
-
|
398
|
+
it "update timestamps when authenticated" do
|
399
399
|
user = Permissions::User.create(@valid)
|
400
400
|
key1 = Permissions::AccessKey.create(:user_id => user.id)
|
401
401
|
Time.stubs(:now).returns(@now + 1000)
|
402
402
|
key2 = Permissions::AccessKey.create(:user_id => user.id)
|
403
403
|
key3 = Permissions::AccessKey.authenticate(key2.key_id)
|
404
|
-
key2.id.
|
405
|
-
key2.reload.last_access_at.to_i.
|
406
|
-
key2.user.last_access_at.to_i.
|
404
|
+
key2.id.must_equal key3.id
|
405
|
+
key2.reload.last_access_at.to_i.must_equal (@now+1000).to_i
|
406
|
+
key2.user.last_access_at.to_i.must_equal (@now+1000).to_i
|
407
407
|
end
|
408
408
|
|
409
|
-
|
409
|
+
it "be guaranteed unique" do
|
410
410
|
Permissions.stubs(:random_string).returns("xxxx")
|
411
411
|
key1 = Permissions::AccessKey.create()
|
412
412
|
lambda { Permissions::AccessKey.create() }.must_raise(Sequel::DatabaseError)
|
413
413
|
end
|
414
414
|
|
415
|
-
|
415
|
+
it "have a creation date" do
|
416
416
|
key1 = Permissions::AccessKey.create
|
417
|
-
key1.created_at.to_i.
|
417
|
+
key1.created_at.to_i.must_equal @now.to_i
|
418
418
|
end
|
419
419
|
|
420
|
-
|
421
|
-
|
422
|
-
should "retrieve their associated user" do
|
420
|
+
it "retrieve their associated user" do
|
423
421
|
user = Permissions::User.create(@valid)
|
424
422
|
key1 = Permissions::AccessKey.create(:user_id => user.id)
|
425
|
-
key1.reload.user.
|
423
|
+
key1.reload.user.must_equal user
|
426
424
|
end
|
427
425
|
|
428
|
-
|
426
|
+
it "be disabled when user blocked" do
|
429
427
|
user = Permissions::User.create(@valid)
|
430
428
|
key1 = Permissions::AccessKey.create(:user_id => user.id)
|
431
429
|
user.update(:disabled => true)
|
432
430
|
key3 = Permissions::AccessKey.authenticate(key1.key_id)
|
433
|
-
key3.
|
431
|
+
key3.must_be_nil
|
434
432
|
end
|
435
|
-
end
|
436
433
|
|
434
|
+
describe "csrf tokens" do
|
435
|
+
before do
|
436
|
+
user = Permissions::User.create(@valid)
|
437
|
+
@key1 = Permissions::AccessKey.create(:user_id => user.id)
|
438
|
+
@key2 = Permissions::AccessKey.create(:user_id => user.id)
|
439
|
+
end
|
437
440
|
|
441
|
+
it "be validatable" do
|
442
|
+
token = @key1.generate_csrf_token
|
443
|
+
assert @key1.csrf_token_valid?(token)
|
444
|
+
end
|
438
445
|
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
446
|
+
it "only be valid for the same token" do
|
447
|
+
token = @key1.generate_csrf_token
|
448
|
+
refute @key2.csrf_token_valid?(token)
|
449
|
+
end
|
450
|
+
|
451
|
+
it "recognises nil tokens as invalid" do
|
452
|
+
refute @key2.csrf_token_valid?(nil)
|
453
|
+
end
|
444
454
|
end
|
455
|
+
end
|
456
|
+
|
457
|
+
|
445
458
|
|
446
|
-
|
459
|
+
describe "Groups" do
|
460
|
+
before do
|
461
|
+
@valid_group = { :name => "Some People" }
|
447
462
|
end
|
448
463
|
|
449
|
-
|
464
|
+
it "always have a name" do
|
450
465
|
group = Permissions::AccessGroup.new(@valid_group.merge(:name => ""))
|
451
|
-
group.valid
|
452
|
-
group.errors[:name].
|
466
|
+
refute group.valid?
|
467
|
+
group.errors[:name].wont_be_empty
|
453
468
|
end
|
454
469
|
|
455
|
-
|
470
|
+
it "default to a user level of :none" do
|
456
471
|
group = Permissions::AccessGroup.create(@valid_group)
|
457
472
|
group.reload
|
458
|
-
group.level.
|
473
|
+
group.level.must_equal Permissions::UserLevel::None
|
459
474
|
end
|
460
475
|
|
461
476
|
# disabling a user and blocking a group are different
|
462
477
|
# if you disable a user you disable their login
|
463
478
|
# if you block a group they belong to you remove the permissions
|
464
479
|
# granted by that group but you aren't stopping them from logging in
|
465
|
-
|
480
|
+
it "be blockable" do
|
466
481
|
group = Permissions::AccessGroup.create(@valid_group.merge(:level => Permissions::UserLevel.admin))
|
467
|
-
group.level.
|
482
|
+
group.level.must_equal Permissions::UserLevel.admin
|
468
483
|
group.update(:disabled => true)
|
469
|
-
group.level.
|
484
|
+
group.level.must_equal Permissions::UserLevel.none
|
470
485
|
end
|
471
486
|
|
472
|
-
|
487
|
+
it "default to applying to the whole site" do
|
473
488
|
group = Permissions::AccessGroup.create(@valid_group)
|
474
|
-
group.access_selector.
|
489
|
+
group.access_selector.must_equal "*"
|
475
490
|
end
|
476
491
|
|
477
|
-
|
492
|
+
it "return the right user level for a piece of content" do
|
478
493
|
group = Permissions::AccessGroup.create(@valid_group)
|
479
494
|
page = Page.create
|
480
495
|
group.update(:level => Permissions::UserLevel.admin)
|
481
|
-
group.access_selector.
|
482
|
-
group.level_for(page).
|
496
|
+
group.access_selector.must_equal "*"
|
497
|
+
group.level_for(page).must_equal Permissions::UserLevel.admin
|
483
498
|
end
|
484
499
|
end
|
485
500
|
|
486
|
-
|
487
|
-
|
501
|
+
describe "Guards" do
|
502
|
+
before do
|
488
503
|
Permissions::User.delete
|
489
504
|
@visitor = Permissions::User.create(:email => "visitor@example.com", :login => "visitor", :name => "visitor", :password => "visitorpass")
|
490
505
|
@editor = Permissions::User.create(:email => "editor@example.com", :login => "editor", :name => "editor", :password => "editorpass")
|
@@ -557,144 +572,144 @@ class PermissionsTest < MiniTest::Spec
|
|
557
572
|
@i = C.new
|
558
573
|
end
|
559
574
|
|
560
|
-
|
575
|
+
after do
|
561
576
|
Object.send(:remove_const, :C) rescue nil
|
562
577
|
Object.send(:remove_const, :D) rescue nil
|
563
578
|
end
|
564
579
|
|
565
|
-
|
580
|
+
it "protect field reads" do
|
566
581
|
# without user (e.g. terminal/console access) everything is always
|
567
582
|
# possible
|
568
|
-
@i.field_readable?(nil, :editor_level)
|
569
|
-
@i.field_readable?(nil, :admin_level)
|
570
|
-
@i.field_readable?(nil, :root_level)
|
571
|
-
@i.field_readable?(nil, :mixed_level)
|
572
|
-
@i.field_readable?(nil, :default_level)
|
573
|
-
|
574
|
-
@i.field_readable?(@visitor, :editor_level)
|
575
|
-
@i.field_readable?(@visitor, :admin_level)
|
576
|
-
@i.field_readable?(@visitor, :root_level)
|
577
|
-
@i.field_readable?(@visitor, :mixed_level)
|
578
|
-
@i.field_readable?(@visitor, :default_level)
|
579
|
-
|
580
|
-
@i.field_readable?(@editor, :editor_level)
|
581
|
-
@i.field_readable?(@editor, :admin_level)
|
582
|
-
@i.field_readable?(@editor, :root_level)
|
583
|
-
@i.field_readable?(@editor, :mixed_level)
|
584
|
-
@i.field_readable?(@editor, :default_level)
|
585
|
-
|
586
|
-
@i.field_readable?(@admin, :editor_level)
|
587
|
-
@i.field_readable?(@admin, :admin_level)
|
588
|
-
@i.field_readable?(@admin, :root_level)
|
589
|
-
@i.field_readable?(@admin, :mixed_level)
|
590
|
-
@i.field_readable?(@admin, :default_level)
|
591
|
-
|
592
|
-
@i.field_readable?(@root, :editor_level)
|
593
|
-
@i.field_readable?(@root, :admin_level)
|
594
|
-
@i.field_readable?(@root, :root_level)
|
595
|
-
@i.field_readable?(@root, :mixed_level)
|
596
|
-
@i.field_readable?(@root, :default_level)
|
597
|
-
end
|
598
|
-
|
599
|
-
|
583
|
+
assert @i.field_readable?(nil, :editor_level)
|
584
|
+
assert @i.field_readable?(nil, :admin_level)
|
585
|
+
assert @i.field_readable?(nil, :root_level)
|
586
|
+
assert @i.field_readable?(nil, :mixed_level)
|
587
|
+
assert @i.field_readable?(nil, :default_level)
|
588
|
+
|
589
|
+
refute @i.field_readable?(@visitor, :editor_level)
|
590
|
+
refute @i.field_readable?(@visitor, :admin_level)
|
591
|
+
refute @i.field_readable?(@visitor, :root_level)
|
592
|
+
refute @i.field_readable?(@visitor, :mixed_level)
|
593
|
+
assert @i.field_readable?(@visitor, :default_level)
|
594
|
+
|
595
|
+
assert @i.field_readable?(@editor, :editor_level)
|
596
|
+
refute @i.field_readable?(@editor, :admin_level)
|
597
|
+
refute @i.field_readable?(@editor, :root_level)
|
598
|
+
assert @i.field_readable?(@editor, :mixed_level)
|
599
|
+
assert @i.field_readable?(@editor, :default_level)
|
600
|
+
|
601
|
+
assert @i.field_readable?(@admin, :editor_level)
|
602
|
+
assert @i.field_readable?(@admin, :admin_level)
|
603
|
+
refute @i.field_readable?(@admin, :root_level)
|
604
|
+
assert @i.field_readable?(@admin, :mixed_level)
|
605
|
+
assert @i.field_readable?(@admin, :default_level)
|
606
|
+
|
607
|
+
assert @i.field_readable?(@root, :editor_level)
|
608
|
+
assert @i.field_readable?(@root, :admin_level)
|
609
|
+
assert @i.field_readable?(@root, :root_level)
|
610
|
+
assert @i.field_readable?(@root, :mixed_level)
|
611
|
+
assert @i.field_readable?(@root, :default_level)
|
612
|
+
end
|
613
|
+
|
614
|
+
it "protect field writes" do
|
600
615
|
# without user (e.g. terminal/console access) everything is always
|
601
616
|
# possible
|
602
|
-
@i.field_writable?(nil, :editor_level)
|
603
|
-
@i.field_writable?(nil, :admin_level)
|
604
|
-
@i.field_writable?(nil, :root_level)
|
605
|
-
@i.field_writable?(nil, :mixed_level)
|
606
|
-
@i.field_writable?(nil, :default_level)
|
607
|
-
|
608
|
-
@i.field_writable?(@visitor, :editor_level)
|
609
|
-
@i.field_writable?(@visitor, :admin_level)
|
610
|
-
@i.field_writable?(@visitor, :root_level)
|
611
|
-
@i.field_writable?(@visitor, :mixed_level)
|
612
|
-
@i.field_writable?(@visitor, :default_level)
|
613
|
-
|
614
|
-
@i.field_writable?(@editor, :editor_level)
|
615
|
-
@i.field_writable?(@editor, :admin_level)
|
616
|
-
@i.field_writable?(@editor, :root_level)
|
617
|
-
@i.field_writable?(@editor, :mixed_level)
|
618
|
-
@i.field_writable?(@editor, :default_level)
|
619
|
-
|
620
|
-
@i.field_writable?(@admin, :editor_level)
|
621
|
-
@i.field_writable?(@admin, :admin_level)
|
622
|
-
@i.field_writable?(@admin, :root_level)
|
623
|
-
@i.field_writable?(@admin, :mixed_level)
|
624
|
-
@i.field_writable?(@admin, :default_level)
|
625
|
-
|
626
|
-
@i.field_writable?(@root, :editor_level)
|
627
|
-
@i.field_writable?(@root, :admin_level)
|
628
|
-
@i.field_writable?(@root, :root_level)
|
629
|
-
@i.field_writable?(@root, :mixed_level)
|
630
|
-
@i.field_writable?(@root, :default_level)
|
631
|
-
end
|
632
|
-
|
633
|
-
|
634
|
-
@i.box_readable?(nil, :editor_level)
|
635
|
-
@i.box_readable?(nil, :admin_level)
|
636
|
-
@i.box_readable?(nil, :root_level)
|
637
|
-
@i.box_readable?(nil, :mixed_level)
|
638
|
-
@i.box_readable?(nil, :default_level)
|
639
|
-
|
640
|
-
@i.box_readable?(@visitor, :editor_level)
|
641
|
-
@i.box_readable?(@visitor, :admin_level)
|
642
|
-
@i.box_readable?(@visitor, :root_level)
|
643
|
-
@i.box_readable?(@visitor, :mixed_level)
|
644
|
-
@i.box_readable?(@visitor, :default_level)
|
645
|
-
|
646
|
-
@i.box_readable?(@editor, :editor_level)
|
647
|
-
@i.box_readable?(@editor, :admin_level)
|
648
|
-
@i.box_readable?(@editor, :root_level)
|
649
|
-
@i.box_readable?(@editor, :mixed_level)
|
650
|
-
@i.box_readable?(@editor, :default_level)
|
651
|
-
|
652
|
-
@i.box_readable?(@admin, :editor_level)
|
653
|
-
@i.box_readable?(@admin, :admin_level)
|
654
|
-
@i.box_readable?(@admin, :root_level)
|
655
|
-
@i.box_readable?(@admin, :mixed_level)
|
656
|
-
@i.box_readable?(@admin, :default_level)
|
657
|
-
|
658
|
-
@i.box_readable?(@root, :editor_level)
|
659
|
-
@i.box_readable?(@root, :admin_level)
|
660
|
-
@i.box_readable?(@root, :root_level)
|
661
|
-
@i.box_readable?(@root, :mixed_level)
|
662
|
-
@i.box_readable?(@root, :default_level)
|
663
|
-
end
|
664
|
-
|
665
|
-
@i.box_writable?(nil, :editor_level)
|
666
|
-
@i.box_writable?(nil, :admin_level)
|
667
|
-
@i.box_writable?(nil, :root_level)
|
668
|
-
@i.box_writable?(nil, :mixed_level)
|
669
|
-
@i.box_writable?(nil, :default_level)
|
670
|
-
|
671
|
-
@i.box_writable?(@visitor, :editor_level)
|
672
|
-
@i.box_writable?(@visitor, :admin_level)
|
673
|
-
@i.box_writable?(@visitor, :root_level)
|
674
|
-
@i.box_writable?(@visitor, :mixed_level)
|
675
|
-
@i.box_writable?(@visitor, :default_level)
|
676
|
-
|
677
|
-
@i.box_writable?(@editor, :editor_level)
|
678
|
-
@i.box_writable?(@editor, :admin_level)
|
679
|
-
@i.box_writable?(@editor, :root_level)
|
680
|
-
@i.box_writable?(@editor, :mixed_level)
|
681
|
-
@i.box_writable?(@editor, :default_level)
|
682
|
-
|
683
|
-
@i.box_writable?(@admin, :editor_level)
|
684
|
-
@i.box_writable?(@admin, :admin_level)
|
685
|
-
@i.box_writable?(@admin, :root_level)
|
686
|
-
@i.box_writable?(@admin, :mixed_level)
|
687
|
-
@i.box_writable?(@admin, :default_level)
|
688
|
-
|
689
|
-
|
690
|
-
@i.box_writable?(@root, :editor_level)
|
691
|
-
@i.box_writable?(@root, :admin_level)
|
692
|
-
@i.box_writable?(@root, :root_level)
|
693
|
-
@i.box_writable?(@root, :mixed_level)
|
694
|
-
@i.box_writable?(@root, :default_level)
|
695
|
-
end
|
696
|
-
|
697
|
-
|
617
|
+
assert @i.field_writable?(nil, :editor_level)
|
618
|
+
assert @i.field_writable?(nil, :admin_level)
|
619
|
+
assert @i.field_writable?(nil, :root_level)
|
620
|
+
assert @i.field_writable?(nil, :mixed_level)
|
621
|
+
assert @i.field_writable?(nil, :default_level)
|
622
|
+
|
623
|
+
refute @i.field_writable?(@visitor, :editor_level)
|
624
|
+
refute @i.field_writable?(@visitor, :admin_level)
|
625
|
+
refute @i.field_writable?(@visitor, :root_level)
|
626
|
+
refute @i.field_writable?(@visitor, :mixed_level)
|
627
|
+
refute @i.field_writable?(@visitor, :default_level)
|
628
|
+
|
629
|
+
assert @i.field_writable?(@editor, :editor_level)
|
630
|
+
refute @i.field_writable?(@editor, :admin_level)
|
631
|
+
refute @i.field_writable?(@editor, :root_level)
|
632
|
+
refute @i.field_writable?(@editor, :mixed_level)
|
633
|
+
assert @i.field_writable?(@editor, :default_level)
|
634
|
+
|
635
|
+
assert @i.field_writable?(@admin, :editor_level)
|
636
|
+
assert @i.field_writable?(@admin, :admin_level)
|
637
|
+
refute @i.field_writable?(@admin, :root_level)
|
638
|
+
refute @i.field_writable?(@admin, :mixed_level)
|
639
|
+
assert @i.field_writable?(@admin, :default_level)
|
640
|
+
|
641
|
+
assert @i.field_writable?(@root, :editor_level)
|
642
|
+
assert @i.field_writable?(@root, :admin_level)
|
643
|
+
assert @i.field_writable?(@root, :root_level)
|
644
|
+
assert @i.field_writable?(@root, :mixed_level)
|
645
|
+
assert @i.field_writable?(@root, :default_level)
|
646
|
+
end
|
647
|
+
|
648
|
+
it "protect box reads" do
|
649
|
+
assert @i.box_readable?(nil, :editor_level)
|
650
|
+
assert @i.box_readable?(nil, :admin_level)
|
651
|
+
assert @i.box_readable?(nil, :root_level)
|
652
|
+
assert @i.box_readable?(nil, :mixed_level)
|
653
|
+
assert @i.box_readable?(nil, :default_level)
|
654
|
+
|
655
|
+
refute @i.box_readable?(@visitor, :editor_level)
|
656
|
+
refute @i.box_readable?(@visitor, :admin_level)
|
657
|
+
refute @i.box_readable?(@visitor, :root_level)
|
658
|
+
refute @i.box_readable?(@visitor, :mixed_level)
|
659
|
+
assert @i.box_readable?(@visitor, :default_level)
|
660
|
+
|
661
|
+
assert @i.box_readable?(@editor, :editor_level)
|
662
|
+
refute @i.box_readable?(@editor, :admin_level)
|
663
|
+
refute @i.box_readable?(@editor, :root_level)
|
664
|
+
assert @i.box_readable?(@editor, :mixed_level)
|
665
|
+
assert @i.box_readable?(@editor, :default_level)
|
666
|
+
|
667
|
+
assert @i.box_readable?(@admin, :editor_level)
|
668
|
+
assert @i.box_readable?(@admin, :admin_level)
|
669
|
+
refute @i.box_readable?(@admin, :root_level)
|
670
|
+
assert @i.box_readable?(@admin, :mixed_level)
|
671
|
+
assert @i.box_readable?(@admin, :default_level)
|
672
|
+
|
673
|
+
assert @i.box_readable?(@root, :editor_level)
|
674
|
+
assert @i.box_readable?(@root, :admin_level)
|
675
|
+
assert @i.box_readable?(@root, :root_level)
|
676
|
+
assert @i.box_readable?(@root, :mixed_level)
|
677
|
+
assert @i.box_readable?(@root, :default_level)
|
678
|
+
end
|
679
|
+
it "protect box writes" do
|
680
|
+
assert @i.box_writable?(nil, :editor_level)
|
681
|
+
assert @i.box_writable?(nil, :admin_level)
|
682
|
+
assert @i.box_writable?(nil, :root_level)
|
683
|
+
assert @i.box_writable?(nil, :mixed_level)
|
684
|
+
assert @i.box_writable?(nil, :default_level)
|
685
|
+
|
686
|
+
refute @i.box_writable?(@visitor, :editor_level)
|
687
|
+
refute @i.box_writable?(@visitor, :admin_level)
|
688
|
+
refute @i.box_writable?(@visitor, :root_level)
|
689
|
+
refute @i.box_writable?(@visitor, :mixed_level)
|
690
|
+
refute @i.box_writable?(@visitor, :default_level)
|
691
|
+
|
692
|
+
assert @i.box_writable?(@editor, :editor_level)
|
693
|
+
refute @i.box_writable?(@editor, :admin_level)
|
694
|
+
refute @i.box_writable?(@editor, :root_level)
|
695
|
+
refute @i.box_writable?(@editor, :mixed_level)
|
696
|
+
assert @i.box_writable?(@editor, :default_level)
|
697
|
+
|
698
|
+
assert @i.box_writable?(@admin, :editor_level)
|
699
|
+
assert @i.box_writable?(@admin, :admin_level)
|
700
|
+
refute @i.box_writable?(@admin, :root_level)
|
701
|
+
refute @i.box_writable?(@admin, :mixed_level)
|
702
|
+
assert @i.box_writable?(@admin, :default_level)
|
703
|
+
|
704
|
+
|
705
|
+
assert @i.box_writable?(@root, :editor_level)
|
706
|
+
assert @i.box_writable?(@root, :admin_level)
|
707
|
+
assert @i.box_writable?(@root, :root_level)
|
708
|
+
assert @i.box_writable?(@root, :mixed_level)
|
709
|
+
assert @i.box_writable?(@root, :default_level)
|
710
|
+
end
|
711
|
+
|
712
|
+
it "serialise only things in class viewable by the current user" do
|
698
713
|
expected = [
|
699
714
|
["editor_level", true],
|
700
715
|
["admin_level", true],
|
@@ -702,9 +717,9 @@ class PermissionsTest < MiniTest::Spec
|
|
702
717
|
["mixed_level", true],
|
703
718
|
["default_level", true]
|
704
719
|
]
|
705
|
-
C.export[:fields].map { |f| [f[:name], f[:writable]] }.
|
706
|
-
C.export[:boxes].map { |f| [f[:name], f[:writable]] }.
|
707
|
-
C.export[:boxes].map { |b| [b[:name], b[:fields].map {|f| [f[:name], f[:writable]]}] }.
|
720
|
+
C.export[:fields].map { |f| [f[:name], f[:writable]] }.must_equal expected
|
721
|
+
C.export[:boxes].map { |f| [f[:name], f[:writable]] }.must_equal expected
|
722
|
+
C.export[:boxes].map { |b| [b[:name], b[:fields].map {|f| [f[:name], f[:writable]]}] }.must_equal [
|
708
723
|
["editor_level", expected],
|
709
724
|
["admin_level", expected],
|
710
725
|
["root_level", expected],
|
@@ -713,9 +728,9 @@ class PermissionsTest < MiniTest::Spec
|
|
713
728
|
]
|
714
729
|
|
715
730
|
# Permissions.with_user(@root) do
|
716
|
-
C.export(@root)[:fields].map { |f| [f[:name], f[:writable]] }.
|
717
|
-
C.export(@root)[:boxes].map { |f| [f[:name], f[:writable]] }.
|
718
|
-
C.export(@root)[:boxes].map { |b| [b[:name], b[:fields].map {|f| [f[:name], f[:writable]]}] }.
|
731
|
+
C.export(@root)[:fields].map { |f| [f[:name], f[:writable]] }.must_equal expected
|
732
|
+
C.export(@root)[:boxes].map { |f| [f[:name], f[:writable]] }.must_equal expected
|
733
|
+
C.export(@root)[:boxes].map { |b| [b[:name], b[:fields].map {|f| [f[:name], f[:writable]]}] }.must_equal [
|
719
734
|
["editor_level", expected],
|
720
735
|
["admin_level", expected],
|
721
736
|
["root_level", expected],
|
@@ -728,9 +743,9 @@ class PermissionsTest < MiniTest::Spec
|
|
728
743
|
expected = [
|
729
744
|
["default_level", false]
|
730
745
|
]
|
731
|
-
C.export(@visitor)[:fields].map { |f| [f[:name], f[:writable]] }.
|
732
|
-
C.export(@visitor)[:boxes].map { |f| [f[:name], f[:writable]] }.
|
733
|
-
C.export(@visitor)[:boxes].map { |b| [b[:name], b[:fields].map {|f| [f[:name], f[:writable]]}] }.
|
746
|
+
C.export(@visitor)[:fields].map { |f| [f[:name], f[:writable]] }.must_equal expected
|
747
|
+
C.export(@visitor)[:boxes].map { |f| [f[:name], f[:writable]] }.must_equal expected
|
748
|
+
C.export(@visitor)[:boxes].map { |b| [b[:name], b[:fields].map {|f| [f[:name], f[:writable]]}] }.must_equal [
|
734
749
|
["default_level", expected ]
|
735
750
|
]
|
736
751
|
# end
|
@@ -741,9 +756,9 @@ class PermissionsTest < MiniTest::Spec
|
|
741
756
|
["mixed_level", false],
|
742
757
|
["default_level", true]
|
743
758
|
]
|
744
|
-
C.export(@editor)[:fields].map { |f| [f[:name], f[:writable]] }.
|
745
|
-
C.export(@editor)[:boxes].map { |f| [f[:name], f[:writable]] }.
|
746
|
-
C.export(@editor)[:boxes].map { |b| [b[:name], b[:fields].map {|f| [f[:name], f[:writable]]}] }.
|
759
|
+
C.export(@editor)[:fields].map { |f| [f[:name], f[:writable]] }.must_equal expected
|
760
|
+
C.export(@editor)[:boxes].map { |f| [f[:name], f[:writable]] }.must_equal expected
|
761
|
+
C.export(@editor)[:boxes].map { |b| [b[:name], b[:fields].map {|f| [f[:name], f[:writable]]}] }.must_equal [
|
747
762
|
["editor_level", expected],
|
748
763
|
["mixed_level", expected],
|
749
764
|
["default_level", expected]
|
@@ -757,9 +772,9 @@ class PermissionsTest < MiniTest::Spec
|
|
757
772
|
["mixed_level", false],
|
758
773
|
["default_level", true]
|
759
774
|
]
|
760
|
-
C.export(@admin)[:fields].map { |f| [f[:name], f[:writable]] }.
|
761
|
-
C.export(@admin)[:boxes].map { |f| [f[:name], f[:writable]] }.
|
762
|
-
C.export(@admin)[:boxes].map { |b| [b[:name], b[:fields].map {|f| [f[:name], f[:writable]]}] }.
|
775
|
+
C.export(@admin)[:fields].map { |f| [f[:name], f[:writable]] }.must_equal expected
|
776
|
+
C.export(@admin)[:boxes].map { |f| [f[:name], f[:writable]] }.must_equal expected
|
777
|
+
C.export(@admin)[:boxes].map { |b| [b[:name], b[:fields].map {|f| [f[:name], f[:writable]]}] }.must_equal [
|
763
778
|
["editor_level", expected],
|
764
779
|
["admin_level", expected],
|
765
780
|
["mixed_level", expected],
|
@@ -768,7 +783,7 @@ class PermissionsTest < MiniTest::Spec
|
|
768
783
|
# end
|
769
784
|
end
|
770
785
|
|
771
|
-
|
786
|
+
it "only list allowed types addable by the user" do
|
772
787
|
expected = [
|
773
788
|
["editor_level", ["D", "C"]],
|
774
789
|
["admin_level", ["C"]],
|
@@ -776,16 +791,16 @@ class PermissionsTest < MiniTest::Spec
|
|
776
791
|
["mixed_level", ["C"]],
|
777
792
|
["default_level", ["C"]]
|
778
793
|
]
|
779
|
-
C.export[:boxes].map { |b| [b[:name], b[:allowed_types]] }.
|
794
|
+
C.export[:boxes].map { |b| [b[:name], b[:allowed_types]] }.must_equal expected
|
780
795
|
|
781
796
|
# Permissions.with_user(@root) do
|
782
|
-
C.export(@root)[:boxes].map { |b| [b[:name], b[:allowed_types]] }.
|
797
|
+
C.export(@root)[:boxes].map { |b| [b[:name], b[:allowed_types]] }.must_equal expected
|
783
798
|
# end
|
784
799
|
# Permissions.with_user(@visitor) do
|
785
800
|
expected = [
|
786
801
|
["default_level", []]
|
787
802
|
]
|
788
|
-
C.export(@visitor)[:boxes].map { |b| [b[:name], b[:allowed_types]] }.
|
803
|
+
C.export(@visitor)[:boxes].map { |b| [b[:name], b[:allowed_types]] }.must_equal expected
|
789
804
|
# end
|
790
805
|
# Permissions.with_user(@editor) do
|
791
806
|
expected = [
|
@@ -793,7 +808,7 @@ class PermissionsTest < MiniTest::Spec
|
|
793
808
|
["mixed_level", []],
|
794
809
|
["default_level", ["C"]]
|
795
810
|
]
|
796
|
-
C.export(@editor)[:boxes].map { |b| [b[:name], b[:allowed_types]] }.
|
811
|
+
C.export(@editor)[:boxes].map { |b| [b[:name], b[:allowed_types]] }.must_equal expected
|
797
812
|
# end
|
798
813
|
# Permissions.with_user(@admin) do
|
799
814
|
expected = [
|
@@ -802,11 +817,11 @@ class PermissionsTest < MiniTest::Spec
|
|
802
817
|
["mixed_level", []],
|
803
818
|
["default_level", ["C"]]
|
804
819
|
]
|
805
|
-
C.export(@admin)[:boxes].map { |b| [b[:name], b[:allowed_types]] }.
|
820
|
+
C.export(@admin)[:boxes].map { |b| [b[:name], b[:allowed_types]] }.must_equal expected
|
806
821
|
# end
|
807
822
|
end
|
808
823
|
|
809
|
-
|
824
|
+
it "serialise only things in instance viewable by the current user" do
|
810
825
|
expected = [
|
811
826
|
"editor_level",
|
812
827
|
"admin_level",
|
@@ -814,8 +829,8 @@ class PermissionsTest < MiniTest::Spec
|
|
814
829
|
"mixed_level",
|
815
830
|
"default_level"
|
816
831
|
]
|
817
|
-
@i.export[:boxes].map { |f| f[:name] }.
|
818
|
-
@i.export[:boxes].map { |b| [b[:name], b[:fields].map {|f| f[:name]}] }.
|
832
|
+
@i.export[:boxes].map { |f| f[:name] }.must_equal expected
|
833
|
+
@i.export[:boxes].map { |b| [b[:name], b[:fields].map {|f| f[:name]}] }.must_equal [
|
819
834
|
["editor_level", expected],
|
820
835
|
["admin_level", expected],
|
821
836
|
["root_level", expected],
|
@@ -823,8 +838,8 @@ class PermissionsTest < MiniTest::Spec
|
|
823
838
|
["default_level", expected]
|
824
839
|
]
|
825
840
|
# Permissions.with_user(@root) do
|
826
|
-
@i.export(@root)[:boxes].map { |f| f[:name] }.
|
827
|
-
@i.export(@root)[:boxes].map { |b| [b[:name], b[:fields].map {|f| f[:name]}] }.
|
841
|
+
@i.export(@root)[:boxes].map { |f| f[:name] }.must_equal expected
|
842
|
+
@i.export(@root)[:boxes].map { |b| [b[:name], b[:fields].map {|f| f[:name]}] }.must_equal [
|
828
843
|
["editor_level", expected],
|
829
844
|
["admin_level", expected],
|
830
845
|
["root_level", expected],
|
@@ -834,10 +849,10 @@ class PermissionsTest < MiniTest::Spec
|
|
834
849
|
# end
|
835
850
|
|
836
851
|
# Permissions.with_user(@visitor) do
|
837
|
-
@i.export(@visitor)[:boxes].map { |f| f[:name] }.
|
852
|
+
@i.export(@visitor)[:boxes].map { |f| f[:name] }.must_equal [
|
838
853
|
"default_level"
|
839
854
|
]
|
840
|
-
@i.export(@visitor)[:boxes].map { |b| [b[:name], b[:fields].map {|f| f[:name]}] }.
|
855
|
+
@i.export(@visitor)[:boxes].map { |b| [b[:name], b[:fields].map {|f| f[:name]}] }.must_equal [
|
841
856
|
["default_level", ["default_level"]]
|
842
857
|
]
|
843
858
|
# end
|
@@ -848,8 +863,8 @@ class PermissionsTest < MiniTest::Spec
|
|
848
863
|
"mixed_level",
|
849
864
|
"default_level"
|
850
865
|
]
|
851
|
-
@i.export(@editor)[:boxes].map { |f| f[:name] }.
|
852
|
-
@i.export(@editor)[:boxes].map { |b| [b[:name], b[:fields].map {|f| f[:name]}] }.
|
866
|
+
@i.export(@editor)[:boxes].map { |f| f[:name] }.must_equal expected
|
867
|
+
@i.export(@editor)[:boxes].map { |b| [b[:name], b[:fields].map {|f| f[:name]}] }.must_equal [
|
853
868
|
["editor_level", expected],
|
854
869
|
["mixed_level", expected],
|
855
870
|
["default_level", expected]
|
@@ -863,8 +878,8 @@ class PermissionsTest < MiniTest::Spec
|
|
863
878
|
"mixed_level",
|
864
879
|
"default_level"
|
865
880
|
]
|
866
|
-
@i.export(@admin)[:boxes].map { |f| f[:name] }.
|
867
|
-
@i.export(@admin)[:boxes].map { |b| [b[:name], b[:fields].map {|f| f[:name]}] }.
|
881
|
+
@i.export(@admin)[:boxes].map { |f| f[:name] }.must_equal expected
|
882
|
+
@i.export(@admin)[:boxes].map { |b| [b[:name], b[:fields].map {|f| f[:name]}] }.must_equal [
|
868
883
|
["editor_level", expected],
|
869
884
|
["admin_level", expected],
|
870
885
|
["mixed_level", expected],
|
@@ -874,11 +889,11 @@ class PermissionsTest < MiniTest::Spec
|
|
874
889
|
|
875
890
|
end
|
876
891
|
|
877
|
-
|
892
|
+
it "determine what fields are visible in the exoported schema" do
|
878
893
|
schema = Site.schema.export(@editor)
|
879
894
|
c_schema = schema["C"]
|
880
|
-
c_schema[:fields].map { |f| f[:name] }.
|
881
|
-
c_schema[:boxes].map { |b| b[:name] }.
|
895
|
+
c_schema[:fields].map { |f| f[:name] }.must_equal %w(editor_level mixed_level default_level)
|
896
|
+
c_schema[:boxes].map { |b| b[:name] }.must_equal %w(editor_level mixed_level default_level)
|
882
897
|
end
|
883
898
|
end
|
884
899
|
end
|