Merge branch 'develop' of git.znuny.com:zammad/zammad into develop

This commit is contained in:
Martin Edenhofer 2018-04-26 23:23:58 +02:00
commit 12fb3c9126
122 changed files with 460 additions and 459 deletions

View file

@ -226,3 +226,9 @@ Lint/AmbiguousBlockAssociation:
Exclude:
- "**/*_spec.rb"
- "**/*_examples.rb"
# Special exceptions
Style/HashSyntax:
Exclude:
- "**/*.rake"

View file

@ -2,6 +2,6 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require File.expand_path('config/application', __dir__)
require_relative 'config/application'
Zammad::Application.load_tasks

View file

@ -294,7 +294,7 @@ class ConnectionWizard extends App.WizardModal
option = ''
options = {}
if !_.isEmpty data.attributes && !_.isEmpty data.attributes.namingcontexts
if !_.isEmpty(data.attributes) && !_.isEmpty(data.attributes.namingcontexts)
for dn in data.attributes.namingcontexts
options[dn] = dn
if option is ''

View file

@ -1,6 +1,4 @@
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
require 'exceptions'
class ApplicationController < ActionController::Base
include ApplicationController::HandlesErrors
include ApplicationController::HandlesDevices

View file

@ -1,7 +1,4 @@
# Copyright (C) 2012-2015 Zammad Foundation, http://zammad-foundation.org/
require 'icalendar'
class CalendarSubscriptionsController < ApplicationController
prepend_before_action { authentication_check( { basic_auth_promt: true, permission: 'user_preferences.calendar' } ) }

View file

@ -1,7 +1,4 @@
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
require 'resolv'
class GettingStartedController < ApplicationController
=begin

View file

@ -1,6 +1,4 @@
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
require 'zendesk_api'
class ImportZendeskController < ApplicationController
def url_check

View file

@ -1,7 +1,7 @@
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
require 'ldap'
require 'ldap/user'
require 'ldap/group'
require_dependency 'ldap'
require_dependency 'ldap/user'
require_dependency 'ldap/group'
class Integration::LdapController < ApplicationController
include Integration::ImportJobBase

View file

@ -1,5 +1,4 @@
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
require 'builder'
class Integration::SipgateController < ApplicationController

View file

@ -1,7 +1,4 @@
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
require 'tempfile'
class ReportsController < ApplicationController
prepend_before_action { authentication_check(permission: 'report') }

View file

@ -1,7 +1,4 @@
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
require 'ticket/overviews'
class TicketOverviewsController < ApplicationController
prepend_before_action :authentication_check

View file

@ -1,7 +1,5 @@
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
class ActivityStream < ApplicationModel
load 'activity_stream/assets.rb'
include ActivityStream::Assets
self.table_name = 'activity_streams'

View file

@ -2,6 +2,7 @@
class ActivityStream
module Assets
extend ActiveSupport::Concern
=begin

View file

@ -1,7 +1,6 @@
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
class Channel < ApplicationModel
load 'channel/assets.rb'
include Channel::Assets
belongs_to :group

View file

@ -2,6 +2,7 @@
class Channel
module Assets
extend ActiveSupport::Concern
=begin

View file

@ -1,7 +1,4 @@
# Copyright (C) 2012-2015 Zammad Foundation, http://zammad-foundation.org/
require 'facebook'
class Channel::Driver::Facebook
=begin
@ -38,7 +35,7 @@ class Channel::Driver::Facebook
if !access_token
raise "No access_token found for fb_object_id: #{fb_object_id}"
end
client = Facebook.new(access_token)
client = ::Facebook.new(access_token)
client.from_article(article)
end
@ -96,7 +93,7 @@ returns
page = get_page(page_to_sync_id)
next if !page
next if page_to_sync_params['group_id'].blank?
page_client = Facebook.new(page['access_token'])
page_client = ::Facebook.new(page['access_token'])
posts = page_client.client.get_connection('me', 'feed', fields: 'id,from,to,message,created_time,permalink_url,comments{id,from,to,message,created_time}')
posts.each do |post|

View file

@ -1,5 +1,4 @@
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
require 'net/imap'
class Channel::Driver::Imap < Channel::EmailParser
@ -101,7 +100,7 @@ example
end
Timeout.timeout(timeout) do
@imap = Net::IMAP.new(options[:host], port, ssl, nil, false)
@imap = ::Net::IMAP.new(options[:host], port, ssl, nil, false)
if starttls
@imap.starttls()
end

View file

@ -62,7 +62,7 @@ returns
Rails.logger.info "fetching pop3 (#{options[:host]}/#{options[:user]} port=#{port},ssl=#{ssl})"
@pop = Net::POP3.new(options[:host], port)
@pop = ::Net::POP3.new(options[:host], port)
#@pop.set_debug_output $stderr
# on check, reduce open_timeout to have faster probing

View file

@ -1,7 +1,4 @@
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
require 'mail'
module Channel::EmailBuild
=begin

View file

@ -2,9 +2,6 @@
# encoding: utf-8
require 'mail'
require 'encode'
class Channel::EmailParser
=begin

View file

@ -2,10 +2,8 @@ class Chat::Session < ApplicationModel
include HasSearchIndexBackend
include HasTags
extend Chat::Session::Search
load 'chat/session/search_index.rb'
include Chat::Session::Search
include Chat::Session::SearchIndex
load 'chat/session/assets.rb'
include Chat::Session::Assets
# rubocop:disable Rails/InverseOf

