appoxy_sessions 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/sessions/shareable.rb +133 -135
  2. metadata +2 -2
@@ -1,173 +1,171 @@
1
-
2
1
  module Appoxy
3
- module Sessions
4
- module Shareable
2
+ module Sessions
3
+ module Shareable
5
4
 
6
5
 
7
- def share_with(email, access_rights={}, options={})
6
+ def share_with(email, access_rights={}, options={})
8
7
 
9
- @email = email.strip
8
+ @email = email.strip
10
9
 
11
- # See if user exists in the system already
10
+ # See if user exists in the system already
12
11
  # if @email == current_user.email current_user not available from here
13
12
  # flash[:error] = "Now why do you want to invite yourself??"
14
13
  # return false
15
14
  # end
16
- if @email == self.user.email
17
- self.errors.add_to_base("That user already owns this project.")
18
- return false
19
- end
15
+ if @email == self.user.email
16
+ self.errors.add_to_base("That user already owns this project.")
17
+ return false
18
+ end
20
19
 
21
- user = ::User.find_by_email(@email)
22
- if user.nil?
23
- # lets create the user and send them an invite.
24
- user = User.new(:email=>@email, :status=>"invited")
25
- user.set_activation_code
26
- if user.save
20
+ user = ::User.find_by_email(@email)
21
+ if user.nil?
22
+ # lets create the user and send them an invite.
23
+ user = User.new(:email=>@email, :status=>"invited")
24
+ user.set_activation_code
25
+ if user.save
27
26
 
28
- else
29
- @errors = user.errors.full_messages
30
- return false
31
- end
32
- end
27
+ else
28
+ @errors = user.errors.full_messages
29
+ return false
30
+ end
31
+ end
33
32
 
34
- # check if exists
35
- share_domain = self.share_domain
36
- item_id_name = self.item_id_name
37
- puts 'share_domain = ' + share_domain.inspect
38
- @sdb = SimpleRecord::Base.connection
33
+ # check if exists
34
+ share_domain = self.share_domain
35
+ item_id_name = self.item_id_name
36
+ puts 'share_domain = ' + share_domain.inspect
37
+ @sdb = SimpleRecord::Base.connection
39
38
  # @shared_with = share_class.find(:first, :conditions=>["user_id = ? and item_id = ?", user.id, @item.id])
40
- @project_user = get_results(:first, ["select * from #{share_domain} where user_id=? and #{item_id_name} = ?", user.id, self.id])
41
- puts '@project_user=' + @project_user.inspect
42
- unless @project_user.nil?
43
- self.errors.add_to_base("This project is already shared with this user.")
44
- return false
45
- end
39
+ @project_user = get_results(:first, ["select * from #{share_domain} where user_id=? and #{item_id_name} = ?", user.id, self.id])
40
+ puts '@project_user=' + @project_user.inspect
41
+ unless @project_user.nil?
42
+ self.errors.add_to_base("This project is already shared with this user.")
43
+ return false
44
+ end
46
45
 
47
46
  # id = self.class.generate_id
48
- now = Time.now
49
- id = share_id(user)
50
- @sdb.put_attributes(share_domain, id, {:new_share=>true,
51
- :id=>id,
52
- :created=>now,
53
- :updated=>now,
54
- :user_id => user.id,
55
- item_id_name => self.id }.merge(access_rights), true)
47
+ now = Time.now
48
+ id = share_id(user)
49
+ @sdb.put_attributes(share_domain, id, {:new_share=>true,
50
+ :id=>id,
51
+ :created=>now,
52
+ :updated=>now,
53
+ :user_id => user.id,
54
+ item_id_name => self.id }.merge(access_rights), true)
56
55
 
57
56
 
58
- end
59
-
60
- def item_id_name
61
- name.foreign_key
62
-
63
- end
64
-
65
- def common_attribrutes
66
- ["new_share", "id", "created", "updated", "user_id", item_id_name]
67
- end
68
-
69
- def shared_with
70
- project_users = get_results(:all, ["select * from #{share_domain} where #{item_id_name} = ?", self.id])
71
- user_ids = []
72
- options_hash = {}
73
- project_users.each do |puhash|
74
- puhash.each_pair do |k, v|
75
- puhash[k] = v[0]
76
57
  end
77
- puts 'puhash=' + puhash.inspect
78
- user_ids << puhash["user_id"]
79
- options_hash[puhash["user_id"]] = puhash
80
- end
81
- ret = ::User.find(:all, :conditions=>["id in ('#{user_ids.join("','")}')"]).collect do |u|
82
- def u.share_options=(options=nil)
83
- instance_variable_set(:@share_options, options)
58
+
59
+ def item_id_name
60
+ return self.class.name.foreign_key
84
61
  end
85
62
 
86
- def u.share_options
87
- instance_variable_get(:@share_options)
63
+ def common_attribrutes
64
+ ["new_share", "id", "created", "updated", "user_id", item_id_name]
88
65
  end
89
66
 
90
- u.share_options=options_hash[u.id]
91
- u
92
- end
93
- ret
94
- end
67
+ def shared_with
68
+ project_users = get_results(:all, ["select * from #{share_domain} where #{item_id_name} = ?", self.id])
69
+ user_ids = []
70
+ options_hash = {}
71
+ project_users.each do |puhash|
72
+ puhash.each_pair do |k, v|
73
+ puhash[k] = v[0]
74
+ end
75
+ puts 'puhash=' + puhash.inspect
76
+ user_ids << puhash["user_id"]
77
+ options_hash[puhash["user_id"]] = puhash
78
+ end
79
+ ret = ::User.find(:all, :conditions=>["id in ('#{user_ids.join("','")}')"]).collect do |u|
80
+ def u.share_options=(options=nil)
81
+ instance_variable_set(:@share_options, options)
82
+ end
95
83
 
