forked from codeforamerica/ohana-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request codeforamerica#43 from fullstacklabs/CS-826
CS-826 Ohana support of image loader
- Loading branch information
Showing
12 changed files
with
183 additions
and
18 deletions.
There are no files selected for viewing
This file contains 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 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 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,30 @@ | ||
module Api | ||
module V1 | ||
class OrgProfileImagesController < Api::V1::BaseController | ||
include ErrorSerializer | ||
|
||
def create | ||
org_id = org_profile_image_params[:organization_id] | ||
image = org_profile_image_params[:image] | ||
@profile_image = OrgProfileImage.find_or_initialize_by(organization_id:org_id) | ||
@profile_image.image = image | ||
if @profile_image.save | ||
render json: {url:@profile_image.image.url}, status: 200 | ||
else | ||
render json: ErrorSerializer.serialize(@profile_image.errors), | ||
status: :unprocessable_entity | ||
end | ||
end | ||
|
||
private | ||
|
||
def org_profile_image_params | ||
params.permit( | ||
:local_identifier, | ||
:image, | ||
:organization_id | ||
) | ||
end | ||
end | ||
end | ||
end |
This file contains 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 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,6 @@ | ||
module OrgRecord | ||
extend ActiveSupport::Concern | ||
included do | ||
scope :from_published_orgs, -> { joins(:organization).where('organizations.is_published = true') } | ||
end | ||
end |
This file contains 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 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,4 @@ | ||
class OrgProfileImage < ActiveRecord::Base | ||
attr_accessible :local_identifier, :remote_url, :organization_id, :image | ||
mount_uploader :image, OrgProfileImageUploader | ||
end |
This file contains 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,48 @@ | ||
class OrgProfileImageUploader < CarrierWave::Uploader::Base | ||
# Include RMagick or MiniMagick support: | ||
# include CarrierWave::RMagick | ||
# include CarrierWave::MiniMagick | ||
|
||
# Choose what kind of storage to use for this uploader: | ||
# storage :file | ||
storage :fog | ||
|
||
# Override the directory where uploaded files will be stored. | ||
# This is a sensible default for uploaders that are meant to be mounted: | ||
def store_dir | ||
# "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" | ||
"org-profile-images" | ||
end | ||
|
||
# Provide a default URL as a default if there hasn't been a file uploaded: | ||
# def default_url(*args) | ||
# # For Rails 3.1+ asset pipeline compatibility: | ||
# # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_')) | ||
# | ||
# "/images/fallback/" + [version_name , "default.png"].compact.join('_') | ||
# end | ||
|
||
# Process files as they are uploaded: | ||
# process scale: [200, 300] | ||
# | ||
# def scale(width, height) | ||
# # do something | ||
# end | ||
|
||
# Create different versions of your uploaded files: | ||
# version :thumb do | ||
# process resize_to_fit: [50, 50] | ||
# end | ||
|
||
# Add a white list of extensions which are allowed to be uploaded. | ||
# For images you might use something like this: | ||
# def extension_whitelist | ||
# %w(jpg jpeg gif png) | ||
# end | ||
|
||
# Override the filename of the uploaded files: | ||
# Avoid using model.id or version_name here, see uploader/store.rb for details. | ||
def filename | ||
SecureRandom.uuid | ||
end | ||
end |
This file contains 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 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,5 @@ | ||
class AddImageToOrganization < ActiveRecord::Migration | ||
def change | ||
add_column :organizations, :image, :string | ||
end | ||
end |
This file contains 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,11 @@ | ||
class CreateOrgProfileImage < ActiveRecord::Migration | ||
def change | ||
create_table :org_profile_images do |t| | ||
t.string :local_identifier | ||
t.string :remote_url | ||
t.integer :organization_id | ||
t.index :organization_id | ||
t.string :image | ||
end | ||
end | ||
end |
This file contains 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