symphonia 3.1.5 → 3.3.0
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/.rubocop.yml +4 -8
- data/CHANGELOG.md +88 -0
- data/app/assets/javascripts/symphonia/symphonia_ckeditor.js +0 -1
- data/app/controllers/symphonia/accounts_controller.rb +0 -1
- data/app/controllers/symphonia/roles_controller.rb +3 -64
- data/app/controllers/symphonia/user_sessions_controller.rb +1 -1
- data/app/controllers/symphonia/users_controller.rb +1 -34
- data/app/helpers/symphonia/application_helper.rb +1 -1
- data/app/helpers/symphonia/form_helper.rb +0 -2
- data/app/models/symphonia/user.rb +2 -25
- data/app/views/symphonia/accounts/_form.html.erb +19 -8
- data/app/views/symphonia/accounts/edit.html.erb +2 -2
- data/app/views/symphonia/users/_form.html.erb +7 -7
- data/app/views/symphonia/users/edit.html.erb +17 -15
- data/app/views/symphonia/users/new.html.erb +2 -2
- data/config/routes.rb +1 -0
- data/db/migrate/20200428180001_add_uuid_to_users.rb +6 -0
- data/db/migrate/20200428180008_add_avatar_to_users.rb +5 -0
- data/db/seeds.rb +2 -1
- data/lib/generators/symphonia/setup/setup_generator.rb +2 -1
- data/lib/generators/symphonia/setup/templates/app/assets/javascripts/application.js.tt +1 -0
- data/lib/symphonia.rb +0 -1
- data/lib/symphonia/action_cable/connection.rb +1 -1
- data/lib/symphonia/admin_constraint.rb +2 -1
- data/lib/symphonia/base_controller.rb +7 -0
- data/lib/symphonia/engine.rb +9 -8
- data/lib/symphonia/model_attributes/attribute.rb +1 -1
- data/lib/symphonia/version.rb +1 -1
- data/spec/controllers/base_controller_spec.rb +37 -2
- data/spec/factories/factories.rb +11 -12
- data/spec/spec_helper.rb +2 -2
- metadata +42 -69
- data/app/controllers/symphonia/api_controller.rb +0 -64
- data/app/controllers/symphonia/attachments_controller.rb +0 -37
- data/app/controllers/symphonia/images_controller.rb +0 -16
- data/app/models/symphonia/attachment.rb +0 -16
- data/app/models/symphonia/common_file.rb +0 -9
- data/app/models/symphonia/image.rb +0 -46
- data/app/models/symphonia/swagger/error_model.rb +0 -19
- data/app/models/symphonia/swagger/responses.rb +0 -27
- data/lib/symphonia/attachable.rb +0 -35
- data/spec/controllers/api_controller_spec.rb +0 -9
- data/spec/controllers/images_controller_spec.rb +0 -5
- data/spec/models/attachment_spec.rb +0 -22
- data/spec/requests/attachments_controller_spec.rb +0 -23
@@ -1,64 +0,0 @@
|
|
1
|
-
module Symphonia
|
2
|
-
class ApiController < ApplicationController
|
3
|
-
include ::Swagger::Blocks
|
4
|
-
# https://github.com/fotinakis/swagger-blocks
|
5
|
-
swagger_root do
|
6
|
-
key :swagger, '2.0'
|
7
|
-
info do
|
8
|
-
key :version, '1.0.0'
|
9
|
-
key :title, 'Symphonia API'
|
10
|
-
key :description, ''
|
11
|
-
# key :termsOfService, 'http://helloreverb.com/terms/'
|
12
|
-
contact do
|
13
|
-
key :name, 'Lukas Pokorny'
|
14
|
-
key :email, 'pokorny@luk4s.cz'
|
15
|
-
end
|
16
|
-
license do
|
17
|
-
key :name, 'GPLv3'
|
18
|
-
end
|
19
|
-
end
|
20
|
-
# tag do
|
21
|
-
# key :name, 'pet'
|
22
|
-
# key :description, 'Pets operations'
|
23
|
-
# externalDocs do
|
24
|
-
# key :description, 'Find more info here'
|
25
|
-
# key :url, 'https://swagger.io'
|
26
|
-
# end
|
27
|
-
# end
|
28
|
-
# key :host, 'petstore.swagger.wordnik.com'
|
29
|
-
key :basePath, '/'
|
30
|
-
key :consumes, ['application/json']
|
31
|
-
key :produces, ['application/json']
|
32
|
-
|
33
|
-
security_definition :token do
|
34
|
-
key :type, :apiKey
|
35
|
-
key :name, :Authorization
|
36
|
-
key :in, :header
|
37
|
-
end
|
38
|
-
security do
|
39
|
-
key :token, []
|
40
|
-
end
|
41
|
-
# security_definition :petstore_auth do
|
42
|
-
# key :type, :oauth2
|
43
|
-
# key :authorizationUrl, 'http://swagger.io/api/oauth/dialog'
|
44
|
-
# key :flow, :implicit
|
45
|
-
# scopes do
|
46
|
-
# key 'write:pets', 'modify pets in your account'
|
47
|
-
# key 'read:pets', 'read your pets'
|
48
|
-
# end
|
49
|
-
# end
|
50
|
-
end
|
51
|
-
|
52
|
-
# A list of all classes that have swagger_* declarations.
|
53
|
-
SWAGGERED_CLASSES = [
|
54
|
-
UsersController,
|
55
|
-
User,
|
56
|
-
Swagger::ErrorModel,
|
57
|
-
self
|
58
|
-
]
|
59
|
-
|
60
|
-
def index
|
61
|
-
render json: ::Swagger::Blocks.build_root_json(SWAGGERED_CLASSES)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
module Symphonia
|
2
|
-
class AttachmentsController < ApplicationController
|
3
|
-
|
4
|
-
before_action :require_login, :find_attachment
|
5
|
-
|
6
|
-
def show
|
7
|
-
# find_attachment
|
8
|
-
render(plain: @attachment.attachment.url(:original), layout: false)
|
9
|
-
end
|
10
|
-
|
11
|
-
def destroy
|
12
|
-
# find_attachment
|
13
|
-
@attachment.destroy
|
14
|
-
respond_to do |format|
|
15
|
-
format.html do
|
16
|
-
flash[:notice] = t(:"text_#{@attachment.type.underscore}_successfully_destroy")
|
17
|
-
redirect_back_or_default(polymorphic_path(@attachment.attachable))
|
18
|
-
end
|
19
|
-
format.js
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def reorder
|
24
|
-
# find_attachment
|
25
|
-
new_position = params.require(:position).to_i
|
26
|
-
@attachment.insert_at(new_position)
|
27
|
-
head :ok
|
28
|
-
end
|
29
|
-
|
30
|
-
private
|
31
|
-
|
32
|
-
def find_attachment
|
33
|
-
@attachment = Attachment.find(params.require(:id))
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
module Symphonia
|
2
|
-
class ImagesController < ApplicationController
|
3
|
-
# before_action :require_login
|
4
|
-
|
5
|
-
# raise '??? images ??'
|
6
|
-
# def index
|
7
|
-
# @images = Image.order(created_at: :asc)
|
8
|
-
# @images = @images.like(params[:q]) if params[:q].present?
|
9
|
-
# @images = @images.page(params[:page])
|
10
|
-
# respond_to do |format|
|
11
|
-
# format.html
|
12
|
-
# format.js
|
13
|
-
# end
|
14
|
-
# end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
require 'acts_as_list'
|
2
|
-
module Symphonia
|
3
|
-
class Attachment < ApplicationRecord
|
4
|
-
self.table_name = 'attachments'
|
5
|
-
|
6
|
-
belongs_to :attachable, polymorphic: true, touch: true, optional: true
|
7
|
-
acts_as_list scope: :attachable
|
8
|
-
|
9
|
-
scope :like, proc {|q| where(arel_table[:description].matches("%#{q}%"))}
|
10
|
-
|
11
|
-
def name
|
12
|
-
attachment_file_name
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
module Symphonia
|
2
|
-
class Image < Attachment
|
3
|
-
|
4
|
-
class_attribute :paperclip_options
|
5
|
-
|
6
|
-
def self.image_styles
|
7
|
-
Symphonia.config[:paperclip_styles] || {
|
8
|
-
tiny_thumb: '120x120>', thumb: '200x200>', medium: '400x300>', large: '800x600>', original: '1280x800>'
|
9
|
-
}
|
10
|
-
end
|
11
|
-
|
12
|
-
has_attached_file(:attachment, {
|
13
|
-
styles: image_styles,
|
14
|
-
url: :paperclip_attachment_url,
|
15
|
-
convert_options: {
|
16
|
-
thumb: '-strip -quality 75',
|
17
|
-
tiny_thumb: '-strip -quality 75',
|
18
|
-
large: '-strip -quality 90'
|
19
|
-
}
|
20
|
-
})
|
21
|
-
|
22
|
-
before_post_process :transliterate_file_name
|
23
|
-
|
24
|
-
validates_attachment :attachment, presence: true, content_type: {
|
25
|
-
content_type: %w(image/jpeg image/jpg image/JPG image/png image/gif)}, size: {in: 0..5.megabytes}
|
26
|
-
|
27
|
-
|
28
|
-
def url(variant = :original)
|
29
|
-
attachment.url(variant)
|
30
|
-
end
|
31
|
-
|
32
|
-
private
|
33
|
-
|
34
|
-
def paperclip_attachment_url
|
35
|
-
paperclip_options.try(:[], :url) || Paperclip::Attachment.default_options[:url]
|
36
|
-
end
|
37
|
-
|
38
|
-
def transliterate_file_name
|
39
|
-
extension = File.extname(attachment_file_name).remove('.')
|
40
|
-
filename = File.basename(attachment_file_name, '.*')
|
41
|
-
self.attachment.instance_write(:file_name, "#{filename.parameterize}.#{extension}")
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module Symphonia
|
2
|
-
module Swagger
|
3
|
-
class ErrorModel
|
4
|
-
include ::Swagger::Blocks
|
5
|
-
|
6
|
-
swagger_schema :ErrorModel do
|
7
|
-
key :required, %i[attribute messages]
|
8
|
-
property :attribute do
|
9
|
-
key :type, :string
|
10
|
-
key :example, "login"
|
11
|
-
end
|
12
|
-
property :messages do
|
13
|
-
key :type, :array
|
14
|
-
key :example, "[cannot be blank]"
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
module Symphonia
|
2
|
-
module Swagger
|
3
|
-
module Responses
|
4
|
-
def self.extended(base)
|
5
|
-
base.response 401 do
|
6
|
-
key :description, 'not authorized'
|
7
|
-
end
|
8
|
-
base.response 404 do
|
9
|
-
key :description, 'not found'
|
10
|
-
end
|
11
|
-
base.response 406 do
|
12
|
-
key :description, 'not allowed'
|
13
|
-
end
|
14
|
-
base.response 422 do
|
15
|
-
key :description, 'unprocessable entity'
|
16
|
-
schema do
|
17
|
-
key :'$ref', :ErrorModel
|
18
|
-
end
|
19
|
-
end
|
20
|
-
base.response 500 do
|
21
|
-
key :description, 'internal server error'
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
27
|
-
end
|
data/lib/symphonia/attachable.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
module Symphonia
|
2
|
-
module Attachable
|
3
|
-
|
4
|
-
extend ActiveSupport::Concern
|
5
|
-
|
6
|
-
included do
|
7
|
-
has_many :images, -> { order(:position) }, as: :attachable, dependent: :destroy, validate: false, class_name: 'Symphonia::Image'
|
8
|
-
has_many :common_files, -> { order(:position) }, as: :attachable, dependent: :destroy, class_name: 'Symphonia::CommonFile'
|
9
|
-
|
10
|
-
# validate do |container|
|
11
|
-
# container.images.each do |img|
|
12
|
-
# next if img.valid?
|
13
|
-
# img.errors.full_messages.each do |msg|
|
14
|
-
# errors.add(:base, "#{img.name}: #{msg}")
|
15
|
-
# end
|
16
|
-
# end
|
17
|
-
# end
|
18
|
-
|
19
|
-
def image_attachments=(form_images=[])
|
20
|
-
form_images.each do |attribute|
|
21
|
-
self.images.build(attachment: attribute)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def file_attachments=(form_files=[])
|
26
|
-
form_files.each do |attribute|
|
27
|
-
self.common_files.build(attachment: attribute)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
describe Symphonia::Attachment do
|
2
|
-
|
3
|
-
context 'files' do
|
4
|
-
let(:file) { FactoryBot.create(:file) }
|
5
|
-
it '#create' do
|
6
|
-
expect { file }.to change(described_class, :count).by 1
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'just create common file' do
|
10
|
-
f = nil
|
11
|
-
expect { f = FactoryBot.create(:file, attachable: nil) }.to change(described_class, :count).by 1
|
12
|
-
expect(f.attachable).to be_nil
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
context 'images' do
|
17
|
-
let(:image) { FactoryBot.create(:image) }
|
18
|
-
it '#create', pending: "When `identify` missing" do
|
19
|
-
expect { image }.to change(described_class, :count).by 1
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
describe Symphonia::AttachmentsController, logged: true do
|
2
|
-
|
3
|
-
let!(:file) { FactoryBot.create(:file) }
|
4
|
-
let(:images) { FactoryBot.create_list(:image, 3, attachable_id: nil, attachable_type: nil) }
|
5
|
-
|
6
|
-
it '#show' do
|
7
|
-
get symphonia.attachment_path(file)
|
8
|
-
expect(response.body).to match file.attachment.url(:original)
|
9
|
-
end
|
10
|
-
|
11
|
-
it '#destroy' do
|
12
|
-
expect{ delete(symphonia.attachment_path(file)) }.to change(Symphonia::Attachment, :count).by -1
|
13
|
-
end
|
14
|
-
|
15
|
-
it '#reorder', pending: "When `identify` missing" do
|
16
|
-
expect { images }.to change(Symphonia::Image, :count).by 3
|
17
|
-
patch symphonia.reorder_attachment_path images.last, 1
|
18
|
-
expect(response).to have_http_status :success
|
19
|
-
imgs = Symphonia::Image.order(:position).to_a
|
20
|
-
expect(imgs.first.id).to be > imgs.last.id
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|