appoxy_sessions 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/appoxy_sessions.rb +1 -1
- data/lib/sessions/shareable.rb +173 -0
- metadata +3 -2
data/lib/appoxy_sessions.rb
CHANGED
@@ -3,4 +3,4 @@ require File.join(File.dirname(__FILE__), "sessions", "user")
|
|
3
3
|
require File.join(File.dirname(__FILE__), "sessions", "application_controller")
|
4
4
|
require File.join(File.dirname(__FILE__), "sessions", "sessions_controller")
|
5
5
|
require File.join(File.dirname(__FILE__), "sessions", "users_controller")
|
6
|
-
|
6
|
+
require File.join(File.dirname(__FILE__), "sessions", "shareable")
|
@@ -0,0 +1,173 @@
|
|
1
|
+
|
2
|
+
module Appoxy
|
3
|
+
module Sessions
|
4
|
+
module Shareable
|
5
|
+
|
6
|
+
|
7
|
+
def share_with(email, access_rights={}, options={})
|
8
|
+
|
9
|
+
@email = email.strip
|
10
|
+
|
11
|
+
# See if user exists in the system already
|
12
|
+
# if @email == current_user.email current_user not available from here
|
13
|
+
# flash[:error] = "Now why do you want to invite yourself??"
|
14
|
+
# return false
|
15
|
+
# end
|
16
|
+
if @email == self.user.email
|
17
|
+
self.errors.add_to_base("That user already owns this project.")
|
18
|
+
return false
|
19
|
+
end
|
20
|
+
|
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
|
27
|
+
|
28
|
+
else
|
29
|
+
@errors = user.errors.full_messages
|
30
|
+
return false
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
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
|
39
|
+
# @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
|
46
|
+
|
47
|
+
# 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)
|
56
|
+
|
57
|
+
|
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
|
+
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)
|
84
|
+
end
|
85
|
+
|
86
|
+
def u.share_options
|
87
|
+
instance_variable_get(:@share_options)
|
88
|
+
end
|
89
|
+
|
90
|
+
u.share_options=options_hash[u.id]
|
91
|
+
u
|
92
|
+
end
|
93
|
+
ret
|
94
|
+
end
|
95
|
+
|
96
|
+
def unshare_by_id(id)
|
97
|
+
# @project_user = ProjectUser.find(params[:pu_id])
|
98
|
+
# @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
|
114
|
+
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
|
+
|
122
|
+
end
|
123
|
+
|
124
|
+
def share_id(user)
|
125
|
+
"#{self.id}_#{user.id}"
|
126
|
+
end
|
127
|
+
|
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
|
136
|
+
|
137
|
+
|
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)
|
152
|
+
end
|
153
|
+
ret << i[k]
|
154
|
+
end
|
155
|
+
# break if index > 100
|
156
|
+
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
|
+
end
|
166
|
+
end
|
167
|
+
which == :first ? nil : ret
|
168
|
+
end
|
169
|
+
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
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.
|
4
|
+
version: 0.0.8
|
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-
|
12
|
+
date: 2010-02-09 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -44,6 +44,7 @@ files:
|
|
44
44
|
- lib/appoxy_sessions.rb
|
45
45
|
- lib/sessions/application_controller.rb
|
46
46
|
- lib/sessions/sessions_controller.rb
|
47
|
+
- lib/sessions/shareable.rb
|
47
48
|
- lib/sessions/user.rb
|
48
49
|
- lib/sessions/users_controller.rb
|
49
50
|
- README.markdown
|