summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorStefan Wintermeyer <stefan.wintermeyer@amooma.de>2013-01-20 20:57:35 +0100
committerStefan Wintermeyer <stefan.wintermeyer@amooma.de>2013-01-20 20:57:35 +0100
commit4e67f8769a3a3199bfb5b363fe9baa231c329a2b (patch)
tree3479e67255b6612e1eca50245bb886680d305eb7 /app
parenta2abe7dffb8fe31687910ca4be6dc0374a247d00 (diff)
Refactoring
Diffstat (limited to 'app')
-rw-r--r--app/controllers/tenants_controller.rb19
-rw-r--r--app/models/gateway.rb7
-rw-r--r--app/models/tenant.rb11
-rw-r--r--app/views/gateways/_index_core.html.haml34
-rw-r--r--app/views/tenants/_admin_area.de.html.haml32
-rw-r--r--app/views/tenants/_admin_area.html.haml24
-rw-r--r--app/views/tenants/show.html.haml4
7 files changed, 59 insertions, 72 deletions
diff --git a/app/controllers/tenants_controller.rb b/app/controllers/tenants_controller.rb
index 7bb8ecd..cb67e5f 100644
--- a/app/controllers/tenants_controller.rb
+++ b/app/controllers/tenants_controller.rb
@@ -1,13 +1,17 @@
class TenantsController < ApplicationController
- load_and_authorize_resource :tenant
+ authorize_resource :tenant
def index
+ @tenants = Tenant.scoped
end
def show
+ @tenant = Tenant.find(params[:id])
+ @gateways = Gateway.order(:updated_at)
end
def new
+ @tenant = Tenant.new
@tenant.name = generate_a_new_name(@tenant)
@tenant.sip_domain = SipDomain.last
@tenant.country = GemeinschaftSetup.first.country
@@ -18,6 +22,8 @@ class TenantsController < ApplicationController
end
def create
+ @tenant = Tenant.new(tenant_params)
+
if @tenant.save
# Become a member of this tenant.
#
@@ -86,10 +92,12 @@ class TenantsController < ApplicationController
end
def edit
+ @tenant = Tenant.find(params[:id])
end
def update
- if @tenant.update_attributes(params[:tenant])
+ @tenant = Tenant.find(params[:id])
+ if @tenant.update_attributes(tenant_params)
redirect_to @tenant, :notice => t('tenants.controller.successfuly_updated')
else
render :edit
@@ -97,8 +105,15 @@ class TenantsController < ApplicationController
end
def destroy
+ @tenant = Tenant.find(params[:id])
@tenant.destroy
redirect_to tenants_url, :notice => t('tenants.controller.successfuly_destroyed')
end
+
+ private
+ def tenant_params
+ params.require(:tenant).permit(:name, :description, :sip_domain_id, :country_id, :language_id, :from_field_pin_change_email, :from_field_voicemail_email
+)
+ end
end
diff --git a/app/models/gateway.rb b/app/models/gateway.rb
index 21dc831..3e791a6 100644
--- a/app/models/gateway.rb
+++ b/app/models/gateway.rb
@@ -14,6 +14,7 @@ class Gateway < ActiveRecord::Base
:presence => true,
:inclusion => { :in => TECHNOLOGIES }
+ after_initialize :set_defaults
before_validation :downcase_technology
def to_s
@@ -25,4 +26,10 @@ class Gateway < ActiveRecord::Base
self.technology = self.technology.downcase if !self.technology.blank?
end
+ def set_defaults
+ if TECHNOLOGIES.count == 1
+ self.technology = TECHNOLOGIES.first
+ end
+ end
+
end
diff --git a/app/models/tenant.rb b/app/models/tenant.rb
index c3e2926..419ac3a 100644
--- a/app/models/tenant.rb
+++ b/app/models/tenant.rb
@@ -1,15 +1,8 @@
# encoding: UTF-8
class Tenant < ActiveRecord::Base
- attr_accessible :name, :description, :sip_domain_id, :country_id, :language_id, :from_field_pin_change_email, :from_field_voicemail_email
-
- if GsParameter.get('STRICT_INTERNAL_EXTENSION_HANDLING') == true
- attr_accessible :internal_extension_ranges
- end
-
- if GsParameter.get('STRICT_DID_HANDLING') == true
- attr_accessible :did_list
- end
+ # https://github.com/rails/strong_parameters
+ include ActiveModel::ForbiddenAttributesProtection
# Associations:
#
diff --git a/app/views/gateways/_index_core.html.haml b/app/views/gateways/_index_core.html.haml
index 21414c3..dd2d1f5 100644
--- a/app/views/gateways/_index_core.html.haml
+++ b/app/views/gateways/_index_core.html.haml
@@ -1,17 +1,19 @@
-%table
- %tr
- %th= t('gateways.index.name')
- %th= t('gateways.index.technology')
- %th= t('gateways.index.inbound')
- %th= t('gateways.index.outbound')
- %th= t('gateways.index.description')
+- cache(['gateways_table', gateways.count, gateways.first, gateways.last]) do
+ %table
+ %tr
+ %th= t('gateways.index.name')
+ %th= t('gateways.index.technology')
+ %th= t('gateways.index.inbound')
+ %th= t('gateways.index.outbound')
+ %th= t('gateways.index.description')
- - reset_cycle
- - for gateway in gateways
- %tr{:class => cycle('odd', 'even')}
- %td= gateway.name
- %td= gateway.technology
- %td= gateway.inbound
- %td= gateway.outbound
- %td= gateway.description
- =render :partial => 'shared/index_view_edit_destroy_part', :locals => {:child => gateway} \ No newline at end of file
+ - reset_cycle
+ - for gateway in gateways
+ %tr{:class => cycle('odd', 'even')}
+ - cache(['gateway_single_table_row_within_tr', gateway, gateways.count]) do
+ %td= gateway.name
+ %td= gateway.technology
+ %td= gateway.inbound
+ %td= gateway.outbound
+ %td= gateway.description
+ =render :partial => 'shared/index_view_edit_destroy_part', :locals => {:child => gateway} \ No newline at end of file
diff --git a/app/views/tenants/_admin_area.de.html.haml b/app/views/tenants/_admin_area.de.html.haml
deleted file mode 100644
index 6a4bef9..0000000
--- a/app/views/tenants/_admin_area.de.html.haml
+++ /dev/null
@@ -1,32 +0,0 @@
-= render :partial => 'tenants/sip_accounts_and_phones', :locals => {:tenant => @tenant}
-
-= render :partial => 'users_table', :locals => {:tenant => @tenant}
-
-= render :partial => 'user_groups_table', :locals => {:tenant => @tenant}
-
-%h2 Features
-= render :partial => 'tenants/table_of_functions', :locals => {:tenant => @tenant}
-
-= render :partial => 'tenants/table_of_phone_books', :locals => {:tenant => @tenant}
-
-%h2 Gemeinschaft Konfiguration
-= render :partial => 'tenants/gs_parameter_table', :locals => {:tenant => @tenant}
-
-%p
- Das System kann
- = PhoneModel.count
- verschiedene Telefonmodelle von den folgenden Herstellern verwalten:
- - Manufacturer.all.each do |manufacturer|
- - if manufacturer != Manufacturer.last && manufacturer != Manufacturer.limit(Manufacturer.count - 1).last
- = succeed ', ' do
- =link_to manufacturer, manufacturer_path(manufacturer)
- - elsif manufacturer == Manufacturer.limit(Manufacturer.count - 1).last
- = succeed ' und ' do
- =link_to manufacturer, manufacturer_path(manufacturer)
- - else
- = succeed '.' do
- =link_to manufacturer, manufacturer_path(manufacturer)
-
-= render :partial => 'call_routes', :locals => {:tenant => @tenant}
-
-= render :partial => 'gateways', :locals => {:tenant => @tenant} \ No newline at end of file
diff --git a/app/views/tenants/_admin_area.html.haml b/app/views/tenants/_admin_area.html.haml
index b974c02..7e7e46b 100644
--- a/app/views/tenants/_admin_area.html.haml
+++ b/app/views/tenants/_admin_area.html.haml
@@ -1,30 +1,32 @@
-= render :partial => 'tenants/sip_accounts_and_phones', :locals => {:tenant => @tenant}
+= render :partial => 'tenants/sip_accounts_and_phones', :locals => {:tenant => tenant}
-= render :partial => 'users_table', :locals => {:tenant => @tenant}
+= render :partial => 'users_table', :locals => {:tenant => tenant}
-= render :partial => 'user_groups_table', :locals => {:tenant => @tenant}
+= render :partial => 'user_groups_table', :locals => {:tenant => tenant}
%h2 Features
-= render :partial => 'tenants/table_of_functions', :locals => {:tenant => @tenant}
+= render :partial => 'tenants/table_of_functions', :locals => {:tenant => tenant}
-= render :partial => 'tenants/table_of_phone_books', :locals => {:tenant => @tenant}
+= render :partial => 'tenants/table_of_phone_books', :locals => {:tenant => tenant}
-%h2 Gemeinschaft Configuration
-= render :partial => 'tenants/gs_parameter_table', :locals => {:tenant => @tenant}
+%h2 Gemeinschaft Konfiguration
+= render :partial => 'tenants/gs_parameter_table', :locals => {:tenant => tenant}
%p
- This system can setup
+ Das System kann
= PhoneModel.count
- different phone models from the manufacturers
+ verschiedene Telefonmodelle von den folgenden Herstellern verwalten:
- Manufacturer.all.each do |manufacturer|
- if manufacturer != Manufacturer.last && manufacturer != Manufacturer.limit(Manufacturer.count - 1).last
= succeed ', ' do
=link_to manufacturer, manufacturer_path(manufacturer)
- elsif manufacturer == Manufacturer.limit(Manufacturer.count - 1).last
- = succeed ' and ' do
+ = succeed ' und ' do
=link_to manufacturer, manufacturer_path(manufacturer)
- else
= succeed '.' do
=link_to manufacturer, manufacturer_path(manufacturer)
-= render :partial => 'call_routes', :locals => {:tenant => @tenant} \ No newline at end of file
+= render :partial => 'call_routes', :locals => {:tenant => tenant}
+
+= render :partial => 'gateways', :locals => {:tenant => tenant, :gateways => gateways} \ No newline at end of file
diff --git a/app/views/tenants/show.html.haml b/app/views/tenants/show.html.haml
index f5cff5f..9b9d4ec 100644
--- a/app/views/tenants/show.html.haml
+++ b/app/views/tenants/show.html.haml
@@ -7,5 +7,5 @@
= render :partial => 'shared/show_edit_destroy_part', :locals => { :child => @tenant }
-- if @tenant.user_groups.where(:name => 'Admins').count > 0 && @tenant.user_groups.where(:name => 'Admins').first.users.include?(current_user)
- = render 'admin_area' \ No newline at end of file
+- if @tenant.user_groups.where(:name => 'Admins').any? && @tenant.user_groups.where(:name => 'Admins').first.users.include?(current_user)
+ = render :partial => 'admin_area', :locals => { :tenant => @tenant, :gateways => @gateways} \ No newline at end of file