fakecrm 0.9.9.beta1 → 0.9.9.beta2
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.
- checksums.yaml +4 -4
- data/README.md +4 -0
- data/lib/fakecrm/drop.rb +4 -3
- data/lib/fakecrm/fetch.rb +13 -12
- data/lib/fakecrm/resource/activity.rb +31 -1
- data/lib/fakecrm/resource/event_contact.rb +3 -1
- data/lib/fakecrm/server/activities.rb +2 -2
- data/lib/fakecrm/server/contacts.rb +3 -1
- data/lib/fakecrm/tolerant_mass_assignment.rb +38 -0
- data/lib/fakecrm/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 65aeb24a701c44b20fca4abcef97498b39a08efe
|
|
4
|
+
data.tar.gz: 19b687eb4fc99ef916decacadbcd46d52f11ea3b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0f941e7c058c5d2bc5a6fcede4dd857bb7e033060062b2cfc330b4346117d2615ae4685361988832d89a00bdd1b79319f84de125adeb103bedfcb16f6e7cdf34
|
|
7
|
+
data.tar.gz: 0c84d6ddd979e41d29b887bb72c29c663d47b184adae8e60abb53625c7513c17d7ae81ccdd5f9d5ea48491f9c9e5c52cfd7fc5f1e5f08d41c98b45e9454f3bde
|
data/README.md
CHANGED
data/lib/fakecrm/drop.rb
CHANGED
|
@@ -8,7 +8,7 @@ module Fakecrm
|
|
|
8
8
|
instance.attributes = data
|
|
9
9
|
|
|
10
10
|
if instance.save
|
|
11
|
-
response = instance
|
|
11
|
+
response = ResourceView.decorate(instance)
|
|
12
12
|
else
|
|
13
13
|
status 422
|
|
14
14
|
response = instance.errors.to_hash
|
|
@@ -19,7 +19,7 @@ module Fakecrm
|
|
|
19
19
|
rescue ArgumentError => e
|
|
20
20
|
status 422
|
|
21
21
|
::Fakecrm.logger.error("Unable to set unknown attribute: #{e.inspect}")
|
|
22
|
-
{:error => "Unknown attribute"}.to_json
|
|
22
|
+
{:error => "Unknown attribute #{e.inspect}"}.to_json
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
def update_one(resource, primary_key, data)
|
|
@@ -28,6 +28,7 @@ module Fakecrm
|
|
|
28
28
|
instance = resource.get!(primary_key)
|
|
29
29
|
::Fakecrm.logger.debug("Updating resource with: #{data.inspect}")
|
|
30
30
|
instance.attributes = data
|
|
31
|
+
|
|
31
32
|
if instance.save
|
|
32
33
|
response = {}
|
|
33
34
|
else
|
|
@@ -43,7 +44,7 @@ module Fakecrm
|
|
|
43
44
|
rescue ArgumentError => e
|
|
44
45
|
status 422
|
|
45
46
|
::Fakecrm.logger.error("Unable to set unknown attribute: #{e.inspect}")
|
|
46
|
-
{:error => "Unknown attribute"}.to_json
|
|
47
|
+
{:error => "Unknown attribute #{e.inspect}"}.to_json
|
|
47
48
|
end
|
|
48
49
|
|
|
49
50
|
def destroy_one(resource, primary_key)
|
data/lib/fakecrm/fetch.rb
CHANGED
|
@@ -59,20 +59,21 @@ module Fakecrm
|
|
|
59
59
|
|
|
60
60
|
# full text
|
|
61
61
|
if params.key?('q')
|
|
62
|
-
|
|
62
|
+
search_words = params['q'].split(/\s/)
|
|
63
|
+
sub_queries = []
|
|
63
64
|
values = []
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
fields << (" ( " + sub_fields.join(" OR ") + " ) ") unless sub_fields.empty?
|
|
65
|
+
|
|
66
|
+
search_words.each do |search_word|
|
|
67
|
+
sub_query = (full_text_fields + custom_fields).map do |full_text_field|
|
|
68
|
+
values << "%#{search_word}%"
|
|
69
|
+
"(#{full_text_field} LIKE ?)"
|
|
70
|
+
end.join(" OR ")
|
|
71
|
+
|
|
72
|
+
sub_queries << " ( " + sub_query + " ) "
|
|
73
73
|
end
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
|
|
75
|
+
if !sub_queries.empty?
|
|
76
|
+
options[:conditions] = [sub_queries.join(" AND ")] + values
|
|
76
77
|
end
|
|
77
78
|
end
|
|
78
79
|
|
|
@@ -28,7 +28,7 @@ module Fakecrm
|
|
|
28
28
|
property :updated_at, DateTime
|
|
29
29
|
property :deleted_at, ParanoidDateTime
|
|
30
30
|
|
|
31
|
-
property :comments, Json
|
|
31
|
+
property :comments, Json
|
|
32
32
|
|
|
33
33
|
property :updated_by, String, :default => 'root'
|
|
34
34
|
|
|
@@ -52,6 +52,36 @@ module Fakecrm
|
|
|
52
52
|
return true
|
|
53
53
|
end
|
|
54
54
|
|
|
55
|
+
before :save do
|
|
56
|
+
self.comments = [] if self.comments.nil?
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def self.transform_comment_params( params )
|
|
60
|
+
if params["comment_notes"]
|
|
61
|
+
if params["comment_contact_id"]
|
|
62
|
+
contact = Contact.get!( params["comment_contact_id"].to_i )
|
|
63
|
+
else
|
|
64
|
+
contact = Contact.search(:params => {:login => 'root'}).first
|
|
65
|
+
end
|
|
66
|
+
new_comment = {
|
|
67
|
+
:contact_id => contact.id,
|
|
68
|
+
:updated_by => 'root',
|
|
69
|
+
:notes => params["comment_notes"].to_s,
|
|
70
|
+
:published => !!params["comment_published"],
|
|
71
|
+
:updated_at => Time.now
|
|
72
|
+
}
|
|
73
|
+
params["comments"] = (Activity.get!(params["id"].to_i).comments || []) rescue []
|
|
74
|
+
params["comments"] << new_comment
|
|
75
|
+
end
|
|
76
|
+
params.delete("comment_notes")
|
|
77
|
+
params.delete("comment_contact_id")
|
|
78
|
+
params.delete("comment_published")
|
|
79
|
+
|
|
80
|
+
return params
|
|
81
|
+
rescue ::DataMapper::ObjectNotFoundError
|
|
82
|
+
status 404
|
|
83
|
+
end
|
|
84
|
+
|
|
55
85
|
end
|
|
56
86
|
end
|
|
57
87
|
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
|
2
|
+
|
|
3
|
+
require 'fakecrm/tolerant_mass_assignment'
|
|
2
4
|
module Fakecrm
|
|
3
5
|
class EventContact
|
|
4
6
|
include DataMapper::Resource
|
|
7
|
+
include Fakecrm::TolerantMassAssignment
|
|
5
8
|
|
|
6
9
|
property :id, Serial
|
|
7
10
|
property :state, Enum['unregistered', 'registered', 'attended', 'refused', 'noshow'], :required => true
|
|
@@ -15,7 +18,6 @@ module Fakecrm
|
|
|
15
18
|
|
|
16
19
|
belongs_to :event, :required => true
|
|
17
20
|
belongs_to :contact, :required => true
|
|
18
|
-
|
|
19
21
|
end
|
|
20
22
|
end
|
|
21
23
|
|
|
@@ -18,11 +18,11 @@ module Fakecrm
|
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
put '/crm/api/activities/:id.?:format?' do |id, format|
|
|
21
|
-
update_one(Activity, id.to_i, params["activity"])
|
|
21
|
+
update_one(Activity, id.to_i, Activity.transform_comment_params(params["activity"]))
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
post '/crm/api/activities.?:format?' do
|
|
25
|
-
create_one(Activity, params["activity"])
|
|
25
|
+
create_one(Activity, Activity.transform_comment_params(params["activity"]))
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
delete '/crm/api/activities/:id.?:format?' do |id, format|
|
|
@@ -84,7 +84,9 @@ module Fakecrm
|
|
|
84
84
|
end
|
|
85
85
|
|
|
86
86
|
post '/crm/api/contacts.?:format?' do |format|
|
|
87
|
-
|
|
87
|
+
contact = params["contact"]
|
|
88
|
+
contact.delete("title") # workaround for silly connector tests
|
|
89
|
+
create_one(Contact, contact)
|
|
88
90
|
end
|
|
89
91
|
|
|
90
92
|
delete '/crm/api/contacts/:id.?:format?' do |id, format|
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
module Fakecrm
|
|
2
|
+
module TolerantMassAssignment
|
|
3
|
+
# Assign values to multiple attributes in one call (mass assignment)
|
|
4
|
+
#
|
|
5
|
+
# @param [Hash] attributes
|
|
6
|
+
# names and values of attributes to assign
|
|
7
|
+
#
|
|
8
|
+
# @return [Hash]
|
|
9
|
+
# names and values of attributes assigned
|
|
10
|
+
#
|
|
11
|
+
# @note unknown custom_* attributes are ignored with warning
|
|
12
|
+
#
|
|
13
|
+
# @api public
|
|
14
|
+
def attributes=(attributes)
|
|
15
|
+
model = self.model
|
|
16
|
+
attributes.each do |name, value|
|
|
17
|
+
case name
|
|
18
|
+
when String, Symbol
|
|
19
|
+
if model.allowed_writer_methods.include?(setter = "#{name}=")
|
|
20
|
+
__send__(setter, value)
|
|
21
|
+
else
|
|
22
|
+
if name.to_s =~ /^custom_/
|
|
23
|
+
::Fakecrm.logger.error("Ignoring the unknown attribute '#{name}' in #{model}")
|
|
24
|
+
else
|
|
25
|
+
raise ArgumentError, "The attribute '#{name}' is not accessible in #{model}"
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
when Associations::Relationship, Property
|
|
29
|
+
# only call a public #typecast (e.g. on Property instances)
|
|
30
|
+
if name.respond_to?(:typecast)
|
|
31
|
+
value = name.typecast(value)
|
|
32
|
+
end
|
|
33
|
+
self.persistence_state = persistence_state.set(name, value)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
data/lib/fakecrm/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: fakecrm
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.9.9.
|
|
4
|
+
version: 0.9.9.beta2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Mateusz Sojka
|
|
@@ -231,6 +231,7 @@ files:
|
|
|
231
231
|
- lib/fakecrm/server/mailings.rb
|
|
232
232
|
- lib/fakecrm/server/roles.rb
|
|
233
233
|
- lib/fakecrm/server/templates.rb
|
|
234
|
+
- lib/fakecrm/tolerant_mass_assignment.rb
|
|
234
235
|
- lib/fakecrm/version.rb
|
|
235
236
|
- locales/de.yml
|
|
236
237
|
- locales/en.yml
|
|
@@ -299,3 +300,4 @@ test_files:
|
|
|
299
300
|
- test/embedded/lib/tasks/.gitkeep
|
|
300
301
|
- test/embedded/log/.gitkeep
|
|
301
302
|
- test/embedded/script/rails
|
|
303
|
+
has_rdoc:
|