View file

@ -1,5 +1,6 @@
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
module Chat::Session::Assets
extend ActiveSupport::Concern
=begin

View file

@ -1,7 +1,10 @@
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
class Chat::Session
module Search
extend ActiveSupport::Concern
# methods defined here are going to extend the class, not the instance of it
class_methods do
=begin
@ -22,13 +25,13 @@ returns if user has no permissions to search
=end
def search_preferences(current_user)
return false if Setting.get('chat') != true || !current_user.permissions?('chat.agent')
{
prio: 900,
direct_search_index: true,
}
end
def search_preferences(current_user)
return false if Setting.get('chat') != true || !current_user.permissions?('chat.agent')
{
prio: 900,
direct_search_index: true,
}
end
=begin
@ -47,36 +50,37 @@ returns
=end
def search(params)
def search(params)
# get params
query = params[:query]
limit = params[:limit] || 10
offset = params[:offset] || 0
current_user = params[:current_user]
# get params
query = params[:query]
limit = params[:limit] || 10
offset = params[:offset] || 0
current_user = params[:current_user]
# enable search only for agents and admins
return [] if !search_preferences(current_user)
# enable search only for agents and admins
return [] if !search_preferences(current_user)
# try search index backend
if SearchIndexBackend.enabled?
items = SearchIndexBackend.search(query, limit, 'Chat::Session', {}, offset)
chat_sessions = []
items.each do |item|
chat_session = Chat::Session.lookup(id: item[:id])
next if !chat_session
chat_sessions.push chat_session
# try search index backend
if SearchIndexBackend.enabled?
items = SearchIndexBackend.search(query, limit, 'Chat::Session', {}, offset)
chat_sessions = []
items.each do |item|
chat_session = Chat::Session.lookup(id: item[:id])
next if !chat_session
chat_sessions.push chat_session
end
return chat_sessions
end
return chat_sessions
end
# fallback do sql query
# - stip out * we already search for *query* -
query.delete! '*'
chat_sessions = Chat::Session.where(
'name LIKE ?', "%#{query}%"
).order('name').offset(offset).limit(limit).to_a
chat_sessions
# fallback do sql query
# - stip out * we already search for *query* -
query.delete! '*'
chat_sessions = Chat::Session.where(
'name LIKE ?', "%#{query}%"
).order('name').offset(offset).limit(limit).to_a
chat_sessions
end
end
end
end

View file

@ -1,5 +1,9 @@
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
module Chat::Session::SearchIndex
extend ActiveSupport::Concern
# methods defined here are going to extend the class, not the instance of it
class_methods do
=begin
@ -14,23 +18,24 @@ returns
=end
def search_index_attribute_lookup
attributes = super
return if !attributes
def search_index_attribute_lookup
attributes = super
return if !attributes
attributes[:tag] = tag_list
attributes[:tag] = tag_list
messages = Chat::Message.where(chat_session_id: id)
attributes['messages'] = []
messages.each do |message|
messages = Chat::Message.where(chat_session_id: id)
attributes['messages'] = []
messages.each do |message|
# lookup attributes of ref. objects (normally name and note)
message_attributes = message.search_index_attribute_lookup
# lookup attributes of ref. objects (normally name and note)
message_attributes = message.search_index_attribute_lookup
attributes['messages'].push message_attributes
attributes['messages'].push message_attributes
end
attributes
end
attributes
end
end

View file

@ -1,4 +1,5 @@
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
require 'csv'
module CanCsvImport
@ -58,7 +59,7 @@ returns
raise Exceptions::UnprocessableEntity, 'Unable to parse empty file/string!'
end
rows = CSV.parse(data[:string], data[:parse_params])
rows = ::CSV.parse(data[:string], data[:parse_params])
header = rows.shift
if header.blank?
raise Exceptions::UnprocessableEntity, 'Unable to parse file/string without header!'
@ -301,7 +302,7 @@ returns
end
rows_to_add = []
end
CSV.generate(params) do |csv|
::CSV.generate(params) do |csv|
csv << header
rows.each do |row|
csv << row

View file

@ -1,7 +1,6 @@
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
class History < ApplicationModel
load 'history/assets.rb'
include History::Assets
self.table_name = 'histories'

View file

@ -2,6 +2,7 @@
class History
module Assets
extend ActiveSupport::Concern
=begin

View file

@ -4,7 +4,6 @@ class Job < ApplicationModel
include ChecksClientNotification
include ChecksConditionValidation
load 'job/assets.rb'
include Job::Assets
store :timeplan

View file

@ -2,6 +2,7 @@
class Job
module Assets
extend ActiveSupport::Concern
=begin

View file

@ -1,7 +1,4 @@
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
require 'history'
class Observer::Session < ActiveRecord::Observer
observe 'active_record::_session_store::_session'

View file

@ -1,7 +1,4 @@
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
require 'history'
class Observer::Tag::TicketHistory < ActiveRecord::Observer
observe 'tag'

View file

@ -1,7 +1,4 @@
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
require 'channel/driver/facebook'
class Observer::Ticket::Article::CommunicateFacebook < ActiveRecord::Observer
observe 'ticket::_article'

View file

@ -1,7 +1,8 @@
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
require_dependency 'stats/ticket_reopen'
class Observer::Ticket::StatsReopen < ActiveRecord::Observer
load 'stats/ticket_reopen.rb'
observe 'ticket'

View file

@ -1,7 +1,6 @@
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
class OnlineNotification < ApplicationModel
load 'online_notification/assets.rb'
include OnlineNotification::Assets
belongs_to :user

View file

@ -2,6 +2,7 @@
class OnlineNotification
module Assets
extend ActiveSupport::Concern
=begin

View file

@ -7,12 +7,10 @@ class Organization < ApplicationModel
include HasHistory
include HasSearchIndexBackend
include CanCsvImport
include Organization::ChecksAccess
load 'organization/assets.rb'
include Organization::ChecksAccess
include Organization::Assets
extend Organization::Search
load 'organization/search_index.rb'
include Organization::Search
include Organization::SearchIndex
# rubocop:disable Rails/InverseOf

View file

@ -2,6 +2,7 @@
class Organization
module Assets
extend ActiveSupport::Concern
=begin

View file

@ -2,6 +2,10 @@
class Organization
module Search
extend ActiveSupport::Concern
# methods defined here are going to extend the class, not the instance of it
class_methods do
=begin
@ -22,13 +26,13 @@ returns if user has no permissions to search
=end
def search_preferences(current_user)
return false if !current_user.permissions?('ticket.agent') && !current_user.permissions?('admin.organization')
{
prio: 1000,
direct_search_index: true,
}
end
def search_preferences(current_user)
return false if !current_user.permissions?('ticket.agent') && !current_user.permissions?('admin.organization')
{
prio: 1000,
direct_search_index: true,
}
end
=begin
@ -47,60 +51,61 @@ returns
=end
def search(params)
def search(params)
# get params
query = params[:query]
limit = params[:limit] || 10
offset = params[:offset] || 0
current_user = params[:current_user]
# get params
query = params[:query]
limit = params[:limit] || 10
offset = params[:offset] || 0
current_user = params[:current_user]
# enable search only for agents and admins
return [] if !search_preferences(current_user)
# enable search only for agents and admins
return [] if !search_preferences(current_user)
# try search index backend
if SearchIndexBackend.enabled?
items = SearchIndexBackend.search(query, limit, 'Organization', {}, offset)
organizations = []
items.each do |item|
organization = Organization.lookup(id: item[:id])
next if !organization
organizations.push organization
end
return organizations
end
# fallback do sql query
# - stip out * we already search for *query* -
query.delete! '*'
organizations = Organization.where(
'name LIKE ? OR note LIKE ?', "%#{query}%", "%#{query}%"
).order('name').offset(offset).limit(limit).to_a
# use result independent of size if an explicit offset is given
# this is the case for e.g. paginated searches
return organizations if params[:offset].present?
return organizations if organizations.length > 3
# if only a few organizations are found, search for names of users
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 do |organization_by_user|
organization_exists = false
organizations.each do |organization|
next if organization.id != organization_by_user.id
organization_exists = true
break
# try search index backend
if SearchIndexBackend.enabled?
items = SearchIndexBackend.search(query, limit, 'Organization', {}, offset)
organizations = []
items.each do |item|
organization = Organization.lookup(id: item[:id])
next if !organization
organizations.push organization
end
return organizations
end
# get model with full data
next if organization_exists
organizations.push Organization.find(organization_by_user.id)
# fallback do sql query
# - stip out * we already search for *query* -
query.delete! '*'
organizations = Organization.where(
'name LIKE ? OR note LIKE ?', "%#{query}%", "%#{query}%"
).order('name').offset(offset).limit(limit).to_a
# use result independent of size if an explicit offset is given
# this is the case for e.g. paginated searches
return organizations if params[:offset].present?
return organizations if organizations.length > 3
# if only a few organizations are found, search for names of users
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 do |organization_by_user|
organization_exists = false
organizations.each do |organization|
next if organization.id != organization_by_user.id
organization_exists = true
break
end
# get model with full data
next if organization_exists
organizations.push Organization.find(organization_by_user.id)
end
organizations
end
organizations
end
end
end

View file

@ -2,6 +2,7 @@
class Organization
module SearchIndex
extend ActiveSupport::Concern
=begin

View file

@ -6,7 +6,6 @@ class Overview < ApplicationModel
include ChecksConditionValidation
include CanSeed
load 'overview/assets.rb'
include Overview::Assets
has_and_belongs_to_many :roles, after_add: :cache_update, after_remove: :cache_update, class_name: 'Role'

View file

@ -2,6 +2,7 @@
class Overview
module Assets
extend ActiveSupport::Concern
=begin

View file

@ -1,7 +1,6 @@
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
class RecentView < ApplicationModel
load 'recent_view/assets.rb'
include RecentView::Assets
# rubocop:disable Rails/InverseOf

View file

@ -2,6 +2,7 @@
class RecentView
module Assets
extend ActiveSupport::Concern
=begin

View file

@ -6,7 +6,6 @@ class Role < ApplicationModel
include ChecksLatestChangeObserved
include HasGroups
load 'role/assets.rb'
include Role::Assets
has_and_belongs_to_many :users, after_add: :cache_update, after_remove: :cache_update

View file

@ -2,6 +2,7 @@
class Role
module Assets
extend ActiveSupport::Concern
=begin

