Merge branch 'master' into patch/view_migration
This commit is contained in:
commit
11cc4a5e60
455 changed files with 157626 additions and 118449 deletions
|
@ -114,18 +114,18 @@ module Api
|
|||
|
||||
def amf_handle_error(call, rootobj, rootid)
|
||||
yield
|
||||
rescue OSM::APIAlreadyDeletedError => ex
|
||||
[-4, ex.object, ex.object_id]
|
||||
rescue OSM::APIVersionMismatchError => ex
|
||||
[-3, [rootobj, rootid], [ex.type.downcase, ex.id, ex.latest]]
|
||||
rescue OSM::APIUserChangesetMismatchError => ex
|
||||
[-2, ex.to_s]
|
||||
rescue OSM::APIBadBoundingBox => ex
|
||||
[-2, "Sorry - I can't get the map for that area. The server said: #{ex}"]
|
||||
rescue OSM::APIError => ex
|
||||
[-1, ex.to_s]
|
||||
rescue StandardError => ex
|
||||
[-2, "An unusual error happened (in #{call}). The server said: #{ex}"]
|
||||
rescue OSM::APIAlreadyDeletedError => e
|
||||
[-4, e.object, e.object_id]
|
||||
rescue OSM::APIVersionMismatchError => e
|
||||
[-3, [rootobj, rootid], [e.type.downcase, e.id, e.latest]]
|
||||
rescue OSM::APIUserChangesetMismatchError => e
|
||||
[-2, e.to_s]
|
||||
rescue OSM::APIBadBoundingBox => e
|
||||
[-2, "Sorry - I can't get the map for that area. The server said: #{e}"]
|
||||
rescue OSM::APIError => e
|
||||
[-1, e.to_s]
|
||||
rescue StandardError => e
|
||||
[-2, "An unusual error happened (in #{call}). The server said: #{e}"]
|
||||
end
|
||||
|
||||
def amf_handle_error_with_timeout(call, rootobj, rootid)
|
||||
|
|
|
@ -364,10 +364,10 @@ module Api
|
|||
end
|
||||
# stupid Time seems to throw both of these for bad parsing, so
|
||||
# we have to catch both and ensure the correct code path is taken.
|
||||
rescue ArgumentError => ex
|
||||
raise OSM::APIBadUserInput, ex.message.to_s
|
||||
rescue RuntimeError => ex
|
||||
raise OSM::APIBadUserInput, ex.message.to_s
|
||||
rescue ArgumentError => e
|
||||
raise OSM::APIBadUserInput, e.message.to_s
|
||||
rescue RuntimeError => e
|
||||
raise OSM::APIBadUserInput, e.message.to_s
|
||||
end
|
||||
|
||||
##
|
||||
|
|
|
@ -22,8 +22,8 @@ module Api
|
|||
@bounds = BoundingBox.from_bbox_params(params)
|
||||
@bounds.check_boundaries
|
||||
@bounds.check_size
|
||||
rescue StandardError => err
|
||||
report_error(err.message)
|
||||
rescue StandardError => e
|
||||
report_error(e.message)
|
||||
return
|
||||
end
|
||||
|
||||
|
|
|
@ -1,218 +0,0 @@
|
|||
module Api
|
||||
class SwfController < ApiController
|
||||
before_action :check_api_readable
|
||||
authorize_resource :class => false
|
||||
|
||||
# to log:
|
||||
# RAILS_DEFAULT_LOGGER.error("Args: #{args[0]}, #{args[1]}, #{args[2]}, #{args[3]}")
|
||||
# $log.puts Time.new.to_s+','+Time.new.usec.to_s+": started GPS script"
|
||||
# http://localhost:3000/api/0.4/swf/trackpoints?xmin=-2.32402605810577&xmax=-2.18386309423859&ymin=52.1546608755772&ymax=52.2272777906895&baselong=-2.25325793066437&basey=61.3948537948532&masterscale=5825.4222222222
|
||||
|
||||
# ====================================================================
|
||||
# Public methods
|
||||
|
||||
# ---- trackpoints compile SWF of trackpoints
|
||||
|
||||
def trackpoints
|
||||
# - Initialise
|
||||
|
||||
baselong = params["baselong"].to_f
|
||||
basey = params["basey"].to_f
|
||||
masterscale = params["masterscale"].to_f
|
||||
|
||||
bbox = BoundingBox.new(params["xmin"], params["ymin"],
|
||||
params["xmax"], params["ymax"])
|
||||
start = params["start"].to_i
|
||||
|
||||
# - Begin movie
|
||||
|
||||
bounds_left = 0
|
||||
bounds_right = 320 * 20
|
||||
bounds_bottom = 0
|
||||
bounds_top = 240 * 20
|
||||
|
||||
m = ""
|
||||
m += swf_record(9, 255.chr + 155.chr + 155.chr) # Background
|
||||
absx = 0
|
||||
absy = 0
|
||||
xl = yb = 9999999
|
||||
xr = yt = -9999999
|
||||
|
||||
# - Send SQL for GPS tracks
|
||||
|
||||
b = ""
|
||||
lasttime = 0
|
||||
lasttrack = lastfile = "-1"
|
||||
|
||||
if params["token"]
|
||||
user = User.authenticate(:token => params[:token])
|
||||
sql = "SELECT gps_points.latitude*0.0000001 AS lat,gps_points.longitude*0.0000001 AS lon,gpx_files.id AS fileid," + " EXTRACT(EPOCH FROM gps_points.timestamp) AS ts, gps_points.trackid AS trackid " + " FROM gpx_files,gps_points " + "WHERE gpx_files.id=gpx_id " + " AND gpx_files.user_id=#{user.id} " + " AND " + OSM.sql_for_area(bbox, "gps_points.") + " AND (gps_points.timestamp IS NOT NULL) " + "ORDER BY fileid DESC,ts " + "LIMIT 10000 OFFSET #{start}"
|
||||
else
|
||||
sql = "SELECT latitude*0.0000001 AS lat,longitude*0.0000001 AS lon,gpx_id AS fileid," + " EXTRACT(EPOCH FROM timestamp) AS ts, gps_points.trackid AS trackid " + " FROM gps_points " + "WHERE " + OSM.sql_for_area(bbox, "gps_points.") + " AND (gps_points.timestamp IS NOT NULL) " + "ORDER BY fileid DESC,ts " + "LIMIT 10000 OFFSET #{start}"
|
||||
end
|
||||
gpslist = ActiveRecord::Base.connection.select_all sql
|
||||
|
||||
# - Draw GPS trace lines
|
||||
|
||||
r = start_shape
|
||||
gpslist.each do |row|
|
||||
xs = (long2coord(row["lon"].to_f, baselong, masterscale) * 20).floor
|
||||
ys = (lat2coord(row["lat"].to_f, basey, masterscale) * 20).floor
|
||||
xl = [xs, xl].min
|
||||
xr = [xs, xr].max
|
||||
yb = [ys, yb].min
|
||||
yt = [ys, yt].max
|
||||
if row["ts"].to_i - lasttime > 180 || row["fileid"] != lastfile || row["trackid"] != lasttrack # or row['ts'].to_i==lasttime
|
||||
b += start_and_move(xs, ys, "01")
|
||||
absx = xs.floor
|
||||
absy = ys.floor
|
||||
end
|
||||
b += draw_to(absx, absy, xs, ys)
|
||||
absx = xs.floor
|
||||
absy = ys.floor
|
||||
lasttime = row["ts"].to_i
|
||||
lastfile = row["fileid"]
|
||||
lasttrack = row["trackid"]
|
||||
r += [b.slice!(0...80)].pack("B*") while b.length > 80
|
||||
end
|
||||
|
||||
# (Unwayed segments removed)
|
||||
|
||||
# - Write shape
|
||||
|
||||
b += end_shape
|
||||
r += [b].pack("B*")
|
||||
m += swf_record(2, pack_u16(1) + pack_rect(xl, xr, yb, yt) + r)
|
||||
m += swf_record(4, pack_u16(1) + pack_u16(1))
|
||||
|
||||
# - Create Flash header and write to browser
|
||||
|
||||
m += swf_record(1, "") # Show frame
|
||||
m += swf_record(0, "") # End
|
||||
|
||||
m = pack_rect(bounds_left, bounds_right, bounds_bottom, bounds_top) + 0.chr + 12.chr + pack_u16(1) + m
|
||||
m = "FWS" + 6.chr + pack_u32(m.length + 8) + m
|
||||
|
||||
render :body => m, :content_type => "application/x-shockwave-flash"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# =======================================================================
|
||||
# SWF functions
|
||||
|
||||
# -----------------------------------------------------------------------
|
||||
# Line-drawing
|
||||
|
||||
def start_shape
|
||||
s = 0.chr # No fill styles
|
||||
s += 2.chr # Two line styles
|
||||
s += pack_u16(0) + 0.chr + 255.chr + 255.chr # Width 5, RGB #00FFFF
|
||||
s += pack_u16(0) + 255.chr + 0.chr + 255.chr # Width 5, RGB #FF00FF
|
||||
s += 34.chr # 2 fill, 2 line index bits
|
||||
s
|
||||
end
|
||||
|
||||
def end_shape
|
||||
"000000"
|
||||
end
|
||||
|
||||
def start_and_move(x, y, col)
|
||||
d = "001001" # Line style change, moveTo
|
||||
l = [length_sb(x), length_sb(y)].max
|
||||
d += format("%05b%0*b%0*b", l, l, x, l, y)
|
||||
d += col # Select line style
|
||||
d
|
||||
end
|
||||
|
||||
def draw_to(absx, absy, x, y)
|
||||
dx = x - absx
|
||||
dy = y - absy
|
||||
|
||||
# Split the line up if there's anything>16383, because
|
||||
# that would overflow the 4 bits allowed for length
|
||||
mstep = [dx.abs / 16383, dy.abs / 16383, 1].max.ceil
|
||||
xstep = dx / mstep
|
||||
ystep = dy / mstep
|
||||
d = ""
|
||||
1.upto(mstep).each do
|
||||
d += draw_section(x, y, x + xstep, y + ystep)
|
||||
x += xstep
|
||||
y += ystep
|
||||
end
|
||||
d
|
||||
end
|
||||
|
||||
def draw_section(x1, y1, x2, y2)
|
||||
d = "11" # TypeFlag, EdgeFlag
|
||||
dx = x2 - x1
|
||||
dy = y2 - y1
|
||||
l = [length_sb(dx), length_sb(dy)].max
|
||||
d += format("%04b", l - 2)
|
||||
d += "1" # GeneralLine
|
||||
d += format("%0*b%0*b", l, dx, l, dy)
|
||||
d
|
||||
end
|
||||
|
||||
# -----------------------------------------------------------------------
|
||||
# Specific data types
|
||||
|
||||
# SWF data block type
|
||||
|
||||
def swf_record(id, r)
|
||||
if r.length > 62
|
||||
# Long header: tag id, 0x3F, length
|
||||
pack_u16((id << 6) + 0x3F) + pack_u32(r.length) + r
|
||||
else
|
||||
# Short header: tag id, length
|
||||
pack_u16((id << 6) + r.length) + r
|
||||
end
|
||||
end
|
||||
|
||||
# SWF RECT type
|
||||
|
||||
def pack_rect(a, b, c, d)
|
||||
l = [length_sb(a),
|
||||
length_sb(b),
|
||||
length_sb(c),
|
||||
length_sb(d)].max
|
||||
# create binary string (00111001 etc.) - 5-byte length, then bbox
|
||||
n = format("%05b%0*b%0*b%0*b%0*b", l, l, a, l, b, l, c, l, d)
|
||||
# pack into byte string
|
||||
[n].pack("B*")
|
||||
end
|
||||
|
||||
# -----------------------------------------------------------------------
|
||||
# Generic pack functions
|
||||
|
||||
def pack_u16(n)
|
||||
[n.floor].pack("v")
|
||||
end
|
||||
|
||||
def pack_u32(n)
|
||||
[n.floor].pack("V")
|
||||
end
|
||||
|
||||
# Find number of bits required to store arbitrary-length binary
|
||||
|
||||
def length_sb(n)
|
||||
Math.frexp(n + (n.zero? ? 1 : 0))[1] + 1
|
||||
end
|
||||
|
||||
# ====================================================================
|
||||
# Co-ordinate conversion
|
||||
# (this is duplicated from amf_controller, should probably share)
|
||||
|
||||
def lat2coord(a, basey, masterscale)
|
||||
-(lat2y(a) - basey) * masterscale
|
||||
end
|
||||
|
||||
def long2coord(a, baselong, masterscale)
|
||||
(a - baselong) * masterscale
|
||||
end
|
||||
|
||||
def lat2y(a)
|
||||
180 / Math::PI * Math.log(Math.tan(Math::PI / 4 + a * (Math::PI / 180) / 2))
|
||||
end
|
||||
end
|
||||
end
|
|
@ -25,8 +25,8 @@ module Api
|
|||
bbox = BoundingBox.from_bbox_params(params)
|
||||
bbox.check_boundaries
|
||||
bbox.check_size
|
||||
rescue StandardError => err
|
||||
report_error(err.message)
|
||||
rescue StandardError => e
|
||||
report_error(e.message)
|
||||
return
|
||||
end
|
||||
|
||||
|
|
|
@ -16,13 +16,9 @@ module Api
|
|||
around_action :api_call_handle_error
|
||||
|
||||
def show
|
||||
trace = Trace.visible.find(params[:id])
|
||||
@trace = Trace.visible.find(params[:id])
|
||||
|
||||
if trace.public? || trace.user == current_user
|
||||
render :xml => trace.to_xml.to_s
|
||||
else
|
||||
head :forbidden
|
||||
end
|
||||
head :forbidden unless @trace.public? || @trace.user == current_user
|
||||
end
|
||||
|
||||
def update
|
||||
|
|
|
@ -13,7 +13,7 @@ module Api
|
|||
|
||||
def show
|
||||
if @user.visible?
|
||||
render :action => :show, :content_type => "text/xml"
|
||||
render :content_type => "text/xml"
|
||||
else
|
||||
head :gone
|
||||
end
|
||||
|
@ -33,15 +33,12 @@ module Api
|
|||
|
||||
@users = User.visible.find(ids)
|
||||
|
||||
render :action => :index, :content_type => "text/xml"
|
||||
render :content_type => "text/xml"
|
||||
end
|
||||
|
||||
def gpx_files
|
||||
doc = OSM::API.new.get_xml_doc
|
||||
current_user.traces.reload.each do |trace|
|
||||
doc.root << trace.to_xml_node
|
||||
end
|
||||
render :xml => doc.to_s
|
||||
@traces = current_user.traces.reload
|
||||
render :content_type => "application/xml"
|
||||
end
|
||||
|
||||
private
|
||||
|
|
15
app/controllers/api/versions_controller.rb
Normal file
15
app/controllers/api/versions_controller.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
module Api
|
||||
class VersionsController < ApiController
|
||||
authorize_resource :class => false
|
||||
|
||||
around_action :api_call_handle_error, :api_call_timeout
|
||||
|
||||
# Show the list of available API versions. This will replace the global
|
||||
# unversioned capabilities call in due course.
|
||||
# Currently we only support deploying one version at a time, but this will
|
||||
# hopefully change soon.
|
||||
def show
|
||||
@versions = [Settings.api_version]
|
||||
end
|
||||
end
|
||||
end
|
|
@ -37,8 +37,8 @@ class ApplicationController < ActionController::Base
|
|||
elsif session[:token]
|
||||
session[:user] = current_user.id if self.current_user = User.authenticate(:token => session[:token])
|
||||
end
|
||||
rescue StandardError => ex
|
||||
logger.info("Exception authorizing user: #{ex}")
|
||||
rescue StandardError => e
|
||||
logger.info("Exception authorizing user: #{e}")
|
||||
reset_session
|
||||
self.current_user = nil
|
||||
end
|
||||
|
@ -185,22 +185,22 @@ class ApplicationController < ActionController::Base
|
|||
|
||||
def api_call_handle_error
|
||||
yield
|
||||
rescue ActiveRecord::RecordNotFound => ex
|
||||
rescue ActiveRecord::RecordNotFound => e
|
||||
head :not_found
|
||||
rescue LibXML::XML::Error, ArgumentError => ex
|
||||
report_error ex.message, :bad_request
|
||||
rescue ActiveRecord::RecordInvalid => ex
|
||||
message = "#{ex.record.class} #{ex.record.id}: "
|
||||
ex.record.errors.each { |attr, msg| message << "#{attr}: #{msg} (#{ex.record[attr].inspect})" }
|
||||
rescue LibXML::XML::Error, ArgumentError => e
|
||||
report_error e.message, :bad_request
|
||||
rescue ActiveRecord::RecordInvalid => e
|
||||
message = "#{e.record.class} #{e.record.id}: "
|
||||
e.record.errors.each { |attr, msg| message << "#{attr}: #{msg} (#{e.record[attr].inspect})" }
|
||||
report_error message, :bad_request
|
||||
rescue OSM::APIError => ex
|
||||
report_error ex.message, ex.status
|
||||
rescue AbstractController::ActionNotFound => ex
|
||||
rescue OSM::APIError => e
|
||||
report_error e.message, e.status
|
||||
rescue AbstractController::ActionNotFound => e
|
||||
raise
|
||||
rescue StandardError => ex
|
||||
logger.info("API threw unexpected #{ex.class} exception: #{ex.message}")
|
||||
ex.backtrace.each { |l| logger.info(l) }
|
||||
report_error "#{ex.class}: #{ex.message}", :internal_server_error
|
||||
rescue StandardError => e
|
||||
logger.info("API threw unexpected #{e.class} exception: #{e.message}")
|
||||
e.backtrace.each { |l| logger.info(l) }
|
||||
report_error "#{e.class}: #{e.message}", :internal_server_error
|
||||
end
|
||||
|
||||
##
|
||||
|
@ -227,11 +227,11 @@ class ApplicationController < ActionController::Base
|
|||
OSM::Timer.timeout(Settings.web_timeout, Timeout::Error) do
|
||||
yield
|
||||
end
|
||||
rescue ActionView::Template::Error => ex
|
||||
ex = ex.cause
|
||||
rescue ActionView::Template::Error => e
|
||||
e = e.cause
|
||||
|
||||
if ex.is_a?(Timeout::Error) ||
|
||||
(ex.is_a?(ActiveRecord::StatementInvalid) && ex.message =~ /execution expired/)
|
||||
if e.is_a?(Timeout::Error) ||
|
||||
(e.is_a?(ActiveRecord::StatementInvalid) && e.message =~ /execution expired/)
|
||||
render :action => "timeout"
|
||||
else
|
||||
raise
|
||||
|
|
|
@ -53,14 +53,14 @@ class ChangesetsController < ApplicationController
|
|||
elsif @params[:bbox]
|
||||
changesets = conditions_bbox(changesets, BoundingBox.from_bbox_params(params))
|
||||
elsif @params[:friends] && current_user
|
||||
changesets = changesets.where(:user_id => current_user.friend_users.identifiable)
|
||||
changesets = changesets.where(:user_id => current_user.friends.identifiable)
|
||||
elsif @params[:nearby] && current_user
|
||||
changesets = changesets.where(:user_id => current_user.nearby)
|
||||
end
|
||||
|
||||
changesets = changesets.where("changesets.id <= ?", @params[:max_id]) if @params[:max_id]
|
||||
|
||||
@edits = changesets.order("changesets.id DESC").limit(20).preload(:user, :changeset_tags, :comments)
|
||||
@changesets = changesets.order("changesets.id DESC").limit(20).preload(:user, :changeset_tags, :comments)
|
||||
|
||||
render :action => :index, :layout => false
|
||||
end
|
||||
|
|
|
@ -8,38 +8,40 @@ class DiaryEntriesController < ApplicationController
|
|||
authorize_resource
|
||||
|
||||
before_action :lookup_user, :only => [:show, :comments]
|
||||
before_action :check_database_writable, :only => [:new, :edit, :comment, :hide, :hidecomment, :subscribe, :unsubscribe]
|
||||
before_action :allow_thirdparty_images, :only => [:new, :edit, :index, :show, :comments]
|
||||
before_action :check_database_writable, :only => [:new, :create, :edit, :update, :comment, :hide, :hidecomment, :subscribe, :unsubscribe]
|
||||
before_action :allow_thirdparty_images, :only => [:new, :create, :edit, :update, :index, :show, :comments]
|
||||
|
||||
def new
|
||||
@title = t "diary_entries.new.title"
|
||||
|
||||
if request.post?
|
||||
@diary_entry = DiaryEntry.new(entry_params)
|
||||
@diary_entry.user = current_user
|
||||
default_lang = current_user.preferences.where(:k => "diary.default_language").first
|
||||
lang_code = default_lang ? default_lang.v : current_user.preferred_language
|
||||
@diary_entry = DiaryEntry.new(entry_params.merge(:language_code => lang_code))
|
||||
set_map_location
|
||||
render :action => "new"
|
||||
end
|
||||
|
||||
if @diary_entry.save
|
||||
default_lang = current_user.preferences.where(:k => "diary.default_language").first
|
||||
if default_lang
|
||||
default_lang.v = @diary_entry.language_code
|
||||
default_lang.save!
|
||||
else
|
||||
current_user.preferences.create(:k => "diary.default_language", :v => @diary_entry.language_code)
|
||||
end
|
||||
def create
|
||||
@title = t "diary_entries.new.title"
|
||||
|
||||
# Subscribe user to diary comments
|
||||
@diary_entry.subscriptions.create(:user => current_user)
|
||||
@diary_entry = DiaryEntry.new(entry_params)
|
||||
@diary_entry.user = current_user
|
||||
|
||||
redirect_to :action => "index", :display_name => current_user.display_name
|
||||
else
|
||||
render :action => "edit"
|
||||
end
|
||||
else
|
||||
if @diary_entry.save
|
||||
default_lang = current_user.preferences.where(:k => "diary.default_language").first
|
||||
lang_code = default_lang ? default_lang.v : current_user.preferred_language
|
||||
@diary_entry = DiaryEntry.new(entry_params.merge(:language_code => lang_code))
|
||||
set_map_location
|
||||
render :action => "edit"
|
||||
if default_lang
|
||||
default_lang.v = @diary_entry.language_code
|
||||
default_lang.save!
|
||||
else
|
||||
current_user.preferences.create(:k => "diary.default_language", :v => @diary_entry.language_code)
|
||||
end
|
||||
|
||||
# Subscribe user to diary comments
|
||||
@diary_entry.subscriptions.create(:user => current_user)
|
||||
|
||||
redirect_to :action => "index", :display_name => current_user.display_name
|
||||
else
|
||||
render :action => "new"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -47,19 +49,32 @@ class DiaryEntriesController < ApplicationController
|
|||
@title = t "diary_entries.edit.title"
|
||||
@diary_entry = DiaryEntry.find(params[:id])
|
||||
|
||||
if current_user != @diary_entry.user
|
||||
redirect_to diary_entry_path(@diary_entry.user, @diary_entry)
|
||||
elsif params[:diary_entry] && @diary_entry.update(entry_params)
|
||||
redirect_to diary_entry_path(@diary_entry.user, @diary_entry)
|
||||
end
|
||||
redirect_to diary_entry_path(@diary_entry.user, @diary_entry) if current_user != @diary_entry.user
|
||||
|
||||
set_map_location
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render :action => "no_such_entry", :status => :not_found
|
||||
end
|
||||
|
||||
def update
|
||||
@title = t "diary_entries.edit.title"
|
||||
@diary_entry = DiaryEntry.find(params[:id])
|
||||
|
||||
if current_user != @diary_entry.user
|
||||
redirect_to diary_entry_path(@diary_entry.user, @diary_entry)
|
||||
elsif params[:diary_entry] && @diary_entry.update(entry_params)
|
||||
redirect_to diary_entry_path(@diary_entry.user, @diary_entry)
|
||||
else
|
||||
set_map_location
|
||||
render :action => "edit"
|
||||
end
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render :action => "no_such_entry", :status => :not_found
|
||||
end
|
||||
|
||||
def comment
|
||||
@entry = DiaryEntry.find(params[:id])
|
||||
@comments = @entry.visible_comments
|
||||
@diary_comment = @entry.comments.build(comment_params)
|
||||
@diary_comment.user = current_user
|
||||
if @diary_comment.save
|
||||
|
@ -114,7 +129,7 @@ class DiaryEntriesController < ApplicationController
|
|||
elsif params[:friends]
|
||||
if current_user
|
||||
@title = t "diary_entries.index.title_friends"
|
||||
@entries = DiaryEntry.where(:user_id => current_user.friend_users)
|
||||
@entries = DiaryEntry.where(:user_id => current_user.friends)
|
||||
else
|
||||
require_user
|
||||
return
|
||||
|
@ -143,7 +158,7 @@ class DiaryEntriesController < ApplicationController
|
|||
@page = (params[:page] || 1).to_i
|
||||
@page_size = 20
|
||||
|
||||
@entries = @entries.visible
|
||||
@entries = @entries.visible unless current_user&.administrator?
|
||||
@entries = @entries.order("created_at DESC")
|
||||
@entries = @entries.offset((@page - 1) * @page_size)
|
||||
@entries = @entries.limit(@page_size)
|
||||
|
@ -166,6 +181,10 @@ class DiaryEntriesController < ApplicationController
|
|||
else
|
||||
@entries = DiaryEntry.joins(:user).where(:users => { :status => %w[active confirmed] })
|
||||
|
||||
# Items can't be flagged as deleted in the RSS format.
|
||||
# For the general feeds, allow a delay before publishing, to help spam fighting
|
||||
@entries = @entries.where("created_at < :time", :time => Settings.diary_feed_delay.hours.ago)
|
||||
|
||||
if params[:language]
|
||||
@entries = @entries.where(:language_code => params[:language])
|
||||
@title = t("diary_entries.feed.language.title", :language_name => Language.find(params[:language]).english_name)
|
||||
|
@ -177,7 +196,6 @@ class DiaryEntriesController < ApplicationController
|
|||
@link = url_for :action => "index", :host => Settings.server_url, :protocol => Settings.server_protocol
|
||||
end
|
||||
end
|
||||
|
||||
@entries = @entries.visible.includes(:user).order("created_at DESC").limit(20)
|
||||
end
|
||||
|
||||
|
@ -185,6 +203,7 @@ class DiaryEntriesController < ApplicationController
|
|||
@entry = @user.diary_entries.visible.where(:id => params[:id]).first
|
||||
if @entry
|
||||
@title = t "diary_entries.show.title", :user => params[:display_name], :title => @entry.title
|
||||
@comments = current_user&.administrator? ? @entry.comments : @entry.visible_comments
|
||||
else
|
||||
@title = t "diary_entries.no_such_entry.title", :id => params[:id]
|
||||
render :action => "no_such_entry", :status => :not_found
|
||||
|
@ -197,12 +216,24 @@ class DiaryEntriesController < ApplicationController
|
|||
redirect_to :action => "index", :display_name => entry.user.display_name
|
||||
end
|
||||
|
||||
def unhide
|
||||
entry = DiaryEntry.find(params[:id])
|
||||
entry.update(:visible => true)
|
||||
redirect_to :action => "index", :display_name => entry.user.display_name
|
||||
end
|
||||
|
||||
def hidecomment
|
||||
comment = DiaryComment.find(params[:comment])
|
||||
comment.update(:visible => false)
|
||||
redirect_to diary_entry_path(comment.diary_entry.user, comment.diary_entry)
|
||||
end
|
||||
|
||||
def unhidecomment
|
||||
comment = DiaryComment.find(params[:comment])
|
||||
comment.update(:visible => true)
|
||||
redirect_to diary_entry_path(comment.diary_entry.user, comment.diary_entry)
|
||||
end
|
||||
|
||||
def comments
|
||||
@comment_pages, @comments = paginate(:diary_comments,
|
||||
:conditions => {
|
||||
|
|
|
@ -98,8 +98,8 @@ class GeocoderController < ApplicationController
|
|||
end
|
||||
|
||||
render :action => "results"
|
||||
rescue StandardError => ex
|
||||
@error = "Error contacting geocoder.ca: #{ex}"
|
||||
rescue StandardError => e
|
||||
@error = "Error contacting geocoder.ca: #{e}"
|
||||
render :action => "error"
|
||||
end
|
||||
|
||||
|
@ -166,8 +166,8 @@ class GeocoderController < ApplicationController
|
|||
end
|
||||
|
||||
render :action => "results"
|
||||
rescue StandardError => ex
|
||||
@error = "Error contacting nominatim.openstreetmap.org: #{ex}"
|
||||
rescue StandardError => e
|
||||
@error = "Error contacting nominatim.openstreetmap.org: #{e}"
|
||||
render :action => "error"
|
||||
end
|
||||
|
||||
|
@ -198,8 +198,8 @@ class GeocoderController < ApplicationController
|
|||
end
|
||||
|
||||
render :action => "results"
|
||||
rescue StandardError => ex
|
||||
@error = "Error contacting api.geonames.org: #{ex}"
|
||||
rescue StandardError => e
|
||||
@error = "Error contacting api.geonames.org: #{e}"
|
||||
render :action => "error"
|
||||
end
|
||||
|
||||
|
@ -230,8 +230,8 @@ class GeocoderController < ApplicationController
|
|||
end
|
||||
|
||||
render :action => "results"
|
||||
rescue StandardError => ex
|
||||
@error = "Error contacting nominatim.openstreetmap.org: #{ex}"
|
||||
rescue StandardError => e
|
||||
@error = "Error contacting nominatim.openstreetmap.org: #{e}"
|
||||
render :action => "error"
|
||||
end
|
||||
|
||||
|
@ -261,8 +261,8 @@ class GeocoderController < ApplicationController
|
|||
end
|
||||
|
||||
render :action => "results"
|
||||
rescue StandardError => ex
|
||||
@error = "Error contacting api.geonames.org: #{ex}"
|
||||
rescue StandardError => e
|
||||
@error = "Error contacting api.geonames.org: #{e}"
|
||||
render :action => "error"
|
||||
end
|
||||
|
||||
|
|
|
@ -126,7 +126,7 @@ class SiteController < ApplicationController
|
|||
:style_src => %w['unsafe-inline']
|
||||
)
|
||||
|
||||
render "id", :layout => false
|
||||
render :layout => false
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -113,8 +113,8 @@ class TracesController < ApplicationController
|
|||
begin
|
||||
@trace = do_create(params[:trace][:gpx_file], params[:trace][:tagstring],
|
||||
params[:trace][:description], params[:trace][:visibility])
|
||||
rescue StandardError => ex
|
||||
logger.debug ex
|
||||
rescue StandardError => e
|
||||
logger.debug e
|
||||
end
|
||||
|
||||
if @trace.id
|
||||
|
|
|
@ -36,7 +36,7 @@ class UsersController < ApplicationController
|
|||
def save
|
||||
@title = t "users.new.title"
|
||||
|
||||
if params[:decline]
|
||||
if params[:decline] || !(params[:read_tou] && params[:read_ct])
|
||||
if current_user
|
||||
current_user.terms_seen = true
|
||||
|
||||
|
@ -47,12 +47,15 @@ class UsersController < ApplicationController
|
|||
else
|
||||
redirect_to :action => :account, :display_name => current_user.display_name
|
||||
end
|
||||
else
|
||||
elsif params[:decline]
|
||||
redirect_to t("users.terms.declined")
|
||||
else
|
||||
redirect_to :action => :terms
|
||||
end
|
||||
elsif current_user
|
||||
unless current_user.terms_agreed?
|
||||
current_user.consider_pd = params[:user][:consider_pd]
|
||||
current_user.tou_agreed = Time.now.getutc
|
||||
current_user.terms_agreed = Time.now.getutc
|
||||
current_user.terms_seen = true
|
||||
|
||||
|
@ -73,6 +76,7 @@ class UsersController < ApplicationController
|
|||
current_user.creation_ip = request.remote_ip
|
||||
current_user.languages = http_accept_language.user_preferred_languages
|
||||
current_user.terms_agreed = Time.now.getutc
|
||||
current_user.tou_agreed = Time.now.getutc
|
||||
current_user.terms_seen = true
|
||||
|
||||
if current_user.auth_uid.blank?
|
||||
|
@ -384,16 +388,16 @@ class UsersController < ApplicationController
|
|||
|
||||
if @new_friend
|
||||
if request.post?
|
||||
friend = Friend.new
|
||||
friend.befriender = current_user
|
||||
friend.befriendee = @new_friend
|
||||
friendship = Friendship.new
|
||||
friendship.befriender = current_user
|
||||
friendship.befriendee = @new_friend
|
||||
if current_user.is_friends_with?(@new_friend)
|
||||
flash[:warning] = t "users.make_friend.already_a_friend", :name => @new_friend.display_name
|
||||
elsif friend.save
|
||||
elsif friendship.save
|
||||
flash[:notice] = t "users.make_friend.success", :name => @new_friend.display_name
|
||||
Notifier.friend_notification(friend).deliver_later
|
||||
Notifier.friend_notification(friendship).deliver_later
|
||||
else
|
||||
friend.add_error(t("users.make_friend.failed", :name => @new_friend.display_name))
|
||||
friendship.add_error(t("users.make_friend.failed", :name => @new_friend.display_name))
|
||||
end
|
||||
|
||||
if params[:referer]
|
||||
|
@ -413,7 +417,7 @@ class UsersController < ApplicationController
|
|||
if @friend
|
||||
if request.post?
|
||||
if current_user.is_friends_with?(@friend)
|
||||
Friend.where(:user_id => current_user.id, :friend_user_id => @friend.id).delete_all
|
||||
Friendship.where(:befriender => current_user, :befriendee => @friend).delete_all
|
||||
flash[:notice] = t "users.remove_friend.success", :name => @friend.display_name
|
||||
else
|
||||
flash[:error] = t "users.remove_friend.not_a_friend", :name => @friend.display_name
|
||||
|
@ -748,7 +752,13 @@ class UsersController < ApplicationController
|
|||
email.split("@").last
|
||||
end
|
||||
|
||||
if blocked = Acl.no_account_creation(request.remote_ip, domain)
|
||||
mx_servers = if domain.nil?
|
||||
nil
|
||||
else
|
||||
domain_mx_servers(domain)
|
||||
end
|
||||
|
||||
if blocked = Acl.no_account_creation(request.remote_ip, :domain => domain, :mx => mx_servers)
|
||||
logger.info "Blocked signup from #{request.remote_ip} for #{email}"
|
||||
|
||||
render :action => "blocked"
|
||||
|
@ -757,6 +767,14 @@ class UsersController < ApplicationController
|
|||
!blocked
|
||||
end
|
||||
|
||||
##
|
||||
# get list of MX servers for a domains
|
||||
def domain_mx_servers(domain)
|
||||
Resolv::DNS.open do |dns|
|
||||
dns.getresources(domain, Resolv::DNS::Resource::IN::MX).collect(&:exchange).collect(&:to_s)
|
||||
end
|
||||
end
|
||||
|
||||
##
|
||||
# check if this user has a gravatar and set the user pref is true
|
||||
def gravatar_enable(user)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue