introspective_grape 0.5.5 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/Gemfile +22 -18
- data/README.md +2 -0
- data/introspective_grape.gemspec +5 -4
- data/lib/introspective_grape/api.rb +461 -454
- data/lib/introspective_grape/create_helpers.rb +25 -25
- data/lib/introspective_grape/traversal.rb +1 -1
- data/lib/introspective_grape/validators.rb +36 -34
- data/lib/introspective_grape/version.rb +5 -5
- data/spec/dummy/Gemfile +23 -22
- data/spec/dummy/app/api/api_helpers.rb +38 -37
- data/spec/dummy/app/api/dummy_api.rb +61 -61
- data/spec/dummy/app/api/permissions_helper.rb +7 -7
- data/spec/dummy/app/helpers/current.rb +3 -0
- data/spec/dummy/app/models/chat_message.rb +34 -34
- data/spec/dummy/app/models/chat_user.rb +16 -16
- data/spec/dummy/app/models/location.rb +26 -26
- data/spec/dummy/app/models/role.rb +30 -30
- data/spec/dummy/app/models/team.rb +14 -9
- data/spec/dummy/app/models/user/chatter.rb +79 -79
- data/spec/dummy/bin/bundle +3 -3
- data/spec/dummy/bin/rails +4 -4
- data/spec/dummy/bin/setup +36 -29
- data/spec/dummy/bin/update +31 -0
- data/spec/dummy/bin/yarn +11 -0
- data/spec/dummy/config/application.rb +30 -37
- data/spec/dummy/config/boot.rb +3 -6
- data/spec/dummy/config/environment.rb +5 -11
- data/spec/dummy/config/environments/development.rb +54 -42
- data/spec/dummy/config/environments/production.rb +81 -79
- data/spec/dummy/config/environments/test.rb +47 -44
- data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
- data/spec/dummy/config/initializers/assets.rb +14 -11
- data/spec/dummy/config/initializers/content_security_policy.rb +25 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +5 -3
- data/spec/dummy/config/initializers/inflections.rb +16 -16
- data/spec/dummy/config/initializers/new_framework_defaults_5_2.rb +38 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -14
- data/spec/dummy/config/locales/en.yml +33 -23
- data/spec/dummy/config/storage.yml +34 -0
- data/spec/models/image_spec.rb +10 -14
- data/spec/requests/project_api_spec.rb +185 -182
- data/spec/requests/user_api_spec.rb +221 -221
- data/spec/support/request_helpers.rb +22 -21
- metadata +21 -158
@@ -1,79 +1,79 @@
|
|
1
|
-
module User::Chatter
|
2
|
-
|
3
|
-
def message_query(chat_id, new = true)
|
4
|
-
messages.joins(:chat_message_users)
|
5
|
-
.where('chat_message_users.user_id'=> id)
|
6
|
-
.where(new ? {'chat_message_users.read_at'=>nil} : '')
|
7
|
-
.where(chat_id ? {'chat_messages.chat_id'=> chat_id} : '')
|
8
|
-
.order('') # or it will add an order by id clause that breaks the count query.
|
9
|
-
end
|
10
|
-
|
11
|
-
def new_messages?(chat=nil) # returns a hash of chat_ids with new message counts
|
12
|
-
chat_id = chat.kind_of?(Chat) ? chat.id : chat
|
13
|
-
new = message_query(chat_id)
|
14
|
-
.select("chat_messages.chat_id, count(chat_messages.id) as count")
|
15
|
-
.group('chat_id')
|
16
|
-
|
17
|
-
chat ? { chat_id => new.first.try(:count)||0 } : Hash[new.map {|c| [c.chat_id, c.count]} ]
|
18
|
-
end
|
19
|
-
|
20
|
-
def read_messages(chat= nil, mark_as_read= false, new= true)
|
21
|
-
chat_id = chat.kind_of?(Chat) ? chat.id : chat
|
22
|
-
new = message_query(chat_id, new).order('chat_messages.created_at').includes(:author) # :chat?
|
23
|
-
new.map(&:chat).uniq.each {|c| mark_as_read(c) } if mark_as_read
|
24
|
-
new
|
25
|
-
end
|
26
|
-
|
27
|
-
def chat(users, message)
|
28
|
-
users = [users].flatten
|
29
|
-
users = users.first.kind_of?(User) ? users : User.where(id: users)
|
30
|
-
chat = Chat.create(creator: self)
|
31
|
-
chat.users.push users
|
32
|
-
chat.messages.build(message: message, author: self)
|
33
|
-
chat.save!
|
34
|
-
chat
|
35
|
-
end
|
36
|
-
|
37
|
-
def reply(chat, message)
|
38
|
-
chat = chat.kind_of?(Chat) ? chat : Chat.find(chat)
|
39
|
-
mark_as_read(chat) # a reply implies that the thread has been read
|
40
|
-
chat.messages.build(message: message, author: self)
|
41
|
-
chat.save!
|
42
|
-
chat
|
43
|
-
end
|
44
|
-
|
45
|
-
def add_chatters(chat, users)
|
46
|
-
users = [users].flatten
|
47
|
-
users = users.first.kind_of?(User) ? users : User.where(id: users)
|
48
|
-
chat = chat.kind_of?(Chat) ? chat : Chat.find(chat)
|
49
|
-
|
50
|
-
if chat.active_users.include?(self) # only current participants can add new users
|
51
|
-
chat.users.push users
|
52
|
-
chat.messages.build(chat: chat, author: self, message: "#{self.name} [[ADDED_USER_MESSAGE]] #{users.map(&:name).join(',')}")
|
53
|
-
chat.save!
|
54
|
-
else
|
55
|
-
chat.errors
|
56
|
-
raise ActiveRecord::RecordInvalid.new(chat)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def leave_chat(chat)
|
61
|
-
chat = chat.kind_of?(Chat) ? chat : Chat.find(chat)
|
62
|
-
|
63
|
-
if chat.active_users.include?(self)
|
64
|
-
reply(chat, "#{name} [[DEPARTS_MESSAGE]]")
|
65
|
-
chat.chat_users.detect {|cu| cu.user_id == self.id}.
|
66
|
-
else
|
67
|
-
true
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def mark_as_read(chat)
|
72
|
-
ChatMessageUser.joins(:chat_message).where('read_at IS NULL AND chat_messages.chat_id = ? AND user_id = ?', chat.id, id).update_all(read_at: Time.now)
|
73
|
-
end
|
74
|
-
|
75
|
-
def mark_messages_as_read(messages)
|
76
|
-
chat_message_users.where("chat_message_id in (?) and read_at IS NULL", messages.map(&:id)).update_all(read_at: Time.now)
|
77
|
-
end
|
78
|
-
|
79
|
-
end
|
1
|
+
module User::Chatter
|
2
|
+
|
3
|
+
def message_query(chat_id, new = true)
|
4
|
+
messages.joins(:chat_message_users)
|
5
|
+
.where('chat_message_users.user_id'=> id)
|
6
|
+
.where(new ? {'chat_message_users.read_at'=>nil} : '')
|
7
|
+
.where(chat_id ? {'chat_messages.chat_id'=> chat_id} : '')
|
8
|
+
.order('') # or it will add an order by id clause that breaks the count query.
|
9
|
+
end
|
10
|
+
|
11
|
+
def new_messages?(chat=nil) # returns a hash of chat_ids with new message counts
|
12
|
+
chat_id = chat.kind_of?(Chat) ? chat.id : chat
|
13
|
+
new = message_query(chat_id)
|
14
|
+
.select("chat_messages.chat_id, count(chat_messages.id) as count")
|
15
|
+
.group('chat_id')
|
16
|
+
|
17
|
+
chat ? { chat_id => new.first.try(:count)||0 } : Hash[new.map {|c| [c.chat_id, c.count]} ]
|
18
|
+
end
|
19
|
+
|
20
|
+
def read_messages(chat= nil, mark_as_read= false, new= true)
|
21
|
+
chat_id = chat.kind_of?(Chat) ? chat.id : chat
|
22
|
+
new = message_query(chat_id, new).order('chat_messages.created_at').includes(:author) # :chat?
|
23
|
+
new.map(&:chat).uniq.each {|c| mark_as_read(c) } if mark_as_read
|
24
|
+
new
|
25
|
+
end
|
26
|
+
|
27
|
+
def chat(users, message)
|
28
|
+
users = [users].flatten
|
29
|
+
users = users.first.kind_of?(User) ? users : User.where(id: users)
|
30
|
+
chat = Chat.create(creator: self)
|
31
|
+
chat.users.push users
|
32
|
+
chat.messages.build(message: message, author: self)
|
33
|
+
chat.save!
|
34
|
+
chat
|
35
|
+
end
|
36
|
+
|
37
|
+
def reply(chat, message)
|
38
|
+
chat = chat.kind_of?(Chat) ? chat : Chat.find(chat)
|
39
|
+
mark_as_read(chat) # a reply implies that the thread has been read
|
40
|
+
chat.messages.build(message: message, author: self)
|
41
|
+
chat.save!
|
42
|
+
chat
|
43
|
+
end
|
44
|
+
|
45
|
+
def add_chatters(chat, users)
|
46
|
+
users = [users].flatten
|
47
|
+
users = users.first.kind_of?(User) ? users : User.where(id: users)
|
48
|
+
chat = chat.kind_of?(Chat) ? chat : Chat.find(chat)
|
49
|
+
|
50
|
+
if chat.active_users.include?(self) # only current participants can add new users
|
51
|
+
chat.users.push users
|
52
|
+
chat.messages.build(chat: chat, author: self, message: "#{self.name} [[ADDED_USER_MESSAGE]] #{users.map(&:name).join(',')}")
|
53
|
+
chat.save!
|
54
|
+
else
|
55
|
+
chat.errors.add(:base, "Only current chat participants can add users.")
|
56
|
+
raise ActiveRecord::RecordInvalid.new(chat)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def leave_chat(chat)
|
61
|
+
chat = chat.kind_of?(Chat) ? chat : Chat.find(chat)
|
62
|
+
|
63
|
+
if chat.active_users.include?(self)
|
64
|
+
reply(chat, "#{name} [[DEPARTS_MESSAGE]]")
|
65
|
+
chat.chat_users.detect {|cu| cu.user_id == self.id}.update(departed_at: Time.now)
|
66
|
+
else
|
67
|
+
true
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def mark_as_read(chat)
|
72
|
+
ChatMessageUser.joins(:chat_message).where('read_at IS NULL AND chat_messages.chat_id = ? AND user_id = ?', chat.id, id).update_all(read_at: Time.now)
|
73
|
+
end
|
74
|
+
|
75
|
+
def mark_messages_as_read(messages)
|
76
|
+
chat_message_users.where("chat_message_id in (?) and read_at IS NULL", messages.map(&:id)).update_all(read_at: Time.now)
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
data/spec/dummy/bin/bundle
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('
|
3
|
-
load Gem.bin_path('bundler', 'bundle')
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
|
3
|
+
load Gem.bin_path('bundler', 'bundle')
|
data/spec/dummy/bin/rails
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
APP_PATH = File.expand_path('
|
3
|
-
require_relative '../config/boot'
|
4
|
-
require 'rails/commands'
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_PATH = File.expand_path('../config/application', __dir__)
|
3
|
+
require_relative '../config/boot'
|
4
|
+
require 'rails/commands'
|
data/spec/dummy/bin/setup
CHANGED
@@ -1,29 +1,36 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require '
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
system
|
22
|
-
|
23
|
-
puts "\n==
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'fileutils'
|
3
|
+
include FileUtils
|
4
|
+
|
5
|
+
# path to your application root.
|
6
|
+
APP_ROOT = File.expand_path('..', __dir__)
|
7
|
+
|
8
|
+
def system!(*args)
|
9
|
+
system(*args) || abort("\n== Command #{args} failed ==")
|
10
|
+
end
|
11
|
+
|
12
|
+
chdir APP_ROOT do
|
13
|
+
# This script is a starting point to setup your application.
|
14
|
+
# Add necessary setup steps to this file.
|
15
|
+
|
16
|
+
puts '== Installing dependencies =='
|
17
|
+
system! 'gem install bundler --conservative'
|
18
|
+
system('bundle check') || system!('bundle install')
|
19
|
+
|
20
|
+
# Install JavaScript dependencies if using Yarn
|
21
|
+
# system('bin/yarn')
|
22
|
+
|
23
|
+
# puts "\n== Copying sample files =="
|
24
|
+
# unless File.exist?('config/database.yml')
|
25
|
+
# cp 'config/database.yml.sample', 'config/database.yml'
|
26
|
+
# end
|
27
|
+
|
28
|
+
puts "\n== Preparing database =="
|
29
|
+
system! 'bin/rails db:setup'
|
30
|
+
|
31
|
+
puts "\n== Removing old logs and tempfiles =="
|
32
|
+
system! 'bin/rails log:clear tmp:clear'
|
33
|
+
|
34
|
+
puts "\n== Restarting application server =="
|
35
|
+
system! 'bin/rails restart'
|
36
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'fileutils'
|
3
|
+
include FileUtils
|
4
|
+
|
5
|
+
# path to your application root.
|
6
|
+
APP_ROOT = File.expand_path('..', __dir__)
|
7
|
+
|
8
|
+
def system!(*args)
|
9
|
+
system(*args) || abort("\n== Command #{args} failed ==")
|
10
|
+
end
|
11
|
+
|
12
|
+
chdir APP_ROOT do
|
13
|
+
# This script is a way to update your development environment automatically.
|
14
|
+
# Add necessary update steps to this file.
|
15
|
+
|
16
|
+
puts '== Installing dependencies =='
|
17
|
+
system! 'gem install bundler --conservative'
|
18
|
+
system('bundle check') || system!('bundle install')
|
19
|
+
|
20
|
+
# Install JavaScript dependencies if using Yarn
|
21
|
+
# system('bin/yarn')
|
22
|
+
|
23
|
+
puts "\n== Updating database =="
|
24
|
+
system! 'bin/rails db:migrate'
|
25
|
+
|
26
|
+
puts "\n== Removing old logs and tempfiles =="
|
27
|
+
system! 'bin/rails log:clear tmp:clear'
|
28
|
+
|
29
|
+
puts "\n== Restarting application server =="
|
30
|
+
system! 'bin/rails restart'
|
31
|
+
end
|
data/spec/dummy/bin/yarn
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path('..', __dir__)
|
3
|
+
Dir.chdir(APP_ROOT) do
|
4
|
+
begin
|
5
|
+
exec "yarnpkg", *ARGV
|
6
|
+
rescue Errno::ENOENT
|
7
|
+
$stderr.puts "Yarn executable was not detected in the system."
|
8
|
+
$stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install"
|
9
|
+
exit 1
|
10
|
+
end
|
11
|
+
end
|
@@ -1,37 +1,30 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
require "
|
6
|
-
require "
|
7
|
-
require "
|
8
|
-
require "
|
9
|
-
require
|
10
|
-
|
11
|
-
require
|
12
|
-
require
|
13
|
-
# require "
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
#
|
23
|
-
#
|
24
|
-
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
# config.i18n.default_locale = :de
|
32
|
-
|
33
|
-
# Do not swallow errors in after_commit/after_rollback callbacks.
|
34
|
-
#config.active_record.raise_in_transactional_callbacks = true
|
35
|
-
|
36
|
-
end
|
37
|
-
end
|
1
|
+
require_relative 'boot'
|
2
|
+
|
3
|
+
require "rails"
|
4
|
+
# Pick the frameworks you want:
|
5
|
+
require "active_model/railtie"
|
6
|
+
require "active_job/railtie"
|
7
|
+
require "active_record/railtie"
|
8
|
+
require "active_storage/engine"
|
9
|
+
require "action_controller/railtie"
|
10
|
+
require "action_mailer/railtie"
|
11
|
+
require "action_view/railtie"
|
12
|
+
# require "action_cable/engine"
|
13
|
+
# require "sprockets/railtie"
|
14
|
+
require "rails/test_unit/railtie"
|
15
|
+
|
16
|
+
# Require the gems listed in Gemfile, including any gems
|
17
|
+
# you've limited to :test, :development, or :production.
|
18
|
+
Bundler.require(*Rails.groups)
|
19
|
+
|
20
|
+
module Dummy
|
21
|
+
class Application < Rails::Application
|
22
|
+
# Initialize configuration defaults for originally generated Rails version.
|
23
|
+
#config.load_defaults 7.0
|
24
|
+
|
25
|
+
# Settings in config/environments/* take precedence over those specified here.
|
26
|
+
# Application configuration can go into files in config/initializers
|
27
|
+
# -- all .rb files in that directory are automatically loaded after loading
|
28
|
+
# the framework and any gems in your application.
|
29
|
+
end
|
30
|
+
end
|
data/spec/dummy/config/boot.rb
CHANGED
@@ -1,6 +1,3 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
|
5
|
-
$LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)
|
6
|
-
|
1
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
|
2
|
+
|
3
|
+
require 'bundler/setup' # Set up gems listed in the Gemfile.
|
@@ -1,11 +1,5 @@
|
|
1
|
-
# Load the Rails application.
|
2
|
-
|
3
|
-
|
4
|
-
# Initialize the Rails application.
|
5
|
-
Rails.application.initialize!
|
6
|
-
#load "#{Rails.root}/db/schema.rb"
|
7
|
-
|
8
|
-
|
9
|
-
#Dir[Rails.root.join("app/api/**/*.rb")].each { |f| require f }
|
10
|
-
Rails.application.reload_routes!
|
11
|
-
|
1
|
+
# Load the Rails application.
|
2
|
+
require_relative 'application'
|
3
|
+
|
4
|
+
# Initialize the Rails application.
|
5
|
+
Rails.application.initialize!
|
@@ -1,42 +1,54 @@
|
|
1
|
-
Rails.application.configure do
|
2
|
-
# Settings specified here will take precedence over those in config/application.rb.
|
3
|
-
|
4
|
-
# In the development environment your application's code is reloaded on
|
5
|
-
# every request. This slows down response time but is perfect for development
|
6
|
-
# since you don't have to restart the web server when you make code changes.
|
7
|
-
config.cache_classes = false
|
8
|
-
|
9
|
-
# Do not eager load code on boot.
|
10
|
-
config.eager_load = false
|
11
|
-
|
12
|
-
# Show full error reports
|
13
|
-
config.consider_all_requests_local
|
14
|
-
|
15
|
-
|
16
|
-
#
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
#
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
#
|
39
|
-
|
40
|
-
|
41
|
-
#
|
42
|
-
|
1
|
+
Rails.application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb.
|
3
|
+
|
4
|
+
# In the development environment your application's code is reloaded on
|
5
|
+
# every request. This slows down response time but is perfect for development
|
6
|
+
# since you don't have to restart the web server when you make code changes.
|
7
|
+
config.cache_classes = false
|
8
|
+
|
9
|
+
# Do not eager load code on boot.
|
10
|
+
config.eager_load = false
|
11
|
+
|
12
|
+
# Show full error reports.
|
13
|
+
config.consider_all_requests_local = true
|
14
|
+
|
15
|
+
# Enable/disable caching. By default caching is disabled.
|
16
|
+
# Run rails dev:cache to toggle caching.
|
17
|
+
if Rails.root.join('tmp', 'caching-dev.txt').exist?
|
18
|
+
config.action_controller.perform_caching = true
|
19
|
+
|
20
|
+
config.cache_store = :memory_store
|
21
|
+
config.public_file_server.headers = {
|
22
|
+
'Cache-Control' => "public, max-age=#{2.days.to_i}"
|
23
|
+
}
|
24
|
+
else
|
25
|
+
config.action_controller.perform_caching = false
|
26
|
+
|
27
|
+
config.cache_store = :null_store
|
28
|
+
end
|
29
|
+
|
30
|
+
# Store uploaded files on the local file system (see config/storage.yml for options)
|
31
|
+
config.active_storage.service = :local
|
32
|
+
|
33
|
+
# Don't care if the mailer can't send.
|
34
|
+
config.action_mailer.raise_delivery_errors = false
|
35
|
+
config.action_mailer.default_url_options = { :host => "yourhost.com" }
|
36
|
+
config.action_mailer.perform_caching = false
|
37
|
+
|
38
|
+
# Print deprecation notices to the Rails logger.
|
39
|
+
config.active_support.deprecation = :log
|
40
|
+
|
41
|
+
# Raise an error on page load if there are pending migrations.
|
42
|
+
config.active_record.migration_error = :page_load
|
43
|
+
|
44
|
+
# Highlight code that triggered database queries in logs.
|
45
|
+
config.active_record.verbose_query_logs = true
|
46
|
+
|
47
|
+
|
48
|
+
# Raises error for missing translations
|
49
|
+
# config.action_view.raise_on_missing_translations = true
|
50
|
+
|
51
|
+
# Use an evented file watcher to asynchronously detect changes in source code,
|
52
|
+
# routes, locales, etc. This feature depends on the listen gem.
|
53
|
+
config.file_watcher = ActiveSupport::EventedFileUpdateChecker
|
54
|
+
end
|