aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorLuc Donnet2015-01-29 16:10:43 +0100
committerLuc Donnet2015-01-29 16:10:43 +0100
commit0bf25cd563d38da17c9265570a98bff210044424 (patch)
treef2d6ce72083375461aa96025cc10f181810bc6c0 /app
parent0ee28dc54b2beeada5d86648c5897e2ea6f25c7e (diff)
downloadchouette-core-0bf25cd563d38da17c9265570a98bff210044424.tar.bz2
Fix several problems with devise and use mainstream source now
Diffstat (limited to 'app')
-rw-r--r--app/assets/javascripts/application.js1
-rw-r--r--app/assets/stylesheets/vendor/simple_form.css.scss5
-rw-r--r--app/controllers/application_controller.rb5
-rw-r--r--app/controllers/invitations_controller.rb21
-rw-r--r--app/controllers/organisations_controller.rb2
-rw-r--r--app/controllers/registrations_controller.rb19
-rw-r--r--app/controllers/subscriptions_controller.rb14
-rw-r--r--app/controllers/users_controller.rb9
-rw-r--r--app/controllers/welcome_controller.rb4
-rw-r--r--app/models/user.rb4
-rw-r--r--app/views/devise/invitations/new.html.erb24
-rw-r--r--app/views/devise/passwords/edit.html.erb6
-rw-r--r--app/views/devise/passwords/new.html.erb4
-rw-r--r--app/views/devise/registrations/edit.html.erb8
-rw-r--r--app/views/devise/registrations/new.html.erb12
-rw-r--r--app/views/devise/sessions/new.html.erb4
-rw-r--r--app/views/organisations/show.html.erb2
-rw-r--r--app/views/subscriptions/new.html.erb25
-rw-r--r--app/views/users/_form.html.erb17
-rw-r--r--app/views/users/_user.html.erb5
-rw-r--r--app/views/users/edit.html.erb3
-rw-r--r--app/views/users/show.html.erb2
22 files changed, 88 insertions, 108 deletions
diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js
index 07fc8694c..a24c418b4 100644
--- a/app/assets/javascripts/application.js
+++ b/app/assets/javascripts/application.js
@@ -26,3 +26,4 @@
//= require_directory ./compliance_check_tasks
//= require_directory ./exports
//= require_directory ./lines
+//= require_directory ./referentials
diff --git a/app/assets/stylesheets/vendor/simple_form.css.scss b/app/assets/stylesheets/vendor/simple_form.css.scss
index ea5e4d528..afac930c1 100644
--- a/app/assets/stylesheets/vendor/simple_form.css.scss
+++ b/app/assets/stylesheets/vendor/simple_form.css.scss
@@ -3,4 +3,9 @@
.help-inline{
color:#cc0000;
}
+
+ .form-actions{
+ @extend .col-sm-offset-3;
+ @extend .col-sm-9;
+ }
} \ No newline at end of file
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 4359ee02e..63775a30f 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -1,7 +1,10 @@
class ApplicationController < ActionController::Base
- protect_from_forgery
+ # TODO : Delete hack to authorize Cross Request for js and json get request from javascript
+ protect_from_forgery unless: -> { request.get? && (request.format.json? || request.format.js?) }
before_filter :authenticate_user!
before_filter :set_locale
+
+ # Load helpers in rails engine
helper LanguageEngine::Engine.helpers
def set_locale
diff --git a/app/controllers/invitations_controller.rb b/app/controllers/invitations_controller.rb
new file mode 100644
index 000000000..97e5352e4
--- /dev/null
+++ b/app/controllers/invitations_controller.rb
@@ -0,0 +1,21 @@
+class InvitationsController < Devise::InvitationsController
+
+ def update
+ if this
+ redirect_to organisation_path
+ else
+ super
+ end
+ end
+
+ protected
+
+ def invite_params
+ params.require(:user).permit(:name, :email )
+ end
+
+ def update_resource_params
+ params.require(:user).permit(:name, :email, :password, :password_confirmation, :invitation_token)
+ end
+
+end
diff --git a/app/controllers/organisations_controller.rb b/app/controllers/organisations_controller.rb
index 026892613..51a325586 100644
--- a/app/controllers/organisations_controller.rb
+++ b/app/controllers/organisations_controller.rb
@@ -1,7 +1,7 @@
class OrganisationsController < BreadcrumbController
defaults :resource_class => Organisation
- respond_to :html
+ respond_to :html, :only => [:edit, :show, :update]
def update
update! do |success, failure|
diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb
index b02d3217a..0cc0b1c31 100644
--- a/app/controllers/registrations_controller.rb
+++ b/app/controllers/registrations_controller.rb
@@ -2,6 +2,23 @@
prepend_before_filter :accept_user_creation, :only => [:new, :create]
+ protected
+
+ # The default url to be used after updating a resource. You need to overwrite
+ # this method in your own RegistrationsController.
+ def after_update_path_for(resource)
+ organisation_user_path(resource)
+ end
+
+ def sign_up_params
+ params.require(:user).permit(:name, :email, :password, :password_confirmation, { organisation_attributes: [:name] } )
+ end
+
+ def account_update_params
+ params.require(:user).permit(:name, :email, :password, :password_confirmation, :current_password)
+ end
+
+
private
def accept_user_creation
@@ -11,6 +28,6 @@
else
return true
end
- end
+ end
end
diff --git a/app/controllers/subscriptions_controller.rb b/app/controllers/subscriptions_controller.rb
deleted file mode 100644
index a1dca5a5d..000000000
--- a/app/controllers/subscriptions_controller.rb
+++ /dev/null
@@ -1,14 +0,0 @@
-class SubscriptionsController < InheritedResources::Base
- skip_filter :authenticate_user!
-
- def create
- create! do |success, failure|
- success.html do
- sign_in resource.user
- redirect_to referentials_path
- end
- end
- end
-
-end
-
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 2b1c2bd14..7726f203a 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -1,7 +1,8 @@
class UsersController < BreadcrumbController
defaults :resource_class => User
-
+ respond_to :html, :only => [:show, :new]
+
def create
@user = current_organisation.users.build(params[:user])
@@ -13,12 +14,6 @@ class UsersController < BreadcrumbController
end
end
- def update
- update! do |success, failure|
- success.html { redirect_to organisation_user_path(@user) }
- end
- end
-
def destroy
destroy! do |success, failure|
success.html { redirect_to organisation_path }
diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb
deleted file mode 100644
index f9b859b9c..000000000
--- a/app/controllers/welcome_controller.rb
+++ /dev/null
@@ -1,4 +0,0 @@
-class WelcomeController < ApplicationController
- def index
- end
-end
diff --git a/app/models/user.rb b/app/models/user.rb
index e3ea71603..4a794beaf 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -1,9 +1,9 @@
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
- devise :database_authenticatable, :registerable,
+ devise :invitable, :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable,
- :confirmable, :invitable
+ :confirmable
# Setup accessible (or protected) attributes for your model
# attr_accessible :email, :password, :current_password, :password_confirmation, :remember_me, :name, :organisation_attributes
diff --git a/app/views/devise/invitations/new.html.erb b/app/views/devise/invitations/new.html.erb
index 5567463c8..76a81a33d 100644
--- a/app/views/devise/invitations/new.html.erb
+++ b/app/views/devise/invitations/new.html.erb
@@ -1,18 +1,12 @@
-<div class="col-md-offset-2 col-md-8">
- <div class="panel panel-default">
- <div class="panel-heading"><%= t "devise.invitations.new.header" %></div>
- <div class="panel-body">
+<h2><%= t "devise.invitations.new.header" %></h2>
- <%= simple_form_for resource, :as => resource_name, :url => invitation_path(resource_name), :html => {:method => :post} do |form| %>
+<%= simple_form_for resource, :as => resource_name, :url => invitation_path(resource_name), :html => {:method => :post, class: "form-horizontal"} do |form| %>
- <% resource.class.invite_key_fields.each do |field| -%>
- <%= form.input field %>
- <% end -%>
+ <% resource.class.invite_key_fields.each do |field| -%>
+ <%= form.input field %>
+ <% end -%>
- <div class="submit">
- <%= form.button :submit, :value => t("devise.invitations.new.submit_button"), :class => "btn-info" %>
- </div>
- <% end %>
- </div>
- </div>
-</div>
+ <div class="form-actions">
+ <%= form.button :submit, :value => t("devise.invitations.new.submit_button"), :class => "btn-info" %>
+ </div>
+<% end %>
diff --git a/app/views/devise/passwords/edit.html.erb b/app/views/devise/passwords/edit.html.erb
index e0cad44a2..0d3d1d99d 100644
--- a/app/views/devise/passwords/edit.html.erb
+++ b/app/views/devise/passwords/edit.html.erb
@@ -2,14 +2,14 @@
<div class="panel panel-default">
<div class="panel-heading"><%= t('.title') %></div>
<div class="panel-body">
- <%= simple_form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :put }) do |f| %>
+ <%= simple_form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :put, class: "form-horizontal" }) do |f| %>
<%= f.input :reset_password_token, :as => :hidden %>
<%= f.input :password, :as => :password %>
<%= f.input :password_confirmation, :as => :password %>
- <div class="submit">
- <%= link_to t("cancel"), root_path, :class => "btn btn-default" %>
+ <div class="form-actions">
+ <%= link_to t("cancel"), unauthenticated_root_path, :class => "btn btn-default" %>
<%= f.button :submit, :value => t("devise.passwords.edit.commit"), :class => "btn-info" %>
</div>
<% end %>
diff --git a/app/views/devise/passwords/new.html.erb b/app/views/devise/passwords/new.html.erb
index 8f5ec0f10..8f9e6dd47 100644
--- a/app/views/devise/passwords/new.html.erb
+++ b/app/views/devise/passwords/new.html.erb
@@ -2,11 +2,11 @@
<div class="panel panel-default">
<div class="panel-heading"><%= t('.title') %></div>
<div class="panel-body">
- <%= simple_form_for(resource, :as => resource_name, :url => password_path(resource_name)) do |form| %>
+ <%= simple_form_for(resource, :as => resource_name, :url => password_path(resource_name), html: {class: 'form-horizontal' } ) do |form| %>
<%= form.input :email, :as => :email, placeholder: 'user@domain.com' %>
<div class="submit">
- <%= link_to t("cancel"), root_path, :class => "btn btn-default" %>
+ <%= link_to t("cancel"), unauthenticated_root_path, :class => "btn btn-default" %>
<%= form.button :submit, :value => t("devise.passwords.new.commit"), :class => "btn-info" %>
</div>
<% end %>
diff --git a/app/views/devise/registrations/edit.html.erb b/app/views/devise/registrations/edit.html.erb
index 95dcbf382..154ecf1c8 100644
--- a/app/views/devise/registrations/edit.html.erb
+++ b/app/views/devise/registrations/edit.html.erb
@@ -1,6 +1,6 @@
<%= title_tag t('.title') %>
-<%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %>
+<%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name), html: { class: "form-horizontal", method: :put }) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
@@ -21,10 +21,4 @@
</div>
<% end %>
-<% content_for :sidebar do %>
-<ul class="actions">
- <%= link_to t('.actions.destroy'), registration_path(resource_name), :confirm => t('.actions.destroy_confirm'), :method => :delete, :class => "remove" %>
-</ul>
-<% end %>
-
diff --git a/app/views/devise/registrations/new.html.erb b/app/views/devise/registrations/new.html.erb
index 9c780cba3..2a1456c58 100644
--- a/app/views/devise/registrations/new.html.erb
+++ b/app/views/devise/registrations/new.html.erb
@@ -4,16 +4,16 @@
<div class="panel panel-default">
<div class="panel-heading"><%= t("devise.registrations.new.title") %></div>
<div class="panel-body">
- <%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), :wrapper => "form_without_label" ) do |form| %>
+ <%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), :wrapper => "form_without_label", html: {class: 'form-horizontal' } ) do |form| %>
<%= form.simple_fields_for :organisation, Organisation.new do |organisation| %>
- <%= organisation.input :name, :label => false, :placeholder => t("helpers.label.user.organisation_name"), input_html: { :class => "form-control" } %>
+ <%= organisation.input :name, :label => false, input_html: { :class => "form-control" } %>
<% end %>
<% if resource.respond_to?( :name) %>
- <%= form.input :name, :label => false, :placeholder => t("helpers.label.user.name"), input_html: { :class => "form-control" } %>
+ <%= form.input :name, :label => false, input_html: { :class => "form-control" } %>
<% end %>
- <%= form.input :email, :label => false, :placeholder => t("helpers.label.user.email"), input_html: { :class => "form-control" } %>
- <%= form.input :password, :as => :password, :label => false, :placeholder => t("helpers.label.user.password"), input_html: { :class => "form-control" } %>
- <%= form.input :password_confirmation, :as => :password, :label => false, :placeholder => t("helpers.label.user.password_confirmation"), input_html: { :class => "form-control" } %>
+ <%= form.input :email, :label => false, input_html: { :class => "form-control" } %>
+ <%= form.input :password, :as => :password, :label => false, input_html: { :class => "form-control" } %>
+ <%= form.input :password_confirmation, :as => :password, :label => false, input_html: { :class => "form-control" } %>
<%= form.button :submit, :class => "btn-primary" %>
<% end %>
diff --git a/app/views/devise/sessions/new.html.erb b/app/views/devise/sessions/new.html.erb
index f0a2a26f4..279eb3ca8 100644
--- a/app/views/devise/sessions/new.html.erb
+++ b/app/views/devise/sessions/new.html.erb
@@ -11,7 +11,7 @@
<div class="col-md-4 login">
<div class="panel panel-default">
<div class="panel-body">
- <%= simple_form_for(resource, :as => resource_name, :url => session_path(resource_name), :wrapper => "form_without_label", html: { :class => 'session_new' } ) do |form| %>
+ <%= simple_form_for(resource, :as => resource_name, :url => session_path(resource_name), :wrapper => "form_without_label", html: { :class => 'form-horizontal session_new' } ) do |form| %>
<%= form.input :email, :label => false, input_html: { :class => "form-control" } %>
<div class="row">
<div class="col-md-6">
@@ -39,7 +39,7 @@
<div class="panel panel-default">
<div class="panel-heading"><%= t("devise.registrations.new.title") %></div>
<div class="panel-body">
- <%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), :wrapper => "form_without_label", html: { class: "registration_new" } ) do |form| %>
+ <%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), :wrapper => "form_without_label", html: { class: "form-horizontal registration_new" } ) do |form| %>
<%= form.simple_fields_for :organisation, Organisation.new do |organisation| %>
<%= organisation.input :name, :label => false, input_html: { :class => "form-control" } %>
<% end %>
diff --git a/app/views/organisations/show.html.erb b/app/views/organisations/show.html.erb
index c67eeb271..753229e60 100644
--- a/app/views/organisations/show.html.erb
+++ b/app/views/organisations/show.html.erb
@@ -12,7 +12,7 @@
<% content_for :sidebar do %>
<ul class="actions">
<li><%= link_to t('organisations.actions.edit'), edit_organisation_path, :class => "edit" %></li>
- <li><%= link_to t('users.actions.new'), new_organisation_user_path, :class => "add" %></li>
+ <li><%= link_to t('users.actions.new'), new_user_invitation_path, :class => "add" %></li>
</ul>
<% end %>
diff --git a/app/views/subscriptions/new.html.erb b/app/views/subscriptions/new.html.erb
deleted file mode 100644
index 686ab8c98..000000000
--- a/app/views/subscriptions/new.html.erb
+++ /dev/null
@@ -1,25 +0,0 @@
-<%= title_tag t('devise.registrations.new.title') %>
-
-<%= semantic_form_for @subscription, :url => subscription_path do |form| %>
- <%= form.inputs do %>
- <%= form.input :organisation_name %>
- <%= form.input :user_name %>
- <%= form.input :email %>
- <%= form.input :password, :as => :password %>
- <%= form.input :password_confirmation, :as => :password %>
- <% end %>
-
- <%= form.actions do %>
- <%= form.action :submit, :as => :button, :label => t('devise.registrations.new.title') %>
- <%= form.action :cancel, :as => :link %>
- <% end %>
-<% end %>
-
-<% content_for :sidebar do %>
-<ul class="actions">
- <li>
- <%= link_to t('devise.shared.sign_in'), new_user_session_path %>
- </li>
-</ul>
-<% end %>
-
diff --git a/app/views/users/_form.html.erb b/app/views/users/_form.html.erb
index ff452c924..74de43cef 100644
--- a/app/views/users/_form.html.erb
+++ b/app/views/users/_form.html.erb
@@ -1,11 +1,10 @@
-<%= semantic_form_for [:organisation, @user] do |form| %>
- <%= form.inputs do %>
- <%= form.input :name %>
- <%= form.input :email %>
- <% end %>
+<%= simple_form_for [:organisation, @user], html: {class: 'form-horizontal' } do |form| %>
+ <%= form.input :name %>
+ <%= form.input :email %>
+
- <%= form.actions do %>
- <%= form.action :submit, :as => :button %>
- <%= form.action :cancel, :as => :link , :url => organisation_path %>
- <% end %>
+ <div class="form-actions">
+ <%= link_to t("cancel"), organisation_path, :class => "btn btn-default" %>
+ <%= form.button :submit, :as => :button %>
+ </div>
<% end %>
diff --git a/app/views/users/_user.html.erb b/app/views/users/_user.html.erb
index 3f70e8479..4a67bb693 100644
--- a/app/views/users/_user.html.erb
+++ b/app/views/users/_user.html.erb
@@ -1,10 +1,7 @@
<div id="index_item" class="panel panel-default user">
<div class="panel-heading">
<div class="panel-title clearfix">
- <span class="pull-right">
- <%= link_to edit_organisation_user_path( user), :class => "btn btn-default btn-sm" do %>
- <span class="fa fa-pencil"></span>
- <% end %>
+ <span class="pull-right">
<%= link_to organisation_user_path(user), :method => :delete, :data => {:confirm => t('users.actions.destroy_confirm')}, :class => "btn btn-danger btn-sm" do %>
<span class="fa fa-trash-o"></span>
<% end %>
diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb
deleted file mode 100644
index 89d01b648..000000000
--- a/app/views/users/edit.html.erb
+++ /dev/null
@@ -1,3 +0,0 @@
-<%= title_tag t('.title', :user => @user.email) %>
-
-<%= render "form" %>
diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb
index 07e747331..b984ce206 100644
--- a/app/views/users/show.html.erb
+++ b/app/views/users/show.html.erb
@@ -13,7 +13,7 @@
<% content_for(:sidebar) do %>
<ul class="actions">
- <li><%= link_to t('users.actions.edit'), edit_organisation_user_path( @user), :class => "edit" %></li>
+ <li><%= link_to( t('users.actions.edit'), edit_user_registration_path, :class => "edit") if @user == current_user %></li>
<% unless current_user.id==@user.id %>
<li><%= link_to t('users.actions.destroy'), organisation_user_path(@user),:method => :delete, :data => {:confirm => t('users.actions.destroy_confirm')}, :class => "remove" %></li>
<% end %>