96
- def unshare_by_id(id)
84
+ def u.share_options
85
+ instance_variable_get(:@share_options)
86
+ end
87
+
88
+ u.share_options=options_hash[u.id]
89
+ u
90
+ end
91
+ ret
92
+ end
93
+
94
+ def unshare_by_id(id)
97
95
  # @project_user = ProjectUser.find(params[:pu_id])
98
96
  # @project_user.delete
99
- puts 'unsharing ' + id.to_s
100
- @sdb = SimpleRecord::Base.connection
101
- puts "response=" + @sdb.delete_attributes(share_domain, id.to_s).inspect
102
- puts 'deleted?'
103
- end
104
-
105
- def update_sharing_options(user, options={})
106
- puts 'options=' + ({ :updated=>Time.now }.merge(options)).inspect
107
- @sdb = SimpleRecord::Base.connection
108
- @project_user = get_results(:first, ["select * from #{share_domain} where user_id=? and #{item_id_name} = ?", user.id, self.id])
109
- # compare values
110
- to_delete = []
111
- @project_user.each_pair do |k,v|
112
- if !common_attribrutes.include?(k) && !options.include?(k)
113
- to_delete << k
97
+ puts 'unsharing ' + id.to_s
98
+ @sdb = SimpleRecord::Base.connection
99
+ puts "response=" + @sdb.delete_attributes(share_domain, id.to_s).inspect
100
+ puts 'deleted?'
114
101
  end
115
- end
116
- if to_delete.size > 0
117
- puts 'to_delete=' + to_delete.inspect
118
- @sdb.delete_attributes(share_domain, share_id(user), to_delete)
119
- end
120
- @sdb.put_attributes(share_domain, share_id(user), { :updated=>Time.now }.merge(options), true)
121
102
 
122
- end
103
+ def update_sharing_options(user, options={})
104
+ puts 'options=' + ({ :updated=>Time.now }.merge(options)).inspect
105
+ @sdb = SimpleRecord::Base.connection
106
+ @project_user = get_results(:first, ["select * from #{share_domain} where user_id=? and #{item_id_name} = ?", user.id, self.id])
107
+ # compare values
108
+ to_delete = []
109
+ @project_user.each_pair do |k, v|
110
+ if !common_attribrutes.include?(k) && !options.include?(k)
111
+ to_delete << k
112
+ end
113
+ end
114
+ if to_delete.size > 0
115
+ puts 'to_delete=' + to_delete.inspect
116
+ @sdb.delete_attributes(share_domain, share_id(user), to_delete)
117
+ end
118
+ @sdb.put_attributes(share_domain, share_id(user), { :updated=>Time.now }.merge(options), true)
123
119
 
124
- def share_id(user)
125
- "#{self.id}_#{user.id}"
126
- end
120
+ end
127
121
 
128
- def share_domain
129
- puts 'instance share_domain'
130
- ret = self.class.name + "User"
131
- puts 'SHARE_NAME=' + ret
132
- ret = ret.tableize
133
- puts 'ret=' + ret
134
- ret
135
- end
122
+ def share_id(user)
123
+ "#{self.id}_#{user.id}"
124
+ end
136
125
 
126
+ def share_domain
127
+ puts 'instance share_domain'
128
+ ret = self.class.name + "User"
129
+ puts 'SHARE_NAME=' + ret
130
+ ret = ret.tableize
131
+ puts 'ret=' + ret
132
+ ret
133
+ end
137
134
 
138
- def get_results(which, q)
139
- @sdb = SimpleRecord::Base.connection
140
- next_token = nil
141
- ret = []
142
- begin
143
- begin
144
- response = @sdb.select(q, next_token)
145
- rs = response[:items]
146
- rs.each_with_index do |i, index|
147
- puts 'i=' + i.inspect
148
- i.each_key do |k|
149
- puts 'key=' + k.inspect
150
- if which == :first
151
- return i[k].update("id"=>k)
135
+
136
+ def get_results(which, q)
137
+ @sdb = SimpleRecord::Base.connection
138
+ next_token = nil
139
+ ret = []
140
+ begin
141
+ begin
142
+ response = @sdb.select(q, next_token)
143
+ rs = response[:items]
144
+ rs.each_with_index do |i, index|
145
+ puts 'i=' + i.inspect
146
+ i.each_key do |k|
147
+ puts 'key=' + k.inspect
148
+ if which == :first
149
+ return i[k].update("id"=>k)
150
+ end
151
+ ret << i[k]
152
+ end
153
+ # break if index > 100
152
154
  end
153
- ret << i[k]
155
+ next_token = response[:next_token]
156
+ end until next_token.nil?
157
+ rescue Aws::AwsError, Aws::ActiveSdb::ActiveSdbError
158
+ if ($!.message().index("NoSuchDomain") != nil)
159
+ puts 'NO SUCH DOMAIN!!!'
160
+ # this is ok
161
+ else
162
+ raise $!
154
163
  end
155
- # break if index > 100
156
164
  end
157
- next_token = response[:next_token]
158
- end until next_token.nil?
159
- rescue Aws::AwsError, Aws::ActiveSdb::ActiveSdbError
160
- if ($!.message().index("NoSuchDomain") != nil)
161
- puts 'NO SUCH DOMAIN!!!'
162
- # this is ok
163
- else
164
- raise $!
165
+ which == :first ? nil : ret
165
166
  end
167
+
166
168
  end
167
- which == :first ? nil : ret
168
169
  end
169
-
170
- end
171
- end
172
- end
170
+ end
173
171
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appoxy_sessions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Travis Reeder
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-09 00:00:00 -08:00
12
+ date: 2010-02-15 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency