bcms_cas 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,6 +2,13 @@ module Cms
2
2
 
3
3
  # This represents a 'temporary' user who is never stored in the database, but lives only as a limited duration (generally tied to a session)
4
4
  # This can be used to represent an externally verified user who should be granted access to areas of the site.
5
+ #
6
+ #
7
+ # Typical Usage:
8
+ #
9
+ # user = Cms::TemporaryUser.new(:login=>"bob@externalurl.com")
10
+ # user << Group.find_by_code("Special Group")
11
+ # user.able_to_view?("/some/path")
5
12
  class TemporaryUser < User
6
13
 
7
14
  # Shouldn't save these users to the db.
@@ -22,6 +29,22 @@ module Cms
22
29
  groups.each do |g|
23
30
  return true if g.cms_access?
24
31
  end
32
+ false
33
+ end
34
+
35
+ # def cms_access?
36
+ # groups.each do |g|
37
+ # return true if g.cms_access?
38
+ # end
39
+ # false
40
+ # end
41
+
42
+ # Returns all sections that this user has rights to view.
43
+ #
44
+ # Overrides core behavior of User to avoid including user as part of the query (since temp users doen't exist in the database).
45
+ #
46
+ def viewable_sections
47
+ Section.find(:all, :joins=>:groups, :conditions=>["groups.id IN (?)", groups])
25
48
  end
26
49
  end
27
50
  end
@@ -29,6 +29,45 @@ class TemporaryUserTest < ActiveSupport::TestCase
29
29
  test "Should belong to no groups by default" do
30
30
  assert_equal 0, @user.groups.size
31
31
  end
32
+
33
+ test "Temp users should be able to view sections their groups have permissions to" do
34
+ group = Group.create!(:name=>"My Group")
35
+ section = Section.create!(:name=>"My Section", :path=>"/mysection")
36
+ section.groups << group
37
+ section.save!
38
+
39
+ user = Cms::TemporaryUser.new
40
+ user.groups << group
41
+
42
+ assert user.able_to_view?(section)
43
+
44
+
45
+ end
46
+
47
+ test "Viewable sections" do
48
+ group = Group.create!(:name=>"Group 1")
49
+ first_section = Section.create!(:name=>"Section1", :path=>"/section1")
50
+ first_section.groups << group
51
+ first_section.save!
52
+
53
+ group2 = Group.create!(:name=>"Group 2")
54
+ second_section = Section.create!(:name=>"Section 2", :path=>"/section2")
55
+ second_section.groups << group2
56
+ second_section.save!
57
+
58
+ user = Cms::TemporaryUser.new
59
+ user.groups << group << group2
60
+
61
+ assert_equal [first_section, second_section], user.viewable_sections
62
+ assert user.able_to_view?(first_section)
63
+ assert user.able_to_view?(second_section)
64
+
65
+ end
66
+
67
+ test "A user with no groups should not have CMS access" do
68
+ user = Cms::TemporaryUser.new
69
+ assert_equal false, user.cms_access?
70
+ end
32
71
  end
33
72
 
34
73
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bcms_cas
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 1
9
- - 0
10
- version: 1.1.0
9
+ - 1
10
+ version: 1.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - BrowserMedia
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-30 00:00:00 -04:00
18
+ date: 2010-10-05 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency