Skip to content

Commit

Permalink
Controller and views for Site
Browse files Browse the repository at this point in the history
  • Loading branch information
daronco committed Nov 23, 2012
1 parent d4748c2 commit 41532b6
Show file tree
Hide file tree
Showing 21 changed files with 253 additions and 54 deletions.
24 changes: 24 additions & 0 deletions app/controllers/sites_controller.rb
@@ -0,0 +1,24 @@
class SitesController < ApplicationController
before_filter :authenticate_user!

respond_to :html

def show
@site = Site.current # TODO: remove after cancan
respond_with(@site)
end

def edit
@site = Site.current # TODO: remove after cancan
respond_with(@site)
end

def update
@site = Site.current # TODO: remove after cancan
if @site.update_attributes(params[:site])
respond_with(@site, :location => site_path)
else
respond_with(@site, :location => edit_site_path(@site))
end
end
end
11 changes: 11 additions & 0 deletions app/inputs/showable_password_input.rb
@@ -0,0 +1,11 @@
class ShowablePasswordInput < SimpleForm::Inputs::PasswordInput
include ActionView::Helpers::FormTagHelper

def input
field = @builder.password_field(attribute_name, input_html_options)
cb_name = attribute_name.to_s + '_show'
cb = check_box_tag cb_name, 'show', false, :class => 'showable_password_show'
cb_label = label_tag cb_name, I18n.t('show_question'), :class => 'showable_password_show_label'
"#{field}#{cb}#{cb_label}".html_safe
end
end
2 changes: 1 addition & 1 deletion app/models/site.rb
Expand Up @@ -6,7 +6,7 @@ class Site < ActiveRecord::Base

# Returns the current (default) Site
def self.current
Site.where(:current => true).first
first || create
end

# HTTP protocol based on SSL settings
Expand Down
35 changes: 35 additions & 0 deletions app/views/sites/edit.html.haml
@@ -0,0 +1,35 @@
-# = render :partial => 'manage/menu'
-# = content_for :sidebar do
-# .affix-top{ :"data-spy" => "affix", :"data-offset-top" => "160" }
-# = link_to t('save'), "#form-edit-site", :class => "btn btn-primary btn-block submit-form"
#manage
= simple_form_for @site, :url => site_path, :html => { :id => "form-edit-site", :method => :put, :multipart => true, :class => 'single-column' } do |f|
.left-column
= f.input :name
= f.input :description, :as => :text, :input_html => { :rows => 5 }
= f.input :domain
= f.input :locale, :collection => I18n.available_locales
= f.input :signature, :as => :text, :input_html => { :rows => 5 }
= f.input :feedback_url
= f.input :analytics_code
= f.input :shib_enabled, :as => :boolean
= f.input :shib_email_field
= f.input :shib_name_field
.right-column
= f.input :smtp_user_name
= f.input :smtp_password, :as => :showable_password
= f.input :smtp_sender
= f.input :smtp_domain
= f.input :smtp_server
= f.input :smtp_port
= f.input :smtp_auto_tls
= f.input :smtp_auth_type
= f.input :exception_notifications, :as => :boolean
= f.input :exception_notifications_email
= f.input :exception_notifications_prefix
= f.input :chat_enabled, :as => :boolean
= f.input :xmpp_domain
= f.input :xmpp_server
= f.button :submit
34 changes: 34 additions & 0 deletions app/views/sites/show.html.haml
@@ -0,0 +1,34 @@
-# = render :partial => 'manage/menu'
-# = content_for :sidebar do
-# .affix-top{ :"data-spy" => "affix", :"data-offset-top" => "160" }
-# = link_to t('button.edit'), edit_site_path, :class => "btn btn-primary btn-block"
#manage
= simple_form_for @site, :url => "", :html => { :class => 'single-column' } do |f|
.left-column
= f.input :name, :disabled => true
= f.input :description, :as => :text, :input_html => { :rows => 5 }, :disabled => true
= f.input :domain, :disabled => true
= f.input :locale, :collection => I18n.available_locales, :disabled => true
= f.input :signature, :as => :text, :input_html => { :rows => 5 }, :disabled => true
= f.input :feedback_url, :disabled => true
= f.input :analytics_code, :disabled => true
= f.input :shib_enabled, :as => :boolean, :disabled => true
= f.input :shib_email_field, :disabled => true
= f.input :shib_name_field, :disabled => true
.right-column
= f.input :smtp_user_name, :disabled => true
= f.input :smtp_password, :disabled => true
= f.input :smtp_sender, :disabled => true
= f.input :smtp_domain, :disabled => true
= f.input :smtp_server, :disabled => true
= f.input :smtp_port, :disabled => true
= f.input :smtp_auto_tls, :disabled => true
= f.input :smtp_auth_type, :disabled => true
= f.input :exception_notifications, :as => :boolean, :disabled => true
= f.input :exception_notifications_email, :disabled => true
= f.input :exception_notifications_prefix, :disabled => true
= f.input :chat_enabled, :as => :boolean, :disabled => true
= f.input :xmpp_domain, :disabled => true
= f.input :xmpp_server, :disabled => true
6 changes: 3 additions & 3 deletions config/application.yml.example
Expand Up @@ -9,19 +9,19 @@ default:
description: "Mconf Website" # Website description
domain: "localhost" # Your server's IP or name address
locale: "en" # This will be the default locale for the application
smtp_login: "username@gmail.com"
smtp_user_name: "username@gmail.com"
smtp_password: "secret-password"

# Configurations for each environment
# You can find below the sections for each environment available.
# Uncomment the lines from one of them to define specific configurations for that environment.
# You can copy any of the parameters from the default section and override them here.
# Remember to copy the entire sections: if you want to override "site.smtp_login" and
# Remember to copy the entire sections: if you want to override "site.smtp_user_name" and
# "admin.username", you must do something like:
#
# development:
# site:
# smtp_login: "override the SMTP login"
# smtp_user_name: "override the SMTP login"
# admin:
# username: "my-special-admin"
#
Expand Down
5 changes: 4 additions & 1 deletion config/initializers/devise.rb
Expand Up @@ -4,7 +4,10 @@
# ==> Mailer Configuration
# Configure the e-mail address which will be shown in Devise::Mailer,
# note that it will be overwritten if you use your own mailer class with default "from" parameter.
config.mailer_sender = configatron.sendmail.username
if Site.table_exists? and Site.current and
Site.current.respond_to?(:smtp_user_name)
config.mailer_sender = Site.current.smtp_user_name
end

# Configure the class responsible to send e-mails.
# config.mailer = "Devise::Mailer"
Expand Down
9 changes: 3 additions & 6 deletions config/initializers/smtp.rb
Expand Up @@ -14,7 +14,7 @@
:domain => nil,
:enable_starttls_auto => false,
:authentication => nil,
:tls => false,
:tls => false, # always false, see http://www.redmine.org/issues/11034
:user_name => nil,
:password => nil
}
Expand All @@ -34,11 +34,8 @@
if site.respond_to?(:smtp_auth_type) and not site.smtp_auth_type.blank?
settings[:authentication] = site.smtp_auth_type
end
if site.respond_to?(:smtp_use_tls) and not site.smtp_use_tls.blank?
settings[:tls] = true
end
if site.respond_to?(:smtp_login) and not site.smtp_login.blank?
settings[:user_name] = site.smtp_login
if site.respond_to?(:smtp_user_name) and not site.smtp_user_name.blank?
settings[:user_name] = site.smtp_user_name
end
if site.respond_to?(:smtp_password) and not site.smtp_password.blank?
settings[:password] = site.smtp_password
Expand Down
56 changes: 45 additions & 11 deletions config/locales/en/_simple_form.yml
@@ -1,4 +1,37 @@
en:
activerecord:
models:
site: "Site"
user: "User"
attributes:
user:
login: "Username or email"
site:
analytics_code: "Analytics Code"
chat_enabled: "Enable Chat"
description: "Description"
domain: "Application Domain"
exception_notifications: "Send email on error"
exception_notifications_email: "Debug emails recipients"
exception_notifications_prefix: "Debug emails subject prefix"
feedback_url: "Feedback URL"
locale: "Language"
name: "Name"
shib_email_field: "Shibboleth field for email"
shib_enabled: "Enable Shibboleth"
shib_name_field: "Shibboleth field for name"
signature: Signature
smtp_auth_type: STMP authentication type
smtp_auto_tls: Auto start TLS in SMTP
smtp_domain: STMP domain
smtp_user_name: SMTP login
smtp_password: SMTP password
smtp_port: SMTP port
smtp_sender: SMTP sender
smtp_server: SMTP server
xmpp_domain: "XMPP Chat Domain"
xmpp_server: "XMPP Server Address"

