summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/ability.rb4
-rw-r--r--app/models/call_history.rb16
-rw-r--r--app/models/call_route.rb11
-rw-r--r--app/models/fax_document.rb4
-rw-r--r--app/models/gateway.rb2
-rw-r--r--app/models/gateway_setting.rb10
-rw-r--r--app/models/gemeinschaft_setup.rb8
-rw-r--r--app/models/sip_account.rb2
-rw-r--r--app/models/sip_registration.rb21
-rw-r--r--app/models/user.rb13
10 files changed, 85 insertions, 6 deletions
diff --git a/app/models/ability.rb b/app/models/ability.rb
index b846af0..0d13dab 100644
--- a/app/models/ability.rb
+++ b/app/models/ability.rb
@@ -82,6 +82,10 @@ class Ability
#
cannot [:create, :destroy], GsParameter
cannot [:create, :destroy], GuiFunction
+
+ # An admin can not destroy his/her account
+ #
+ cannot [:destroy], User, :id => user.id
else
# Any user can do the following stuff.
#
diff --git a/app/models/call_history.rb b/app/models/call_history.rb
index 4db056a..81342bd 100644
--- a/app/models/call_history.rb
+++ b/app/models/call_history.rb
@@ -3,6 +3,9 @@ class CallHistory < ActiveRecord::Base
belongs_to :caller_account, :polymorphic => true
belongs_to :callee_account, :polymorphic => true
belongs_to :auth_account, :polymorphic => true
+
+ validates :start_stamp,
+ :presence => true
def display_number
if self.entry_type == 'dialed'
@@ -78,10 +81,11 @@ class CallHistory < ActiveRecord::Base
end
def display_call_date(date_format, date_today_format)
- if self.start_stamp.strftime('%Y%m%d') == DateTime::now.strftime('%Y%m%d')
+ if self.start_stamp.to_date == Date.today
return self.start_stamp.strftime(date_today_format)
+ else
+ return self.start_stamp.strftime(date_format)
end
- return self.start_stamp.strftime(date_format)
end
def display_duration
@@ -129,6 +133,14 @@ class CallHistory < ActiveRecord::Base
end
+ def voicemail_message?
+ begin
+ return self.call_historyable.voicemail_messages.where(:forwarded_by => self.caller_channel_uuid).any?
+ rescue
+ return nil
+ end
+ end
+
def voicemail_message
begin
return self.call_historyable.voicemail_messages.where(:forwarded_by => self.caller_channel_uuid).first
diff --git a/app/models/call_route.rb b/app/models/call_route.rb
index 28120c1..b4496ab 100644
--- a/app/models/call_route.rb
+++ b/app/models/call_route.rb
@@ -238,4 +238,15 @@ class CallRoute < ActiveRecord::Base
end
end
end
+
+ def endpoint
+ if self.endpoint_id.to_i > 0
+ begin
+ return self.endpoint_type.camelize.constantize.where(:id => self.endpoint_id.to_i).first
+ rescue
+ return nil
+ end
+ end
+ end
+
end
diff --git a/app/models/fax_document.rb b/app/models/fax_document.rb
index 080bdaa..be689e2 100644
--- a/app/models/fax_document.rb
+++ b/app/models/fax_document.rb
@@ -52,7 +52,6 @@ class FaxDocument < ActiveRecord::Base
name
end
- private
def render_thumbnails
directory = "/tmp/GS-#{GsParameter.get('GEMEINSCHAFT_VERSION')}/fax_thumbnails/#{self.id}"
system('mkdir -p ' + directory)
@@ -66,7 +65,8 @@ class FaxDocument < ActiveRecord::Base
system("rm -rf #{directory}")
self.update_attributes(:document_total_pages => number_of_thumbnails) if self.document_total_pages.nil?
end
-
+
+ private
def convert_pdf_to_tiff
page_size_a4 = '595 842'
page_size_command = "<< /Policies << /PageSize 3 >> /InputAttributes currentpagedevice /InputAttributes get dup { pop 1 index exch undef } forall dup 0 << /PageSize [ #{page_size_a4} ] >> put >> setpagedevice"
diff --git a/app/models/gateway.rb b/app/models/gateway.rb
index 3e791a6..a8df41f 100644
--- a/app/models/gateway.rb
+++ b/app/models/gateway.rb
@@ -1,5 +1,5 @@
class Gateway < ActiveRecord::Base
- TECHNOLOGIES = ['sip']
+ TECHNOLOGIES = ['sip', 'xmpp']
attr_accessible :name, :technology, :inbound, :outbound, :description
diff --git a/app/models/gateway_setting.rb b/app/models/gateway_setting.rb
index c01f0a8..e3eaadb 100644
--- a/app/models/gateway_setting.rb
+++ b/app/models/gateway_setting.rb
@@ -11,6 +11,16 @@ class GatewaySetting < ActiveRecord::Base
'auth_pattern' => 'String',
'number_source' => 'String',
},
+ 'xmpp' => {
+ 'server' => 'String',
+ 'login' => 'String',
+ 'password' => 'String',
+ 'inbound_number' => 'String',
+ 'auth_source' => 'String',
+ 'auth_pattern' => 'String',
+ 'number_source' => 'String',
+ 'destination_domain' => 'String',
+ },
}
attr_accessible :gateway_id, :name, :value, :class_type, :description
diff --git a/app/models/gemeinschaft_setup.rb b/app/models/gemeinschaft_setup.rb
index 6056236..4b4dd37 100644
--- a/app/models/gemeinschaft_setup.rb
+++ b/app/models/gemeinschaft_setup.rb
@@ -6,6 +6,14 @@ class GemeinschaftSetup < ActiveRecord::Base
belongs_to :country
belongs_to :language
+ validates :default_company_name,
+ :presence => true,
+ :uniqueness => true
+
+ validates :default_system_email,
+ :presence => true,
+ :uniqueness => true
+
# Remove the cache which was created by the heater rake task.
#
after_create :expire_cache
diff --git a/app/models/sip_account.rb b/app/models/sip_account.rb
index d35f9b4..444eb12 100644
--- a/app/models/sip_account.rb
+++ b/app/models/sip_account.rb
@@ -133,7 +133,7 @@ class SipAccount < ActiveRecord::Base
end
def registration
- return FreeswitchRegistration.where(:reg_user => self.auth_name).first
+ return SipRegistration.where(:sip_user => self.auth_name).first
end
def call( phone_number )
diff --git a/app/models/sip_registration.rb b/app/models/sip_registration.rb
new file mode 100644
index 0000000..b668301
--- /dev/null
+++ b/app/models/sip_registration.rb
@@ -0,0 +1,21 @@
+class SipRegistration < ActiveRecord::Base
+ # Makes sure that this is a readonly model.
+ def readonly?
+ return true
+ end
+
+ # Prevent objects from being destroyed
+ def before_destroy
+ raise ActiveRecord::ReadOnlyRecord
+ end
+
+ # Prevent objects from being deleted
+ def self.delete_all
+ raise ActiveRecord::ReadOnlyRecord
+ end
+
+ # Prevent objects from being deleted
+ def delete
+ raise ActiveRecord::ReadOnlyRecord
+ end
+end
diff --git a/app/models/user.rb b/app/models/user.rb
index b902b99..afb3f04 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -95,6 +95,8 @@ class User < ActiveRecord::Base
before_destroy :destroy_or_logout_phones
+ after_save :become_a_member_of_default_user_groups
+
def destroy
clean_whitelist_entries
super
@@ -142,6 +144,9 @@ class User < ActiveRecord::Base
self.pin_hash == Digest::SHA2.hexdigest( "#{self.pin_salt}#{entered_pin}" )
end
+ def admin?
+ self.user_groups.include?(UserGroup.find(2))
+ end
private
@@ -207,4 +212,12 @@ class User < ActiveRecord::Base
end
end
+ # Normaly a new user should become a member of default user groups.
+ #
+ def become_a_member_of_default_user_groups
+ UserGroup.where(:id => GsParameter.get('DEFAULT_USER_GROUPS_IDS')).each do |user_group|
+ user_group.user_group_memberships.create(:user_id => self.id)
+ end
+ end
+
end