-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/attached files/backend #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Leenday
wants to merge
2
commits into
feature/sidekiq
Choose a base branch
from
feature/attached_files/backend
base: feature/sidekiq
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| class TaskAttachImageForm | ||
| include ActiveModel::Validations | ||
| include Virtus.model | ||
|
|
||
| attribute :image, ActionDispatch::Http::UploadedFile | ||
| attribute :crop_width, Integer | ||
| attribute :crop_height, Integer | ||
| attribute :crop_x, Integer | ||
| attribute :crop_y, Integer | ||
|
|
||
| with_options numericality: { only_integer: true, greater_than_or_equal_to: 0 } do | ||
| validates :crop_width, if: -> { crop_width.present? } | ||
| validates :crop_height, if: -> { crop_height.present? } | ||
| validates :crop_x, if: -> { crop_x.present? } | ||
| validates :crop_y, if: -> { crop_y.present? } | ||
| end | ||
|
|
||
| validates :image, presence: true, | ||
| file_size: { less_than_or_equal_to: 2.megabytes }, | ||
| file_content_type: { allow: ['image/jpeg', 'image/png'] } | ||
|
|
||
| def processed_image | ||
| ImageProcessingService.crop!(image.path, crop_width, crop_height, crop_x, crop_y) if cropping? | ||
|
|
||
| image | ||
| end | ||
|
|
||
| def cropping? | ||
| [crop_width, crop_height, crop_x, crop_y].all?(&:present?) | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| class TaskSerializer < ApplicationSerializer | ||
| attributes :id, :name, :description, :state, :expired_at, :transitions | ||
| attributes :id, :name, :description, :state, :expired_at, :transitions, :image_url | ||
| belongs_to :author | ||
| belongs_to :assignee | ||
|
|
||
|
|
@@ -12,4 +12,8 @@ def transitions | |
| } | ||
| end | ||
| end | ||
|
|
||
| def image_url | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JFYI если добавляется кастомный атрибут, лучше его объявлять в виде |
||
| object.image.attached? ? AttachmentsService.file_url(object.image) : nil | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| module AttachmentsService | ||
| class << self | ||
| def file_url(file) | ||
| Rails.application.routes.url_helpers.rails_blob_url(file) | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| module ImageProcessingService | ||
| class << self | ||
| def crop!(path_to_image, crop_width, crop_height, crop_x, crop_y) | ||
| image = MiniMagick::Image.new(path_to_image) | ||
| image.crop("#{crop_width}x#{crop_height}+#{crop_x}+#{crop_y}") | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| KKKUi8kqBT8qSJ39419AA3r2cQyQGUZLoJL83tOmIjGs5rfE+eNtghuEkO1s9sJ7wzW3mjdydHuRmcfE1Ic+1eidQZ4H/dwfb3EPJ6Ud8nO4Tn1EqAGrkCcZWEgTPRjIlVs+kmhq4VQcwkVHN0bfGXDoTKP5qCiaqdgjOPfnklaJ2jxeUfq1OoXQbwGgrVYB45b+r5RWOOJT+QwG2ddc1cJ7BzcFgipe9/bmVYdw84o4M5EQPr1FBc3eeqjPkMm0/f79R7iSg8F/ZlwUEBBGInrpGVJRffNJ+JDVDKrEXldf4+Lzhd2Hicvy/8cm6IGBEH/j96ksFw+Nv/hYSZ7bfTp046Pu2eU/Z4d0cz8VPGTC756NYecZaaesyHvLnbhBYWepDW8zASbdRMqcrv5zcoQ/Xhl07piPm1WK--eY0CL0IB0ObUsd/B--r2bkypAoIvjzNdkCloiTkQ== | ||
| B8MkR7d7vVYwQr6sXYNpq5WLcGREgNVIWI2EjR7Sz9xV6Q04s+v/GQZiKfWgOQuFFOuInVQi94I2c/NV35s+9LIbQqt1gEaeZS8JaP6//RrKf2FJXzIs2pxuYEU/G2nkPTkQnHWaBz1ZJPJImq209bCa7wu57p6mrY+zk4wjn/C89eKiGgtFaw1QAYbWSJe6cNHCQEeAsNZR9whIi73eaPdDAIeLU4FFmGo8zsS087H462xPUm+UWCYMY62oWDEAhN9h2yoksj6DtVeQAZwbyclxK9Fo42wFR0V/b1PXaL++Farjr4Pwhhdf7pkXxLAWYmYCiWbQi81catnbYtXu4oLjml++JjPGajvov/k5ceqnq3muHSTk68IALIKhiwCRWs6mugfCU7m+sRaEMhPRwdLPT7ZAQZFzAeaO--3Xv+VSAo81kv6uFz--Gr4WW6P2xyb2D/WnxKmlyw== | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. креды не хранят в открытом доступе |
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
db/migrate/20230112070536_create_active_storage_tables.active_storage.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # This migration comes from active_storage (originally 20170806125915) | ||
| class CreateActiveStorageTables < ActiveRecord::Migration[5.2] | ||
| def change | ||
| create_table :active_storage_blobs do |t| | ||
| t.string :key, null: false | ||
| t.string :filename, null: false | ||
| t.string :content_type | ||
| t.text :metadata | ||
| t.bigint :byte_size, null: false | ||
| t.string :checksum, null: false | ||
| t.datetime :created_at, null: false | ||
|
|
||
| t.index [ :key ], unique: true | ||
| end | ||
|
|
||
| create_table :active_storage_attachments do |t| | ||
| t.string :name, null: false | ||
| t.references :record, null: false, polymorphic: true, index: false | ||
| t.references :blob, null: false | ||
|
|
||
| t.datetime :created_at, null: false | ||
|
|
||
| t.index [ :record_type, :record_id, :name, :blob_id ], name: "index_active_storage_attachments_uniqueness", unique: true | ||
| t.foreign_key :active_storage_blobs, column: :blob_id | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
небезопасно использовать параметры напрямую. нужны strong params