simple_form:
"yes": 'Yes'
"no": 'No'
Expand All @@ -10,14 +43,15 @@ en:
# html: '<abbr title="required">*</abbr>'
error_notification:
default_message: "Some errors were found, please take a look:"
# Labels and hints examples
# labels:
# password: 'Password'
# user:
# new:
# email: 'E-mail para efetuar o sign in.'
# edit:
# email: 'E-mail.'
# hints:
# username: 'User name to sign in.'
# password: 'No special characters, please.'
hints:
site:
analytics_code: "Code for your Google Analytics account. Leave it blank to disable. Example: \"UA-12345678-9\""
exception_notifications: "Send debugging emails whenever the application crashes."
exception_notifications_email: "Use either spaces, commas or semi-colons to separate different emails."
feedback_url: "The users will be redirected to this URL when they log out of a webconference. If not set they are redirected to the default URL."
shib_email_field: "When a user authenticates in a Shibboleth service provider this field will be used to obtain the user's email. Example: Shib-inetOrgPerson-mail"
shib_name_field: "When a user authenticates in a Shibboleth service provider this field will be used to obtain the user's name. Example: Shib-inetOrgPerson-sn"
smtp_user_name: "The login email to your SMTP server."
smtp_password: "The password for your email account in your SMTP server."
xmpp_domain: "Domain used to identify the XMPP server (e.g. \"myserver.com\")."
xmpp_server: "Address where's located the XMPP server (e.g. http://myserver.com:5280/http-bind)."
7 changes: 0 additions & 7 deletions config/locales/en/mconf.yml
Expand Up @@ -9,10 +9,3 @@ en:
set:
error: "Unable to change language to \"%{lang}\""
success: "Language changed to \"%{lang}\""

activerecord:
models:
user: "User"
attributes:
user:
login: "Username or email"
45 changes: 45 additions & 0 deletions config/locales/pt-BR/_simple_form.yml
@@ -1,4 +1,37 @@
pt-BR:
activerecord:
models:
site: "Site"
user: "Usuário"
attributes:
user:
login: "Usuário ou e-mail"
site:
analytics_code: "Código do Google Analytics"
chat_enabled: "Habilitar Chat"
description: "Descrição"
domain: "Domínio da Aplicação"
exception_notifications: "Enviar e-mails de depuração"
exception_notifications_email: "Destinatários dos e-mails de depuração"
exception_notifications_prefix: "Prefixo no assunto dos e-mails de depuração"
feedback_url: "Feedback URL"
locale: "Idioma"
name: "Nome"
shib_email_field: "Campo Shibboleth para email"
shib_enabled: "Habilitar Shibboleth"
shib_name_field: "Campo Shibboleth para nome"
signature: Assinatura
smtp_auth_type: "Tipo de autenticação STMP"
smtp_auto_tls: "Auto-iniciar TLS no SMTP"
smtp_domain: "Domínio STMP"
smtp_user_name: "Login SMTP"
smtp_password: Senha SMTP
smtp_port: Porta SMTP
smtp_sender: Remetente SMTP
smtp_server: Servidor SMTP
xmpp_domain: "Domínio do servidor XMPP"
xmpp_server: "Endereço do servidor XMPP"