View file

@ -1,6 +1,7 @@
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
class Scheduler < ApplicationModel
extend ::Mixin::StartFinishLogger
# rubocop:disable Style/ClassVars
@@jobs_started = {}
@ -120,8 +121,13 @@ class Scheduler < ApplicationModel
raise 'This method should only get called when Scheduler.threads are initialized. Use `force: true` to start anyway.'
end
Delayed::Job.all.each do |job|
cleanup_delayed(job)
log_start_finish(:info, 'Cleanup of left over locked delayed jobs') do
Delayed::Job.all.each do |job|
log_start_finish(:info, "Checking left over delayed job #{job.inspect}") do
cleanup_delayed(job)
end
end
end
end
@ -172,7 +178,7 @@ class Scheduler < ApplicationModel
job.destroy
end
Rails.logger.warn "#{action} locked delayed job: #{job_name}"
logger.warn "#{action} locked delayed job: #{job_name}"
end
def self.start_job(job)

View file

@ -4,7 +4,6 @@ class Sla < ApplicationModel
include ChecksClientNotification
include ChecksConditionValidation
load 'sla/assets.rb'
include Sla::Assets
store :condition

View file

@ -2,6 +2,7 @@
class Sla
module Assets
extend ActiveSupport::Concern
=begin

View file

@ -1,9 +1,9 @@
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
class Store < ApplicationModel
load 'store/object.rb'
load 'store/file.rb'
require_dependency 'store/object'
require_dependency 'store/file'
class Store < ApplicationModel
# rubocop:disable Rails/InverseOf
belongs_to :store_object, class_name: 'Store::Object'
belongs_to :store_file, class_name: 'Store::File'

View file

@ -1,6 +1,6 @@
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
class Store
class Store < ApplicationModel
class File < ApplicationModel
include ApplicationLib
after_destroy :destroy_provider

View file

@ -1,6 +1,6 @@
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
class Store
class Store < ApplicationModel
class Object < ApplicationModel
validates :name, presence: true
end

View file

@ -15,11 +15,9 @@ class Ticket < ApplicationModel
include Ticket::Escalation
include Ticket::Subject
load 'ticket/assets.rb'
include Ticket::Assets
load 'ticket/search_index.rb'
include Ticket::SearchIndex
extend Ticket::Search
include Ticket::Search
store :preferences
before_create :check_generate, :check_defaults, :check_title, :set_default_state, :set_default_priority

View file

@ -5,9 +5,8 @@ class Ticket::Article < ApplicationModel
include HasHistory
include ChecksHtmlSanitized
include CanCsvImport
include Ticket::Article::ChecksAccess
load 'ticket/article/assets.rb'
include Ticket::Article::ChecksAccess
include Ticket::Article::Assets
belongs_to :ticket

View file

@ -1,6 +1,7 @@
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
module Ticket::Article::Assets
extend ActiveSupport::Concern
=begin

View file

@ -1,5 +1,6 @@
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
module Ticket::Assets
extend ActiveSupport::Concern
=begin

View file

