mirror of
https://github.com/publiclab/mapknitter.git
synced 2025-12-05 16:00:00 +01:00
* Try migrating from Travis to GitHub Actions for CI * Update actions.yml and tests.yml * Add ruby version * Update config/database.yml.example * Try rubocop and docker jobs * Fix indentation * Update tests.yml * Update tests.yml * Update gemfile * Update rubocop job and Gemfile * Update .rubocop_shopify_styleguide.yml * Update gemfile * Update .rubocop_todo.yml * Update rubocop configuration and styleguides * Fix rubocop offenses * Update .rubocop.yml * Update .rubocop.yml * Udate .codeclimate.yml * Update .codeclimate.yml * Update .codeclimate.yml * Update .codeclimate.yml * Setup unit tests * Update find_verified_user method in connection.rb * Add yarn cache and install to setup * install exporter dependencies; gdal/imagemagick * Introduce Gitpod to migration work (#1538) * Add CORS headers (#1536) * Create .gitpod.dockerfile * Create .gitpod.yml * Create database.yml.gitpod * Update .gitpod.yml * ruby 2.4.6 in gitpod.dockerfile * Update .gitpod.yml * Update database.yml.gitpod Co-authored-by: Sebastian Silva <sebastian@fuentelibre.org> Co-authored-by: Jeffrey Warren <jeff@unterbahn.com> * Install gdal and use egordm for yarn cache * Delete unnecessary query and fix layout * Run script with verbose output * Try installing package in action.yml * Setup controllers job * Fix indentation * Setup system tests job * Setup docker development build job * Fix identifiers * Fix path to action.yml * Update development dockerfile * Setup docker production build job * Update tests.yml * Setup assets precompilation job * Setup production environment * Update tests.yml * Update action.yml for production * Try with test setup * Remove action.yml for production * Change names of jobs for friendliness and clarity * Update .github/workflows/tests.yml Co-authored-by: Jeffrey Warren <jeff@unterbahn.com> * Move dockerfiles to directory and change docker job names for clarity * Update docker job names Co-authored-by: Jeffrey Warren <jeff@unterbahn.com> Co-authored-by: Sebastian Silva <sebastian@fuentelibre.org>
130 lines
4.1 KiB
Ruby
130 lines
4.1 KiB
Ruby
require 'open-uri'
|
|
class ImagesController < ApplicationController
|
|
rescue_from Errno::ENOENT, Errno::ETIMEDOUT,
|
|
OpenURI::HTTPError, Timeout::Error,
|
|
with: :url_upload_not_found
|
|
protect_from_forgery except: %i(update delete)
|
|
# Convert model to json without including root name. Eg. 'warpable'
|
|
ActiveRecord::Base.include_root_in_json = false
|
|
|
|
# proxy, used if MapKnitter is being backed by Amazon S3 file storage,
|
|
# to enable client-side distortion using webgl-distort, which requires same-origin
|
|
def fetch
|
|
if Rails.env.production?
|
|
if params[:url][0..42] == 'https://s3.amazonaws.com/grassrootsmapping/'
|
|
url = URI.parse(params[:url])
|
|
result = Net::HTTP.get_response(url)
|
|
send_data(result.body, type: result.content_type, disposition: 'inline')
|
|
end
|
|
else
|
|
redirect_to(params[:url])
|
|
end
|
|
end
|
|
|
|
# assign attributes directly after rails update
|
|
def create
|
|
@warpable = Warpable.new
|
|
@warpable.history = 'None'
|
|
@warpable.image = params[:uploaded_data]
|
|
map = Map.find_by(slug: params[:map_id])
|
|
@warpable.map_id = map.id
|
|
map.updated_at = Time.now
|
|
map.save
|
|
respond_to do |format|
|
|
if @warpable.save
|
|
format.html { render(json: [@warpable.fup_json].to_json, content_type: 'text/html') }
|
|
format.json { render(json: { files: [@warpable.fup_json] }, status: :created, location: @warpable.image.url) }
|
|
else
|
|
format.html { render(action: 'new') }
|
|
format.json { render(json: { files: [@warpable.fup_error_json] }, layout: false) }
|
|
end
|
|
end
|
|
end
|
|
|
|
# mapknitter.org/import/<map-name>/?url=http://myurl.com/image.jpg
|
|
def import
|
|
map = Map.find_by_name(params[:name])
|
|
@warpable = Warpable.new
|
|
@warpable.map_id = map.id
|
|
@warpable.url = params[:url]
|
|
map.updated_at = Time.now
|
|
map.save
|
|
if @warpable.save
|
|
redirect_to('/maps/' + params[:name])
|
|
else
|
|
flash[:notice] = 'Sorry, the image failed to import.'
|
|
redirect_to('/map/edit/' + params[:name])
|
|
end
|
|
end
|
|
|
|
def url_upload_not_found
|
|
flash[:notice] = 'Sorry, the URL you provided was not valid.'
|
|
redirect_to('/map/edit/' + params[:id])
|
|
end
|
|
|
|
def show
|
|
@image = Warpable.find(params[:id])
|
|
respond_to do |format|
|
|
format.html
|
|
format.json { render(json: @image.map(&:fup_json)) }
|
|
end
|
|
end
|
|
|
|
def update
|
|
@warpable = Warpable.find(params[:warpable_id])
|
|
|
|
if Map.find(@warpable.map_id).anonymous? || logged_in?
|
|
nodes = []
|
|
author = @warpable.map.author
|
|
# is it really necessary to make new points each time?
|
|
params[:points].split(':').each do |point|
|
|
lon = point.split(',')[0]
|
|
lat = point.split(',')[1]
|
|
node = Node.new(color: 'black',
|
|
lat: lat,
|
|
lon: lon,
|
|
author: author,
|
|
name: '')
|
|
node.save
|
|
nodes << node
|
|
end
|
|
@warpable.nodes = nodes.collect(&:id).join(',')
|
|
@warpable.locked = params[:locked]
|
|
@warpable.cm_per_pixel = @warpable.get_cm_per_pixel
|
|
@warpable.save
|
|
|
|
respond_to do |format|
|
|
format.html { render(html: 'success') }
|
|
format.json { render(json: @warpable.map.fetch_map_data) }
|
|
end
|
|
else
|
|
render(plain: 'You must be logged in to update the image, unless the map is anonymous.')
|
|
end
|
|
end
|
|
|
|
def revert
|
|
@warpable = Warpable.find(params[:id])
|
|
version = @warpable.versions.find(params[:version])
|
|
version.reify&.save
|
|
redirect_to(@warpable.map)
|
|
end
|
|
|
|
def destroy
|
|
@warpable = Warpable.find(params[:id])
|
|
if (logged_in? && current_user.can_edit?(@warpable.map)) || @warpable.map.anonymous?
|
|
@warpable.destroy
|
|
respond_to do |format|
|
|
format.html { render(html: { notice: 'Image was successfully destroyed.' }) }
|
|
format.json { render(json: @warpable) }
|
|
end
|
|
else
|
|
respond_to do |format|
|
|
msg = "You do not have privileges to delete this image"
|
|
flash[:notice] = msg
|
|
format.html { redirect_to(@warpable.map) }
|
|
format.json { render(json: msg, status: 401) }
|
|
end
|
|
end
|
|
end
|
|
end
|