simple_form:
"yes": 'Sim'
"no": 'Não'
Expand All @@ -7,3 +40,15 @@ pt-BR:
mark: '*'
error_notification:
default_message: "Alguns erros foram encontrados, veja abaixo:"
hints:
site:
analytics_code: "Código para sua conta do Google Analytics. Deixe em branco para desabilitar. Exemplo: \"UA-12345678-9\""
exception_notifications: "Enviar e-mails de depuração sempre que ocorrer um erro grave na aplicação."
exception_notifications_email: "Use espaços, vírgulas ou ponto-e-vírgulas para separar diferentes e-mails."
feedback_url: "Os usuários serão redirecionados para esta URL quando eles sairem de uma conferência. Se o campo ficar em branco, eles serão redirecionados para '%{default_url}'."
shib_email_field: "Quando um usuário se autentica em provedor de serviços Shibboleth este campo será utilizado para obter o e-mail do usuário. Exemplo: Shib-inetOrgPerson-mail"
shib_name_field: "Quando um usuário se autentica em provedor de serviços Shibboleth este campo será utilizado para obter o nome do usuário. Exemplo: Shib-inetOrgPerson-sn"
smtp_user_name: "O e-mail de login no servidor SMTP."
smtp_password: "A senha para sua conta de e-mail no servidor SMTP."
xmpp_domain: "Domínio usado para identificar o servidor XMPP (e.g. \"myserver.com\")."
xmpp_server: "Endereço onde está localizado o servidor XMPP (e.g. http://myserver.com:5280/http-bind)."
7 changes: 0 additions & 7 deletions config/locales/pt-BR/mconf.yml
Expand Up @@ -9,10 +9,3 @@ pt-BR:
set:
error: "Não foi possível mudar a linguagem para \"%{lang}\""
success: "Linguagem modificada para \"%{lang}\""

activerecord:
models:
user: "Usuário"
attributes:
user:
login: "Usuário ou e-mail"
9 changes: 6 additions & 3 deletions config/routes.rb
Expand Up @@ -3,7 +3,10 @@
get "home", :to => "home#index", :as => "home"
root :to => "home#index"

# devise
# Set locale
match "locale/set/:id", :to => "locales#set", :as => "set_locale"

# Devise
# controllers = { :sessions => "sessions", :registrations => "registrations" }
paths = { :sign_in => "login", :sign_out => "logout", :sign_up => "signup" }
devise_for :users, :path_names => paths #, :controllers => controllers
Expand All @@ -19,7 +22,7 @@
:controllers => controllers,
:as => "bigbluebutton"

# Set locale
match "locale/set/:id", :to => "locales#set", :as => "set_locale"
# The unique Site is created in db/seeds and can only be edited
resource :site, :only => [:show, :edit, :update]

end
5 changes: 2 additions & 3 deletions db/migrate/20121119224920_create_sites.rb
Expand Up @@ -8,7 +8,6 @@ def up
t.string :locale
t.string :feedback_url
t.string :analytics_code
t.boolean :current, :default => false
# t.boolean :ssl, :default => false

t.boolean :exception_notifications, :default => false
Expand All @@ -19,17 +18,17 @@ def up
t.string :shib_name_field
t.string :shib_email_field

t.string :smtp_login
t.string :smtp_user_name
t.string :smtp_password
t.boolean :smtp_auto_tls
t.string :smtp_server
t.integer :smtp_port
t.boolean :smtp_use_tls
t.string :smtp_domain
t.string :smtp_auth_type
t.string :smtp_sender

t.boolean :chat_enabled, :default => false
t.string :xmpp_domain
t.string :xmpp_server

t.timestamps
Expand Down
5 changes: 2 additions & 3 deletions db/schema.rb
Expand Up @@ -56,23 +56,22 @@
t.string "locale"
t.string "feedback_url"
t.string "analytics_code"
t.boolean "current", :default => false
t.boolean "exception_notifications", :default => false
t.string "exception_notifications_email"
t.string "exception_notifications_prefix"
t.boolean "shib_enabled", :default => false
t.string "shib_name_field"
t.string "shib_email_field"
t.string "smtp_login"
t.string "smtp_user_name"
t.string "smtp_password"
t.boolean "smtp_auto_tls"
t.string "smtp_server"
t.integer "smtp_port"
t.boolean "smtp_use_tls"
t.string "smtp_domain"
t.string "smtp_auth_type"
t.string "smtp_sender"
t.boolean "chat_enabled", :default => false
t.string "xmpp_domain"
t.string "xmpp_server"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
Expand Down

0 comments on commit 41532b6

Please sign in to comment.