@ -1,5 +1,9 @@
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
module Ticket::Search
extend ActiveSupport::Concern
# methods defined here are going to extend the class, not the instance of it
class_methods do
=begin
@ -20,12 +24,12 @@ returns if user has no permissions to search
=end
def search_preferences(_current_user)
{
prio: 3000,
direct_search_index: false,
}
end
def search_preferences(_current_user)
{
prio: 3000,
direct_search_index: false,
}
end
=begin
@ -89,103 +93,104 @@ returns
=end
def search(params)
def search(params)
# get params
query = params[:query]
condition = params[:condition]
limit = params[:limit] || 12
offset = params[:offset] || 0
current_user = params[:current_user]
full = false
if params[:full] == true || params[:full] == 'true' || !params.key?(:full)
full = true
end
# try search index backend
if condition.blank? && SearchIndexBackend.enabled?
query_extention = {}
query_extention['bool'] = {}
query_extention['bool']['must'] = []
if current_user.permissions?('ticket.agent')
group_ids = current_user.group_ids_access('read')
access_condition = {
'query_string' => { 'default_field' => 'group_id', 'query' => "\"#{group_ids.join('" OR "')}\"" }
}
else
access_condition = if !current_user.organization || ( !current_user.organization.shared || current_user.organization.shared == false )
{
'query_string' => { 'default_field' => 'customer_id', 'query' => current_user.id }
}
# customer_id: XXX
# conditions = [ 'customer_id = ?', current_user.id ]
else
{
'query_string' => { 'query' => "customer_id:#{current_user.id} OR organization_id:#{current_user.organization.id}" }
}
# customer_id: XXX OR organization_id: XXX
# conditions = [ '( customer_id = ? OR organization_id = ? )', current_user.id, current_user.organization.id ]
end
# get params
query = params[:query]
condition = params[:condition]
limit = params[:limit] || 12
offset = params[:offset] || 0
current_user = params[:current_user]
full = false
if params[:full] == true || params[:full] == 'true' || !params.key?(:full)
full = true
end
query_extention['bool']['must'].push access_condition
# try search index backend
if condition.blank? && SearchIndexBackend.enabled?
query_extention = {}
query_extention['bool'] = {}
query_extention['bool']['must'] = []
items = SearchIndexBackend.search(query, limit, 'Ticket', query_extention, offset)
if current_user.permissions?('ticket.agent')
group_ids = current_user.group_ids_access('read')
access_condition = {
'query_string' => { 'default_field' => 'group_id', 'query' => "\"#{group_ids.join('" OR "')}\"" }
}
else
access_condition = if !current_user.organization || ( !current_user.organization.shared || current_user.organization.shared == false )
{
'query_string' => { 'default_field' => 'customer_id', 'query' => current_user.id }
}
# customer_id: XXX
# conditions = [ 'customer_id = ?', current_user.id ]
else
{
'query_string' => { 'query' => "customer_id:#{current_user.id} OR organization_id:#{current_user.organization.id}" }
}
# customer_id: XXX OR organization_id: XXX
# conditions = [ '( customer_id = ? OR organization_id = ? )', current_user.id, current_user.organization.id ]
end
end
query_extention['bool']['must'].push access_condition
items = SearchIndexBackend.search(query, limit, 'Ticket', query_extention, offset)
if !full
ids = []
items.each do |item|
ids.push item[:id]
end
return ids
end
tickets = []
items.each do |item|
ticket = Ticket.lookup(id: item[:id])
next if !ticket
tickets.push ticket
end
return tickets
end
# fallback do sql query
access_condition = Ticket.access_condition(current_user, 'read')
# do query
# - stip out * we already search for *query* -
if query
query.delete! '*'
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}%" )
.joins(:articles)
.order('tickets.created_at DESC')
.offset(offset)
.limit(limit)
else
query_condition, bind_condition, tables = selector2sql(condition)
tickets_all = Ticket.select('DISTINCT(tickets.id), tickets.created_at')
.joins(tables)
.where(access_condition)
.where(query_condition, *bind_condition)
.order('tickets.created_at DESC')
.offset(offset)
.limit(limit)
end
# build result list
if !full
ids = []
items.each do |item|
ids.push item[:id]
tickets_all.each do |ticket|
ids.push ticket.id
end
return ids
end
tickets = []
items.each do |item|
ticket = Ticket.lookup(id: item[:id])
next if !ticket
tickets.push ticket
end
return tickets
end
# fallback do sql query
access_condition = Ticket.access_condition(current_user, 'read')
# do query
# - stip out * we already search for *query* -
if query
query.delete! '*'
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}%" )
.joins(:articles)
.order('tickets.created_at DESC')
.offset(offset)
.limit(limit)
else
query_condition, bind_condition, tables = selector2sql(condition)
tickets_all = Ticket.select('DISTINCT(tickets.id), tickets.created_at')
.joins(tables)
.where(access_condition)
.where(query_condition, *bind_condition)
.order('tickets.created_at DESC')
.offset(offset)
.limit(limit)
end
# build result list
if !full
ids = []
tickets_all.each do |ticket|
ids.push ticket.id
tickets.push Ticket.lookup(id: ticket.id)
end
return ids
tickets
end
tickets = []
tickets_all.each do |ticket|
tickets.push Ticket.lookup(id: ticket.id)
end
tickets
end
end

View file

@ -1,5 +1,6 @@
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
module Ticket::SearchIndex
extend ActiveSupport::Concern
=begin

View file

@ -1,6 +1,4 @@
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
require 'signature_detection'
class Transaction::CtiCallerIdDetection
=begin

View file

@ -1,6 +1,4 @@
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
require 'signature_detection'
class Transaction::SignatureDetection
=begin
@ -46,14 +44,14 @@ class Transaction::SignatureDetection
return if type['name'] != 'email'
# update current signature of user id
SignatureDetection.rebuild_user(article.created_by_id)
::SignatureDetection.rebuild_user(article.created_by_id)
# user
user = User.lookup(id: article.created_by_id)
return if !user
return if !user.preferences
return if !user.preferences[:signature_detection]
line = SignatureDetection.find_signature_line_by_article(
line = ::SignatureDetection.find_signature_line_by_article(
user,
article
)

View file

@ -4,7 +4,6 @@ class Trigger < ApplicationModel
include ChecksConditionValidation
include CanSeed
load 'trigger/assets.rb'
include Trigger::Assets
store :condition

View file

@ -2,6 +2,7 @@
class Trigger
module Assets
extend ActiveSupport::Concern
=begin

View file

@ -1,28 +1,4 @@
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
require 'digest/md5'
# @model User
#
# @property id(required) [Integer] The identifier for the User.
# @property login(required) [String] The login of the User used for authentication.
# @property firstname [String] The firstname of the User.
# @property lastname [String] The lastname of the User.
# @property email [String] The email of the User.
# @property image [String] The Image used as the User avatar (TODO: Image model?).
# @property web [String] The website/URL of the User.
# @property password [String] The password of the User.
# @property phone [String] The phone number of the User.
# @property fax [String] The fax number of the User.
# @property mobile [String] The mobile number of the User.
# @property department [String] The department the User is working at.
# @property street [String] The street the User lives in.
# @property zip [Integer] The zip postal code of the User city.
# @property city [String] The city the User lives in.
# @property country [String] The country the User lives in.
# @property verified [Boolean] The flag that shows the verified state of the User.
# @property active [Boolean] The flag that shows the active state of the User.
# @property note [String] The note or comment stored to the User.
class User < ApplicationModel
include HasActivityStreamLog
include ChecksClientNotification
@ -31,12 +7,10 @@ class User < ApplicationModel
include CanCsvImport
include HasGroups
include HasRoles
include User::ChecksAccess
load 'user/assets.rb'
include User::ChecksAccess
include User::Assets
extend User::Search
load 'user/search_index.rb'
include User::Search
include User::SearchIndex
has_and_belongs_to_many :roles, after_add: %i[cache_update check_notifications], after_remove: :cache_update, before_add: %i[validate_agent_limit_by_role validate_roles], before_remove: :last_admin_check_by_role, class_name: 'Role'

View file

@ -2,6 +2,7 @@
class User
module Assets
extend ActiveSupport::Concern
=begin

View file

@ -2,6 +2,10 @@
class User
module Search
extend ActiveSupport::Concern
# methods defined here are going to extend the class, not the instance of it
class_methods do
=begin
@ -22,13 +26,13 @@ returns if user has no permissions to search
=end
def search_preferences(current_user)
return false if !current_user.permissions?('ticket.agent') && !current_user.permissions?('admin.user')
{
prio: 2000,
direct_search_index: true,
}
end
def search_preferences(current_user)
return false if !current_user.permissions?('ticket.agent') && !current_user.permissions?('admin.user')
{
prio: 2000,
direct_search_index: true,
}
end
=begin
@ -58,61 +62,62 @@ returns
=end
def search(params)
def search(params)
# get params
query = params[:query]
limit = params[:limit] || 10
offset = params[:offset] || 0
current_user = params[:current_user]
# get params
query = params[:query]
limit = params[:limit] || 10
offset = params[:offset] || 0
current_user = params[:current_user]
# enable search only for agents and admins
return [] if !search_preferences(current_user)
# enable search only for agents and admins
return [] if !search_preferences(current_user)
# lookup for roles of permission
if params[:permissions].present?
params[:role_ids] ||= []
role_ids = Role.with_permissions(params[:permissions]).pluck(:id)
params[:role_ids].concat(role_ids)
end
# lookup for roles of permission
if params[:permissions].present?
params[:role_ids] ||= []
role_ids = Role.with_permissions(params[:permissions]).pluck(:id)
params[:role_ids].concat(role_ids)
end
# try search index backend
if SearchIndexBackend.enabled?
query_extention = {}
if params[:role_ids].present?
query_extention['bool'] = {}
query_extention['bool']['must'] = []
if !params[:role_ids].is_a?(Array)
params[:role_ids] = [params[:role_ids]]
# try search index backend
if SearchIndexBackend.enabled?
query_extention = {}
if params[:role_ids].present?
query_extention['bool'] = {}
query_extention['bool']['must'] = []
if !params[:role_ids].is_a?(Array)
params[:role_ids] = [params[:role_ids]]
end
access_condition = {
'query_string' => { 'default_field' => 'role_ids', 'query' => "\"#{params[:role_ids].join('" OR "')}\"" }
}
query_extention['bool']['must'].push access_condition
end
access_condition = {
'query_string' => { 'default_field' => 'role_ids', 'query' => "\"#{params[:role_ids].join('" OR "')}\"" }
}
query_extention['bool']['must'].push access_condition
items = SearchIndexBackend.search(query, limit, 'User', query_extention, offset)
users = []
items.each do |item|
user = User.lookup(id: item[:id])
next if !user
users.push user
end
return users
end
items = SearchIndexBackend.search(query, limit, 'User', query_extention, offset)
users = []
items.each do |item|
user = User.lookup(id: item[:id])
next if !user
users.push user
end
return users
end
# fallback do sql query
# - stip out * we already search for *query* -
query.delete! '*'
users = if params[:role_ids]
User.joins(:roles).where('roles.id' => params[:role_ids]).where(
'(users.firstname LIKE ? OR users.lastname LIKE ? OR users.email LIKE ? OR users.login LIKE ?) AND users.id != 1', "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%"
).order('updated_at DESC').offset(offset).limit(limit)
else
User.where(
'(firstname LIKE ? OR lastname LIKE ? OR email LIKE ? OR login LIKE ?) AND id != 1', "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%"
).order('updated_at DESC').offset(offset).limit(limit)
end
users
# fallback do sql query
# - stip out * we already search for *query* -
query.delete! '*'
users = if params[:role_ids]
User.joins(:roles).where('roles.id' => params[:role_ids]).where(
'(users.firstname LIKE ? OR users.lastname LIKE ? OR users.email LIKE ? OR users.login LIKE ?) AND users.id != 1', "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%"
).order('updated_at DESC').offset(offset).limit(limit)
else
User.where(
'(firstname LIKE ? OR lastname LIKE ? OR email LIKE ? OR login LIKE ?) AND id != 1', "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%"
).order('updated_at DESC').offset(offset).limit(limit)
end
users
end
end
end
end

View file

@ -2,6 +2,7 @@
class User
module SearchIndex
extend ActiveSupport::Concern
=begin
@ -67,6 +68,5 @@ returns
attributes
end
end
end

View file

@ -1,7 +1,7 @@
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
require 'ldap'
require 'ldap/user'
require_dependency 'ldap'
require_dependency 'ldap/user'
class Auth
class Ldap < Auth::Base

View file

@ -1,4 +1,3 @@
#require 'iconv'
module Encode
def self.conv (charset, string)

View file

@ -1,7 +1,5 @@
# Copyright (C) 2012-2015 Zammad Foundation, http://zammad-foundation.org/
require 'koala'
class Facebook
attr_accessor :client, :account

View file

@ -1,4 +1,4 @@
require 'mixin/rails_logger'
require_dependency 'mixin/rails_logger'
module Import
class Exchange

View file

@ -1,7 +1,7 @@
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
require 'ldap'
require 'ldap/group'
require_dependency 'ldap'
require_dependency 'ldap/group'
module Import
class Ldap < Import::IntegrationBase

View file

@ -2,24 +2,24 @@
# in the importer folder require AND simultaniuos requiring
# of the same file in different threads so we need to
# require them ourself
require 'import/otrs/ticket'
require 'import/otrs/ticket_factory'
require 'import/otrs/article_customer'
require 'import/otrs/article_customer_factory'
require 'import/otrs/article'
require 'import/otrs/article_factory'
require 'import/otrs/article/attachment_factory'
require 'import/otrs/history'
require 'import/otrs/history_factory'
require 'import/otrs/history/article'
require 'import/otrs/history/move'
require 'import/otrs/history/new_ticket'
require 'import/otrs/history/priority_update'
require 'import/otrs/history/state_update'
require 'store'
require 'store/object'
require 'store/provider/db'
require 'store/provider/file'
require_dependency 'import/otrs/ticket'
require_dependency 'import/otrs/ticket_factory'
require_dependency 'import/otrs/article_customer'
require_dependency 'import/otrs/article_customer_factory'
require_dependency 'import/otrs/article'
require_dependency 'import/otrs/article_factory'
require_dependency 'import/otrs/article/attachment_factory'
require_dependency 'import/otrs/history'
require_dependency 'import/otrs/history_factory'
require_dependency 'import/otrs/history/article'
require_dependency 'import/otrs/history/move'
require_dependency 'import/otrs/history/new_ticket'
require_dependency 'import/otrs/history/priority_update'
require_dependency 'import/otrs/history/state_update'
require_dependency 'store'
require_dependency 'store/object'
require_dependency 'store/provider/db'
require_dependency 'store/provider/file'
module Import
module OTRS

View file

@ -1,7 +1,7 @@
# this require is required (hehe) because of Rails autoloading
# which causes strange behavior not inheriting correctly
# from Import::OTRS::DynamicField
require 'import/otrs/dynamic_field'
require_dependency 'import/otrs/dynamic_field'
module Import
module OTRS

View file

@ -1,7 +1,7 @@
# this require is required (hehe) because of Rails autoloading
# which causes strange behavior not inheriting correctly
# from Import::OTRS::DynamicField
require 'import/otrs/dynamic_field'
require_dependency 'import/otrs/dynamic_field'
module Import
module OTRS

View file

@ -1,4 +1,4 @@
require 'ticket'
require_dependency 'ticket'
module Import
module OTRS

View file

@ -1,7 +1,7 @@
# this require is required (hehe) because of Rails autoloading
# which causes strange behavior not inheriting correctly
# from Import::OTRS::DynamicField
require 'import/zendesk/object_attribute/base'
require_dependency 'import/zendesk/object_attribute/base'
module Import
class Zendesk

View file

@ -1,7 +1,7 @@
# this require is required (hehe) because of Rails autoloading
# which causes strange behavior not inheriting correctly
# from Import::OTRS::DynamicField
require 'import/zendesk/object_attribute/base'
require_dependency 'import/zendesk/object_attribute/base'
module Import
class Zendesk

View file

@ -1,7 +1,7 @@
# this require is required (hehe) because of Rails autoloading
# which causes strange behavior not inheriting correctly
# from Import::OTRS::DynamicField
require 'import/zendesk/object_attribute/base'
require_dependency 'import/zendesk/object_attribute/base'
module Import
class Zendesk

View file

@ -1,7 +1,7 @@
# this require is required (hehe) because of Rails autoloading
# which causes strange behavior not inheriting correctly
# from Import::OTRS::DynamicField
require 'import/zendesk/object_attribute/base'
require_dependency 'import/zendesk/object_attribute/base'
module Import
class Zendesk

View file

@ -1,7 +1,7 @@
# this require is required (hehe) because of Rails autoloading
# which causes strange behavior not inheriting correctly
# from Import::OTRS::DynamicField
require 'import/zendesk/object_attribute/base'
require_dependency 'import/zendesk/object_attribute/base'
module Import
class Zendesk

View file

@ -1,7 +1,7 @@
# this require is required (hehe) because of Rails autoloading
# which causes strange behavior not inheriting correctly
# from Import::OTRS::DynamicField
require 'import/zendesk/object_attribute/base'
require_dependency 'import/zendesk/object_attribute/base'
module Import
class Zendesk

View file

@ -1,7 +1,7 @@
# this require is required (hehe) because of Rails autoloading
# which causes strange behavior not inheriting correctly
# from Import::OTRS::DynamicField
require 'import/zendesk/object_attribute/base'
require_dependency 'import/zendesk/object_attribute/base'
module Import
class Zendesk

View file

@ -1,6 +1,6 @@
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
require 'net/ldap'
require 'net/ldap/entry'
require_dependency 'net/ldap'
require_dependency 'net/ldap/entry'
# Class for establishing LDAP connections. A wrapper around Net::LDAP needed for Auth and Sync.
# ATTENTION: Loads custom 'net/ldap/entry' from 'lib/core_ext' which extends the Net::LDAP::Entry class.

View file

@ -6,8 +6,8 @@ class Ldap
# an ::Ldap instance.
#
# @example
# require 'ldap'
# require 'ldap/group'
# require_dependency 'ldap'
# require_dependency 'ldap/group'
class Group
include Ldap::FilterLookup
@ -29,8 +29,8 @@ class Ldap
# @param ldap [Ldap] An optional existing Ldap class instance. Default is a new connection with given configuration.
#
# @example
# require 'ldap'
# require 'ldap/group'
# require_dependency 'ldap'
# require_dependency 'ldap/group'
# ldap_group = Ldap::Group.new
#
# @return [nil]

View file

@ -6,8 +6,8 @@ class Ldap
# an ::Ldap instance.
#
# @example
# require 'ldap'
# require 'ldap/user'
# require_dependency 'ldap'
# require_dependency 'ldap/user'
class User
include Ldap::FilterLookup
@ -76,8 +76,8 @@ class Ldap
# @param ldap [Ldap] An optional existing Ldap class instance. Default is a new connection with given configuration.
#
# @example
# require 'ldap'
# require 'ldap/user'
# require_dependency 'ldap'
# require_dependency 'ldap/user'
# ldap_user = Ldap::User.new
#
# @return [nil]

View file

@ -1,5 +1,5 @@
require 'ldap'
require 'ldap/user'
require_dependency 'ldap'
require_dependency 'ldap/user'
module MigrationJob
class LdapSamaccountnameToUid

View file

@ -1,5 +1,5 @@
require 'mixin/rails_logger'
require 'mixin/start_finish_logger'
require_dependency 'mixin/rails_logger'
require_dependency 'mixin/start_finish_logger'
class Sequencer
include ::Mixin::RailsLogger

View file

@ -1,4 +1,4 @@
require 'sequencer/mixin/prefixed_constantize'
require_dependency 'sequencer/mixin/prefixed_constantize'
class Sequencer
class Sequence

View file

@ -1,5 +1,5 @@
require 'mixin/rails_logger'
require 'mixin/start_finish_logger'
require_dependency 'mixin/rails_logger'
require_dependency 'mixin/start_finish_logger'
class Sequencer
class State

View file

@ -1,4 +1,4 @@
require 'sequencer/mixin/prefixed_constantize'
require_dependency 'sequencer/mixin/prefixed_constantize'
class Sequencer
class Unit

View file

@ -1,4 +1,4 @@
require 'mixin/rails_logger'
require_dependency 'mixin/rails_logger'
class Sequencer
class Unit

View file

@ -5,8 +5,12 @@ class Sequencer
module Mapping
class FlatKeys < Sequencer::Unit::Base
include ::Sequencer::Unit::Import::Common::Mapping::Mixin::ProvideMapped
prepend ::Sequencer::Unit::Import::Common::Model::Mixin::Skip::Action
skip_any_action
uses :resource
provides :mapped
def process
provide_mapped do

View file

@ -1,4 +1,4 @@
require 'sequencer/unit/import/common/model/mixin/handle_failure'
require_dependency 'sequencer/unit/import/common/model/mixin/handle_failure'
class Sequencer
class Unit

View file

@ -5,6 +5,9 @@ class Sequencer
module Model
module Associations
class Extract < Sequencer::Unit::Base
prepend ::Sequencer::Unit::Import::Common::Model::Mixin::Skip::Action
skip_any_action
uses :model_class, :mapped
provides :associations

View file

@ -8,7 +8,7 @@ class Sequencer
include ::Sequencer::Unit::Import::Common::Model::Mixin::HandleFailure
prepend ::Sequencer::Unit::Import::Common::Model::Mixin::Skip::Action
skip_action :skipped
skip_action :skipped, :failed
uses :mapped, :model_class
provides :instance

View file

@ -1,4 +1,4 @@
require 'sequencer/unit/import/common/model/mixin/handle_failure'
require_dependency 'sequencer/unit/import/common/model/mixin/handle_failure'
class Sequencer
class Unit

View file

@ -1,4 +1,4 @@
require 'sequencer/unit/common/mixin/dynamic_attribute'
require_dependency 'sequencer/unit/common/mixin/dynamic_attribute'
class Sequencer
class Unit

View file

@ -1,4 +1,4 @@
require 'sequencer/unit/common/mixin/dynamic_attribute'
require_dependency 'sequencer/unit/common/mixin/dynamic_attribute'
class Sequencer
class Unit

View file

@ -1,5 +1,4 @@
require 'sequencer/unit/import/common/model/statistics/mixin/action_diff'
require_dependency 'sequencer/unit/import/common/model/statistics/mixin/action_diff'
class Sequencer
class Unit
module Import

View file

@ -1,4 +1,4 @@
require 'sequencer/unit/import/common/model/statistics/mixin/action_diff'
require_dependency 'sequencer/unit/import/common/model/statistics/mixin/action_diff'
class Sequencer
class Unit

View file

@ -1,4 +1,4 @@
require 'sequencer/unit/import/common/model/statistics/mixin/action_diff'
require_dependency 'sequencer/unit/import/common/model/statistics/mixin/common'
class Sequencer
class Unit

Some files were not shown because too many files have changed in this diff Show more