appoxy_sessions 0.0.16 → 0.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/sessions/application_controller.rb +3 -1
- data/lib/sessions/shareable.rb +44 -19
- data/lib/sessions/users_controller.rb +11 -4
- metadata +3 -3
@@ -54,9 +54,11 @@ module Appoxy
|
|
54
54
|
session[:return_to] = request.request_uri # return to after logging in
|
55
55
|
puts "ac=" + params[:ac].inspect
|
56
56
|
if params[:user_id] && params[:ac]
|
57
|
+
# todo: should we store ac in cookie? Make it easier to pass around
|
58
|
+
cookies[:ac] = params[:ac]
|
57
59
|
# then from an invite
|
58
60
|
user = ::User.find(params[:user_id])
|
59
|
-
if user && user.password.blank? # this the best way to decide of user has not logged in? Could also check status.
|
61
|
+
if user && user.password.blank? # is this the best way to decide of user has not logged in? Could also check status.
|
60
62
|
redirect_to :controller=>"users", :action=>"new", :email=>user.email, :ac=>params[:ac]
|
61
63
|
return
|
62
64
|
end
|
data/lib/sessions/shareable.rb
CHANGED
@@ -2,6 +2,18 @@ module Appoxy
|
|
2
2
|
module Sessions
|
3
3
|
module Shareable
|
4
4
|
|
5
|
+
# Call this method on your Sharable object to share it with the person.
|
6
|
+
# returns: a hash with :user (the user that the item was shared with), :ac (activation code that should be sent to the user)
|
7
|
+
# or false if couldn't be shared.
|
8
|
+
# You can check for errors by looking at the errors array of the object.
|
9
|
+
# Eg:
|
10
|
+
# if my_ob.share_with(x)
|
11
|
+
# # all good
|
12
|
+
# Mail the user a link that contains user_id and ac, this gem will take care of the rest.
|
13
|
+
# else
|
14
|
+
# # not all good, check errors
|
15
|
+
# errors = my_ob.errors
|
16
|
+
# end
|
5
17
|
|
6
18
|
def share_with(email, access_rights={}, options={})
|
7
19
|
|
@@ -9,13 +21,8 @@ module Appoxy
|
|
9
21
|
|
10
22
|
@email = email.strip
|
11
23
|
|
12
|
-
# See if user exists in the system already
|
13
|
-
# if @email == current_user.email current_user not available from here
|
14
|
-
# flash[:error] = "Now why do you want to invite yourself??"
|
15
|
-
# return false
|
16
|
-
# end
|
17
24
|
if @email == self.user.email
|
18
|
-
self.errors.add_to_base("
|
25
|
+
self.errors.add_to_base("User already owns this item.")
|
19
26
|
return false
|
20
27
|
end
|
21
28
|
|
@@ -23,7 +30,7 @@ module Appoxy
|
|
23
30
|
if user.nil?
|
24
31
|
# lets create the user and send them an invite.
|
25
32
|
user = ::User.new(:email=>@email, :status=>"invited")
|
26
|
-
user.set_activation_code
|
33
|
+
user.set_activation_code # todo: this shouldn't be on user anymore
|
27
34
|
if user.save
|
28
35
|
|
29
36
|
else
|
@@ -31,6 +38,7 @@ module Appoxy
|
|
31
38
|
return false
|
32
39
|
end
|
33
40
|
end
|
41
|
+
activation_code = user.activation_code
|
34
42
|
|
35
43
|
# check if exists
|
36
44
|
share_domain = self.share_domain
|
@@ -38,14 +46,13 @@ module Appoxy
|
|
38
46
|
# puts 'share_domain = ' + share_domain.inspect
|
39
47
|
@sdb = SimpleRecord::Base.connection
|
40
48
|
# @shared_with = share_class.find(:first, :conditions=>["user_id = ? and item_id = ?", user.id, @item.id])
|
41
|
-
@project_user = get_results(:first, ["select * from #{share_domain} where user_id=? and #{item_id_name} = ?", user.id, self.id])
|
42
|
-
puts '
|
49
|
+
@project_user = Shareable.get_results(:first, ["select * from #{share_domain} where user_id=? and #{item_id_name} = ?", user.id, self.id])
|
50
|
+
puts 'sharing user=' + @project_user.inspect
|
43
51
|
unless @project_user.nil?
|
44
|
-
self.errors.add_to_base("This
|
52
|
+
self.errors.add_to_base("This item is already shared with #{email}.")
|
45
53
|
return false
|
46
54
|
end
|
47
55
|
|
48
|
-
# id = self.class.generate_id
|
49
56
|
now = Time.now
|
50
57
|
id = share_id(user)
|
51
58
|
@sdb.put_attributes(share_domain, id, {:new_share=>true,
|
@@ -53,9 +60,15 @@ module Appoxy
|
|
53
60
|
:created=>SimpleRecord::Translations.pad_and_offset(now),
|
54
61
|
:updated=>SimpleRecord::Translations.pad_and_offset(now),
|
55
62
|
:user_id => user.id,
|
56
|
-
|
63
|
+
:activation_code=>activation_code,
|
64
|
+
:status=>"invited",
|
65
|
+
item_id_name => self.id}.merge(access_rights), true)
|
57
66
|
|
58
|
-
|
67
|
+
ret = {
|
68
|
+
:user=>user,
|
69
|
+
:ac=>activation_code
|
70
|
+
}
|
71
|
+
return ret
|
59
72
|
|
60
73
|
end
|
61
74
|
|
@@ -63,12 +76,13 @@ module Appoxy
|
|
63
76
|
return self.class.name.foreign_key
|
64
77
|
end
|
65
78
|
|
66
|
-
def
|
79
|
+
def common_attributes
|
67
80
|
["new_share", "id", "created", "updated", "user_id", item_id_name]
|
68
81
|
end
|
69
82
|
|
83
|
+
# Returns a list of users that this item is shared with.
|
70
84
|
def shared_with
|
71
|
-
project_users = get_results(:all, ["select * from #{share_domain} where #{item_id_name} = ?", self.id])
|
85
|
+
project_users = Shareable.get_results(:all, ["select * from #{share_domain} where #{item_id_name} = ?", self.id])
|
72
86
|
user_ids = []
|
73
87
|
options_hash = {}
|
74
88
|
project_users.each do |puhash|
|
@@ -94,6 +108,7 @@ module Appoxy
|
|
94
108
|
ret
|
95
109
|
end
|
96
110
|
|
111
|
+
# this unshares by the
|
97
112
|
def unshare_by_id(id)
|
98
113
|
# @project_user = ProjectUser.find(params[:pu_id])
|
99
114
|
# @project_user.delete
|
@@ -103,15 +118,25 @@ module Appoxy
|
|
103
118
|
# puts 'deleted?'
|
104
119
|
end
|
105
120
|
|
121
|
+
# Unshare by user.
|
122
|
+
def unshare(user)
|
123
|
+
@sdb = SimpleRecord::Base.connection
|
124
|
+
@sdb.delete_attributes(share_domain, share_id(user))
|
125
|
+
# @project_user = Shareable.get_results(:first, ["select * from #{share_domain} where user_id=? and #{item_id_name} = ?", user.id, self.id])
|
126
|
+
# @project_user.each do |pu|
|
127
|
+
# @sdb.delete_attributes(share_domain, pu["id"])
|
128
|
+
# end
|
129
|
+
end
|
130
|
+
|
106
131
|
def update_sharing_options(user, options={})
|
107
132
|
options={} if options.nil?
|
108
133
|
# puts 'options=' + ({ :updated=>Time.now }.merge(options)).inspect
|
109
134
|
@sdb = SimpleRecord::Base.connection
|
110
|
-
@project_user = get_results(:first, ["select * from #{share_domain} where user_id=? and #{item_id_name} = ?", user.id, self.id])
|
135
|
+
@project_user = Shareable.get_results(:first, ["select * from #{share_domain} where user_id=? and #{item_id_name} = ?", user.id, self.id])
|
111
136
|
# compare values
|
112
137
|
to_delete = []
|
113
138
|
@project_user.each_pair do |k, v|
|
114
|
-
if !
|
139
|
+
if !common_attributes.include?(k) && !options.include?(k)
|
115
140
|
to_delete << k
|
116
141
|
end
|
117
142
|
end
|
@@ -119,7 +144,7 @@ module Appoxy
|
|
119
144
|
puts 'to_delete=' + to_delete.inspect
|
120
145
|
@sdb.delete_attributes(share_domain, share_id(user), to_delete)
|
121
146
|
end
|
122
|
-
@sdb.put_attributes(share_domain, share_id(user), {
|
147
|
+
@sdb.put_attributes(share_domain, share_id(user), {:updated=>Time.now}.merge(options), true)
|
123
148
|
|
124
149
|
end
|
125
150
|
|
@@ -137,7 +162,7 @@ module Appoxy
|
|
137
162
|
end
|
138
163
|
|
139
164
|
|
140
|
-
def get_results(which, q)
|
165
|
+
def self.get_results(which, q)
|
141
166
|
@sdb = SimpleRecord::Base.connection
|
142
167
|
next_token = nil
|
143
168
|
ret = []
|
@@ -6,10 +6,13 @@ module Appoxy
|
|
6
6
|
|
7
7
|
def new
|
8
8
|
before_new
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
if params[:id]
|
10
|
+
@user = User.find params[:id]
|
11
|
+
else
|
12
|
+
@user = User.new
|
13
|
+
@user.email = params[:email] if params[:email]
|
14
|
+
end
|
15
|
+
@user.activation_code = params[:ac] if params[:ac]
|
13
16
|
after_new
|
14
17
|
end
|
15
18
|
|
@@ -42,6 +45,10 @@ module Appoxy
|
|
42
45
|
existing_user = ::User.find_by_email(@user.email)
|
43
46
|
|
44
47
|
if existing_user
|
48
|
+
if params[:ac]
|
49
|
+
|
50
|
+
end
|
51
|
+
# todo: remove activation_code on user
|
45
52
|
if @user.activation_code.present?
|
46
53
|
# hasn't logged in yet, probably invited, need to check access key
|
47
54
|
if existing_user.activation_code == @user.activation_code
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: appoxy_sessions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 61
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 17
|
10
|
+
version: 0.0.17
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Travis Reeder
|