Added postgresql support.
This commit is contained in:
parent
a2b68280b9
commit
c775463fd8
3 changed files with 44 additions and 46 deletions
|
@ -115,13 +115,12 @@ class UsersController < ApplicationController
|
||||||
|
|
||||||
# check if user already exists
|
# check if user already exists
|
||||||
if user.email
|
if user.email
|
||||||
exists = User.where( email: user.email ).first
|
exists = User.where(email: user.email.downcase).first
|
||||||
if exists
|
if exists
|
||||||
render json: { error: 'User already exists!' }, status: :unprocessable_entity
|
render json: { error: 'User already exists!' }, status: :unprocessable_entity
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
user.save!
|
user.save!
|
||||||
|
|
||||||
# if first user was added, set system init done
|
# if first user was added, set system init done
|
||||||
|
@ -178,7 +177,6 @@ class UsersController < ApplicationController
|
||||||
body: data[:body]
|
body: data[:body]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
user_new = User.find(user.id)
|
user_new = User.find(user.id)
|
||||||
render json: user_new, status: :created
|
render json: user_new, status: :created
|
||||||
rescue => e
|
rescue => e
|
||||||
|
@ -685,7 +683,7 @@ Payload:
|
||||||
|
|
||||||
Response:
|
Response:
|
||||||
{
|
{
|
||||||
:message => 'ok'
|
message: 'ok'
|
||||||
}
|
}
|
||||||
|
|
||||||
Test:
|
Test:
|
||||||
|
|
|
@ -35,9 +35,9 @@ returns if user has no permissions to search
|
||||||
search organizations
|
search organizations
|
||||||
|
|
||||||
result = Organization.search(
|
result = Organization.search(
|
||||||
:current_user => User.find(123),
|
current_user: User.find(123),
|
||||||
:query => 'search something',
|
query: 'search something',
|
||||||
:limit => 15,
|
limit: 15,
|
||||||
)
|
)
|
||||||
|
|
||||||
returns
|
returns
|
||||||
|
@ -75,7 +75,7 @@ returns
|
||||||
|
|
||||||
# if only a few organizations are found, search for names of users
|
# if only a few organizations are found, search for names of users
|
||||||
if organizations.length <= 3
|
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}%"
|
'users.firstname LIKE ? or users.lastname LIKE ? or users.email LIKE ?', "%#{query}%", "%#{query}%", "%#{query}%"
|
||||||
).order('organizations.name').limit(limit)
|
).order('organizations.name').limit(limit)
|
||||||
organizations_by_user.each {|organization_by_user|
|
organizations_by_user.each {|organization_by_user|
|
||||||
|
|
|
@ -153,18 +153,18 @@ returns
|
||||||
# - stip out * we already search for *query* -
|
# - stip out * we already search for *query* -
|
||||||
if query
|
if query
|
||||||
query.delete! '*'
|
query.delete! '*'
|
||||||
tickets_all = Ticket.select('DISTINCT(tickets.id)')
|
tickets_all = Ticket.select('DISTINCT(tickets.id), tickets.created_at')
|
||||||
.where(access_condition)
|
.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)
|
.joins(:articles)
|
||||||
.order('`tickets`.`created_at` DESC')
|
.order('tickets.created_at DESC')
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
else
|
else
|
||||||
query_condition, bind_condition = selector2sql(params[:condition])
|
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(access_condition)
|
||||||
.where(query_condition, *bind_condition)
|
.where(query_condition, *bind_condition)
|
||||||
.order('`tickets`.`created_at` DESC')
|
.order('tickets.created_at DESC')
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue