Added postgresql support.

This commit is contained in:
Martin Edenhofer 2016-01-20 02:48:54 +01:00
parent a2b68280b9
commit c775463fd8
3 changed files with 44 additions and 46 deletions

View file

@ -115,13 +115,12 @@ class UsersController < ApplicationController
# check if user already exists
if user.email
exists = User.where( email: user.email ).first
exists = User.where(email: user.email.downcase).first
if exists
render json: { error: 'User already exists!' }, status: :unprocessable_entity
return
end
end
user.save!
# if first user was added, set system init done
@ -178,7 +177,6 @@ class UsersController < ApplicationController
body: data[:body]
)
end
user_new = User.find(user.id)
render json: user_new, status: :created
rescue => e
@ -685,7 +683,7 @@ Payload:
Response:
{
:message => 'ok'
message: 'ok'
}
Test:

View file

@ -35,9 +35,9 @@ returns if user has no permissions to search
search organizations
result = Organization.search(
:current_user => User.find(123),
:query => 'search something',
:limit => 15,
current_user: User.find(123),
query: 'search something',
limit: 15,
)
returns
@ -75,7 +75,7 @@ returns
# if only a few organizations are found, search for names of users
if organizations.length <= 3
organizations_by_user = Organization.select('DISTINCT(organizations.id)').joins('LEFT OUTER JOIN users ON users.organization_id = organizations.id').where(
organizations_by_user = Organization.select('DISTINCT(organizations.id), organizations.name').joins('LEFT OUTER JOIN users ON users.organization_id = organizations.id').where(
'users.firstname LIKE ? or users.lastname LIKE ? or users.email LIKE ?', "%#{query}%", "%#{query}%", "%#{query}%"
).order('organizations.name').limit(limit)
organizations_by_user.each {|organization_by_user|

View file

@ -153,18 +153,18 @@ returns
# - stip out * we already search for *query* -
if query
query.delete! '*'
tickets_all = Ticket.select('DISTINCT(tickets.id)')
tickets_all = Ticket.select('DISTINCT(tickets.id), tickets.created_at')
.where(access_condition)
.where( '( `tickets`.`title` LIKE ? OR `tickets`.`number` LIKE ? OR `ticket_articles`.`body` LIKE ? OR `ticket_articles`.`from` LIKE ? OR `ticket_articles`.`to` LIKE ? OR `ticket_articles`.`subject` LIKE ?)', "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%" )
.where('(tickets.title LIKE ? OR tickets.number LIKE ? OR ticket_articles.body LIKE ? OR ticket_articles.from LIKE ? OR ticket_articles.to LIKE ? OR ticket_articles.subject LIKE ?)', "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%" )
.joins(:articles)
.order('`tickets`.`created_at` DESC')
.order('tickets.created_at DESC')
.limit(limit)
else
query_condition, bind_condition = selector2sql(params[:condition])
tickets_all = Ticket.select('DISTINCT(tickets.id)')
tickets_all = Ticket.select('DISTINCT(tickets.id), tickets.created_at')
.where(access_condition)
.where(query_condition, *bind_condition)
.order('`tickets`.`created_at` DESC')
.order('tickets.created_at DESC')
.limit(limit)
end