appoxy_rails 0.0.30 → 0.0.31
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/appoxy_rails.rb +4 -4
- data/lib/railtie.rb +2 -2
- data/lib/{rails → server_api}/api_controller.rb +4 -4
- data/lib/server_api/signatures.rb +26 -0
- data/lib/sessions/oauth_token.rb +5 -5
- data/lib/sessions/sessions_controller.rb +2 -2
- data/lib/sessions/shareable.rb +165 -165
- metadata +4 -4
- data/lib/rails/signatures.rb +0 -26
data/lib/appoxy_rails.rb
CHANGED
@@ -8,16 +8,16 @@ require_relative 'appoxy_ui'
|
|
8
8
|
require_relative 'appoxy_sessions'
|
9
9
|
require_relative 'ui/time_zoner'
|
10
10
|
|
11
|
-
require_relative "
|
12
|
-
require_relative "
|
11
|
+
require_relative "server_api/api_controller"
|
12
|
+
require_relative "server_api/signatures"
|
13
13
|
|
14
14
|
|
15
15
|
# backwards compatible.
|
16
16
|
# @deprecated
|
17
17
|
module Appoxy
|
18
18
|
module Api
|
19
|
-
include Appoxy::
|
20
|
-
extend Appoxy::
|
19
|
+
include Appoxy::ServerApi
|
20
|
+
extend Appoxy::ServerApi
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
data/lib/railtie.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
# see http://
|
1
|
+
# see http://server_api.rubyonrails.org/classes/Rails/Railtie.html
|
2
2
|
|
3
3
|
# Nice write-up of hooking gems into the views/layouts/statics of Rails 3 apps:
|
4
|
-
# http://numbers.brighterplanet.com/2010/07/26/sharing-views-across-
|
4
|
+
# http://numbers.brighterplanet.com/2010/07/26/sharing-views-across-server_api-3-apps/
|
5
5
|
|
6
6
|
require 'rails'
|
7
7
|
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module Appoxy
|
2
2
|
|
3
|
-
module
|
3
|
+
module ServerApi
|
4
4
|
|
5
|
-
# The
|
5
|
+
# The server_api controllers that use this should set:
|
6
6
|
# protect_from_forgery :only => [] # can add methods to here, eg: :create, :update, :destroy
|
7
7
|
|
8
8
|
# rescue_from SigError, :with => :send_error
|
@@ -26,7 +26,7 @@ module Appoxy
|
|
26
26
|
end
|
27
27
|
|
28
28
|
#operation = "#{controller_name}/#{action_name}"
|
29
|
-
#operation = request.env["PATH_INFO"].gsub(/\/
|
29
|
+
#operation = request.env["PATH_INFO"].gsub(/\/server_api\//, "")# here we're getting original request url'
|
30
30
|
|
31
31
|
# #getting clean params (without parsed via routes)
|
32
32
|
# params_for_signature = params2||request.query_parameters
|
@@ -46,7 +46,7 @@ module Appoxy
|
|
46
46
|
signature = "#{controller_name}/#{action_name}"
|
47
47
|
when "0.2"
|
48
48
|
# puts "new version of client"
|
49
|
-
operation = request.env["PATH_INFO"].gsub(/\/
|
49
|
+
operation = request.env["PATH_INFO"].gsub(/\/server_api\//, "") # here we're getting original request url'
|
50
50
|
params_for_signature = params2||request.query_parameters
|
51
51
|
params_for_signature = params_for_signature.delete_if { |key, value| ["access_key", "sigv", "sig", "timestamp"].include? key }
|
52
52
|
signature = operation+Appoxy::Api::Signatures.hash_to_s(params_for_signature)
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Appoxy
|
2
|
+
module ServerApi
|
3
|
+
module Signatures
|
4
|
+
|
5
|
+
|
6
|
+
def self.generate_timestamp(gmtime)
|
7
|
+
return gmtime.strftime("%Y-%m-%dT%H:%M:%SZ")
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
def self.generate_signature(operation, timestamp, secret_key)
|
12
|
+
my_sha_hmac = Digest::HMAC.digest(operation + timestamp, secret_key, Digest::SHA1)
|
13
|
+
my_b64_hmac_digest = Base64.encode64(my_sha_hmac).strip
|
14
|
+
return my_b64_hmac_digest
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
def self.hash_to_s(hash)
|
19
|
+
str = ""
|
20
|
+
hash.sort.each { |a| str+= "#{a[0]}#{a[1]}" }
|
21
|
+
#removing all characters that could differ after parsing with server_api
|
22
|
+
return str.delete "\"\/:{}[]\' T"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/sessions/oauth_token.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
class OauthToken < SimpleRecord::Base
|
2
2
|
|
3
|
-
|
3
|
+
belongs_to :user
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
has_strings :type, # request or access
|
6
|
+
:site,
|
7
|
+
:token,
|
8
|
+
:secret
|
9
9
|
|
10
10
|
# has_clobs :access_token
|
11
11
|
|
@@ -359,9 +359,9 @@ module Appoxy
|
|
359
359
|
signin = true
|
360
360
|
callback_url = "#{base_url}/sessions/#{(signin ? "create_twitter" : "create_twitter_oauth")}"
|
361
361
|
auth_path = signin ? "authenticate" : "authorize"
|
362
|
-
consumer = oauth_start(::Rails.application.config.twitter_consumer_key, Rails.application.config.twitter_consumer_secret,
|
362
|
+
consumer = oauth_start(::Rails.application.config.twitter_consumer_key, ::Rails.application.config.twitter_consumer_secret,
|
363
363
|
callback_url,
|
364
|
-
"https://
|
364
|
+
"https://server_api.twitter.com",
|
365
365
|
"/oauth/request_token",
|
366
366
|
"/oauth/#{auth_path}",
|
367
367
|
"/oauth/access_token"
|
data/lib/sessions/shareable.rb
CHANGED
@@ -2,205 +2,205 @@ require 'aws'
|
|
2
2
|
require 'simple_record'
|
3
3
|
|
4
4
|
module Appoxy
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
5
|
+
module Sessions
|
6
|
+
module Shareable
|
7
|
+
|
8
|
+
# Call this method on your Sharable object to share it with the person.
|
9
|
+
# returns: a hash with :user (the user that the item was shared with), :ac (activation code that should be sent to the user)
|
10
|
+
# or false if couldn't be shared.
|
11
|
+
# You can check for errors by looking at the errors array of the object.
|
12
|
+
# Eg:
|
13
|
+
# if my_ob.share_with(x)
|
14
|
+
# # all good
|
15
|
+
# Mail the user a link that contains user_id and ac, this gem will take care of the rest.
|
16
|
+
# else
|
17
|
+
# # not all good, check errors
|
18
|
+
# errors = my_ob.errors
|
19
|
+
# end
|
20
|
+
|
21
|
+
def share_with(email, access_rights={}, options={})
|
22
|
+
|
23
|
+
access_rights = {} if access_rights.nil?
|
24
|
+
|
25
|
+
@email = email.strip
|
26
|
+
|
27
|
+
if @email == self.user.email
|
28
|
+
self.errors.add_to_base("User already owns this item.")
|
29
|
+
return false
|
30
|
+
end
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
32
|
+
user = ::User.find_by_email(@email)
|
33
|
+
if user.nil?
|
34
|
+
# lets create the user and send them an invite.
|
35
|
+
user = ::User.new(:email=>@email, :status=>"invited")
|
36
|
+
user.set_activation_code # todo: this shouldn't be on user anymore
|
37
|
+
if user.save
|
38
|
+
|
39
|
+
else
|
40
|
+
self.errors = user.errors
|
41
|
+
return false
|
42
|
+
end
|
43
|
+
end
|
44
|
+
activation_code = user.activation_code
|
45
45
|
|
46
|
-
|
47
|
-
|
48
|
-
|
46
|
+
# check if exists
|
47
|
+
share_domain = self.share_domain
|
48
|
+
item_id_name = self.item_id_name
|
49
49
|
# puts 'share_domain = ' + share_domain.inspect
|
50
|
-
|
50
|
+
@sdb = SimpleRecord::Base.connection
|
51
51
|
# @shared_with = share_class.find(:first, :conditions=>["user_id = ? and item_id = ?", user.id, @item.id])
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
52
|
+
@project_user = Shareable.get_results(:first, ["select * from #{share_domain} where user_id=? and #{item_id_name} = ?", user.id, self.id])
|
53
|
+
puts 'sharing user=' + @project_user.inspect
|
54
|
+
unless @project_user.nil?
|
55
|
+
self.errors.add_to_base("This item is already shared with #{email}.")
|
56
|
+
return false
|
57
|
+
end
|
58
58
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
59
|
+
now = Time.now
|
60
|
+
id = share_id(user)
|
61
|
+
@sdb.put_attributes(share_domain, id, {:new_share=>true,
|
62
|
+
:id=>id,
|
63
|
+
:created=>SimpleRecord::Translations.pad_and_offset(now),
|
64
|
+
:updated=>SimpleRecord::Translations.pad_and_offset(now),
|
65
|
+
:user_id => user.id,
|
66
|
+
:activation_code=>activation_code,
|
67
|
+
:status=>"invited",
|
68
|
+
item_id_name => self.id}.merge(access_rights),
|
69
|
+
true,
|
70
|
+
:create_domain=>true)
|
71
71
|
|
72
72
|
# ret = {
|
73
73
|
# :user=>user,
|
74
74
|
# :ac=>activation_code
|
75
75
|
# }
|
76
76
|
# return ret
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
77
|
+
return user
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
def item_id_name
|
82
|
+
return self.class.name.foreign_key
|
83
|
+
end
|
84
|
+
|
85
|
+
def common_attributes
|
86
|
+
["new_share", "id", "created", "updated", "user_id", item_id_name]
|
87
|
+
end
|
88
|
+
|
89
|
+
# Returns a list of users that this item is shared with.
|
90
|
+
def shared_with
|
91
|
+
project_users = Shareable.get_results(:all, ["select * from #{share_domain} where #{item_id_name} = ?", self.id])
|
92
|
+
user_ids = []
|
93
|
+
options_hash = {}
|
94
|
+
project_users.each do |puhash|
|
95
|
+
puhash.each_pair do |k, v|
|
96
|
+
puhash[k] = v[0]
|
97
|
+
end
|
98
|
+
puts 'puhash=' + puhash.inspect
|
99
|
+
user_ids << puhash["user_id"]
|
100
|
+
options_hash[puhash["user_id"]] = puhash
|
101
|
+
end
|
102
|
+
ret = ::User.find(:all, :conditions=>["id in ('#{user_ids.join("','")}')"]).collect do |u|
|
103
|
+
def u.share_options=(options=nil)
|
104
|
+
instance_variable_set(:@share_options, options)
|
105
|
+
end
|
106
106
|
|
107
|
-
|
108
|
-
|
109
|
-
|
107
|
+
def u.share_options
|
108
|
+
instance_variable_get(:@share_options)
|
109
|
+
end
|
110
110
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
111
|
+
u.share_options=options_hash[u.id]
|
112
|
+
u
|
113
|
+
end
|
114
|
+
ret
|
115
|
+
end
|
116
116
|
|
117
|
-
|
118
|
-
|
117
|
+
# this unshares by the
|
118
|
+
def unshare_by_id(id)
|
119
119
|
# @project_user = ProjectUser.find(params[:pu_id])
|
120
120
|
# @project_user.delete
|
121
121
|
# puts 'unsharing ' + id.to_s
|
122
|
-
|
123
|
-
|
122
|
+
@sdb = SimpleRecord::Base.connection
|
123
|
+
puts "delete_attributes=" + @sdb.delete_attributes(share_domain, id.to_s).inspect
|
124
124
|
# puts 'deleted?'
|
125
|
-
|
125
|
+
end
|
126
126
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
127
|
+
# Unshare by user.
|
128
|
+
def unshare(user)
|
129
|
+
@sdb = SimpleRecord::Base.connection
|
130
|
+
@sdb.delete_attributes(share_domain, share_id(user))
|
131
131
|
# @project_user = Shareable.get_results(:first, ["select * from #{share_domain} where user_id=? and #{item_id_name} = ?", user.id, self.id])
|
132
132
|
# @project_user.each do |pu|
|
133
133
|
# @sdb.delete_attributes(share_domain, pu["id"])
|
134
134
|
# end
|
135
|
-
|
135
|
+
end
|
136
136
|
|
137
|
-
|
138
|
-
|
137
|
+
def update_sharing_options(user, options={})
|
138
|
+
options={} if options.nil?
|
139
139
|
# puts 'options=' + ({ :updated=>Time.now }.merge(options)).inspect
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
140
|
+
@sdb = SimpleRecord::Base.connection
|
141
|
+
@project_user = Shareable.get_results(:first, ["select * from #{share_domain} where user_id=? and #{item_id_name} = ?", user.id, self.id])
|
142
|
+
# compare values
|
143
|
+
to_delete = []
|
144
|
+
@project_user.each_pair do |k, v|
|
145
|
+
if !common_attributes.include?(k) && !options.include?(k)
|
146
|
+
to_delete << k
|
147
|
+
end
|
148
|
+
end
|
149
|
+
if to_delete.size > 0
|
150
|
+
puts 'to_delete=' + to_delete.inspect
|
151
|
+
@sdb.delete_attributes(share_domain, share_id(user), to_delete)
|
152
|
+
end
|
153
|
+
@sdb.put_attributes(share_domain, share_id(user), {:updated=>Time.now}.merge(options), true)
|
154
154
|
|
155
|
-
|
155
|
+
end
|
156
156
|
|
157
|
-
|
158
|
-
|
159
|
-
|
157
|
+
def share_id(user)
|
158
|
+
"#{self.id}_#{user.id}"
|
159
|
+
end
|
160
160
|
|
161
|
-
|
161
|
+
def share_domain
|
162
162
|
# puts 'instance share_domain'
|
163
|
-
|
163
|
+
ret = self.class.name + "User"
|
164
164
|
# puts 'SHARE_NAME=' + ret
|
165
|
-
|
165
|
+
ret = ret.tableize
|
166
166
|
# puts 'ret=' + ret
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
end
|
186
|
-
ret << i[k]
|
187
|
-
end
|
188
|
-
# break if index > 100
|
189
|
-
end
|
190
|
-
next_token = response[:next_token]
|
191
|
-
end until next_token.nil?
|
192
|
-
rescue Aws::AwsError, Aws::ActiveSdb::ActiveSdbError
|
193
|
-
if ($!.message().index("NoSuchDomain") != nil)
|
194
|
-
puts 'NO SUCH DOMAIN!!!'
|
195
|
-
# this is ok
|
196
|
-
else
|
197
|
-
raise $!
|
198
|
-
end
|
167
|
+
ret
|
168
|
+
end
|
169
|
+
|
170
|
+
|
171
|
+
def self.get_results(which, q)
|
172
|
+
@sdb = SimpleRecord::Base.connection
|
173
|
+
next_token = nil
|
174
|
+
ret = []
|
175
|
+
begin
|
176
|
+
begin
|
177
|
+
response = @sdb.select(q, next_token)
|
178
|
+
rs = response[:items]
|
179
|
+
rs.each_with_index do |i, index|
|
180
|
+
puts 'i=' + i.inspect
|
181
|
+
i.each_key do |k|
|
182
|
+
puts 'key=' + k.inspect
|
183
|
+
if which == :first
|
184
|
+
return i[k].update("id"=>k)
|
199
185
|
end
|
200
|
-
|
186
|
+
ret << i[k]
|
187
|
+
end
|
188
|
+
# break if index > 100
|
201
189
|
end
|
202
|
-
|
190
|
+
next_token = response[:next_token]
|
191
|
+
end until next_token.nil?
|
192
|
+
rescue Aws::AwsError, Aws::ActiveSdb::ActiveSdbError
|
193
|
+
if ($!.message().index("NoSuchDomain") != nil)
|
194
|
+
puts 'NO SUCH DOMAIN!!!'
|
195
|
+
# this is ok
|
196
|
+
else
|
197
|
+
raise $!
|
198
|
+
end
|
203
199
|
end
|
200
|
+
which == :first ? nil : ret
|
201
|
+
end
|
202
|
+
|
204
203
|
end
|
204
|
+
end
|
205
205
|
end
|
206
206
|
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 31
|
9
|
+
version: 0.0.31
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Travis Reeder
|
@@ -107,9 +107,9 @@ files:
|
|
107
107
|
- lib/appoxy_rails.rb
|
108
108
|
- lib/appoxy_sessions.rb
|
109
109
|
- lib/appoxy_ui.rb
|
110
|
-
- lib/rails/api_controller.rb
|
111
|
-
- lib/rails/signatures.rb
|
112
110
|
- lib/railtie.rb
|
111
|
+
- lib/server_api/api_controller.rb
|
112
|
+
- lib/server_api/signatures.rb
|
113
113
|
- lib/sessions/application_controller.rb
|
114
114
|
- lib/sessions/oauth_token.rb
|
115
115
|
- lib/sessions/sessions_controller.rb
|
data/lib/rails/signatures.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
module Appoxy
|
2
|
-
module Rails
|
3
|
-
module Signatures
|
4
|
-
|
5
|
-
|
6
|
-
def self.generate_timestamp(gmtime)
|
7
|
-
return gmtime.strftime("%Y-%m-%dT%H:%M:%SZ")
|
8
|
-
end
|
9
|
-
|
10
|
-
|
11
|
-
def self.generate_signature(operation, timestamp, secret_key)
|
12
|
-
my_sha_hmac = Digest::HMAC.digest(operation + timestamp, secret_key, Digest::SHA1)
|
13
|
-
my_b64_hmac_digest = Base64.encode64(my_sha_hmac).strip
|
14
|
-
return my_b64_hmac_digest
|
15
|
-
end
|
16
|
-
|
17
|
-
|
18
|
-
def self.hash_to_s(hash)
|
19
|
-
str = ""
|
20
|
-
hash.sort.each{|a| str+= "#{a[0]}#{a[1]}" }
|
21
|
-
#removing all characters that could differ after parsing with rails
|
22
|
-
return str.delete "\"\/:{}[]\' T"
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|