public
Fork of halorgium/mephisto
Description: A mirror of the mephisto code-base
Homepage: http://mephistoblog.com/
Clone URL: git://github.com/technoweenie/mephisto.git
Click here to lend your support to: mephisto and make a donation at www.pledgie.com !
add simple site memberships

git-svn-id: http://svn.techno-weenie.net/projects/mephisto/trunk@2090 
567b1171-46fb-0310-a4c9-b4bef9110e78
technoweenie (author)
Wed Sep 06 00:21:00 -0700 2006
commit  2bdff7b66cf6bbbad6e365e7393546af7c2deb7e
tree    a1f1e06d1e5f85768954dcb93d89f920794aac1e
parent  a8e03e5772c8a9123606bfe4018f8b2f78f18b71
...
14
15
16
 
 
 
 
17
18
19
...
14
15
16
17
18
19
20
21
22
23
0
@@ -14,6 +14,10 @@ class Site < ActiveRecord::Base
0
   has_many :assets, :as => :attachable, :order => 'created_at desc'
0
   has_many :assets, :order => 'created_at desc', :conditions => 'parent_id is null'
0
 
0
+ has_many :memberships
0
+ has_many :members, :through => :memberships, :source => :user
0
+ has_many :admins, :through => :memberships, :source => :user, :conditions => ['memberships.admin = ? or users.admin = ?', true, true]
0
+
0
   before_validation :downcase_host
0
   before_validation :set_default_timezone
0
   before_validation_on_create :set_default_comment_options
...
1
 
2
3
4
 
 
 
 
 
 
 
5
6
7
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
0
@@ -1,7 +1,15 @@
0
 class User < UserAuth
0
+ @@admin_scope = {:find => { :conditions => ['admin = ?', true] } }
0
   has_many :articles
0
   acts_as_paranoid
0
 
0
+ has_many :memberships
0
+ has_many :sites, :through => :memberships, :order => 'title, host'
0
+
0
+ def self.find_admins(*args)
0
+ with_scope(@@admin_scope) { find *args }
0
+ end
0
+
0
   def to_liquid
0
     [:login, :email].inject({}) { |hsh, attr_name| hsh.merge attr_name.to_s => send(attr_name) }
0
   end
...
6
7
8
9
10
 
 
11
...
6
7
8
 
9
10
11
12
0
@@ -6,4 +6,5 @@ default:
0
   crypted_password: 00742970dc9e6319f8019fd54864d3ea740f04b1 # test
0
   activated_at: <%= Time.now.utc.to_s :db %>
0
   created_at: <%= Time.now.utc.to_s :db %>
0
- updated_at: <%= Time.now.utc.to_s :db %>
0
\ No newline at end of file
0
+ updated_at: <%= Time.now.utc.to_s :db %>
0
+ admin: true
0
\ No newline at end of file
...
2
3
4
5
 
6
7
8
...
95
96
97
 
 
 
 
 
 
 
98
99
100
...
152
153
154
 
155
156
157
...
2
3
4
 
5
6
7
8
...
95
96
97
98
99
100
101
102
103
104
105
106
107
...
159
160
161
162
163
164
165
0
@@ -2,7 +2,7 @@
0
 # migrations feature of ActiveRecord to incrementally modify your database, and
0
 # then regenerate this schema definition.
0
 
0
-ActiveRecord::Schema.define(:version => 51) do
0
+ActiveRecord::Schema.define(:version => 53) do
0
 
0
   create_table "assets", :force => true do |t|
0
     t.column "content_type", :string
0
@@ -95,6 +95,13 @@ ActiveRecord::Schema.define(:version => 51) do
0
     t.column "site_id", :integer
0
   end
0
 
0
+ create_table "memberships", :force => true do |t|
0
+ t.column "site_id", :integer
0
+ t.column "user_id", :integer
0
+ t.column "created_at", :datetime
0
+ t.column "admin", :boolean, :default => false
0
+ end
0
+
0
   create_table "sections", :force => true do |t|
0
     t.column "name", :string
0
     t.column "show_paged_articles", :boolean, :default => false
0
@@ -152,6 +159,7 @@ ActiveRecord::Schema.define(:version => 51) do
0
     t.column "remember_token", :string
0
     t.column "remember_token_expires_at", :datetime
0
     t.column "filter", :string
0
+ t.column "admin", :boolean, :default => false
0
   end
0
 
0
 end
...
11
12
13
 
14
15
16
...
11
12
13
14
15
16
17
0
@@ -11,6 +11,7 @@ quentin:
0
   remember_token: quentintoken
0
   remember_token_expires_at: <%= 5.days.from_now.to_s :db %>
0
   # activated_at: <%= 5.days.ago.to_s :db %> # only if you're activating new signups
0
+ admin: true
0
 arthur:
0
   id: 2
0
   login: arthur
...
46
47
48
 
 
 
 
49
50
51
...
46
47
48
49
50
51
52
53
54
55
0
@@ -46,6 +46,10 @@ class UserTest < Test::Unit::TestCase
0
     assert_equal '', users(:quentin).reload.filter
0
   end
0
 
0
+ def test_should_find_admins
0
+ assert_models_equal [users(:quentin)], User.find_admins(:all)
0
+ end
0
+
0
   protected
0
     def create_user(options = {})
0
       User.create({ :login => 'quire', :email => 'quire@example.com', :password => 'quire', :password_confirmation => 'quire' }.merge(options))

Comments

    No one has commented yet.