aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/assets/stylesheets/organisations.css.scss31
-rw-r--r--app/assets/stylesheets/users.css.scss8
-rw-r--r--app/controllers/application_controller.rb11
-rw-r--r--app/controllers/organisations_controller.rb10
-rw-r--r--app/controllers/users_controller.rb35
-rw-r--r--app/mailers/user_mailer.rb11
-rw-r--r--app/models/organisation.rb5
-rw-r--r--app/models/referential.rb2
-rw-r--r--app/models/user.rb6
-rw-r--r--app/views/layouts/application.html.erb1
-rw-r--r--app/views/organisations/show.html.erb16
-rw-r--r--app/views/users/_form.html.erb10
-rw-r--r--app/views/users/edit.html.erb3
-rw-r--r--app/views/users/new.html.erb3
-rw-r--r--app/views/users/show.html.erb17
15 files changed, 169 insertions, 0 deletions
diff --git a/app/assets/stylesheets/organisations.css.scss b/app/assets/stylesheets/organisations.css.scss
new file mode 100644
index 000000000..13a078bd4
--- /dev/null
+++ b/app/assets/stylesheets/organisations.css.scss
@@ -0,0 +1,31 @@
+// Place all the styles related to the lines controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
+@import "common";
+
+#workspace.organisations.show
+{
+ .user:after {
+ @include after_div_for_object;
+ }
+
+ .users {
+ margin-top: 20px;
+ }
+
+ .users:after {
+ @include content_to_clear;
+ }
+
+ .user {
+ @include div_for_object;
+
+ /* to create multi-column index */
+ width: 350px;
+ float: left;
+ padding-right: 10px;
+ position: relative;
+
+ }
+}
+
diff --git a/app/assets/stylesheets/users.css.scss b/app/assets/stylesheets/users.css.scss
new file mode 100644
index 000000000..e0fef9e5c
--- /dev/null
+++ b/app/assets/stylesheets/users.css.scss
@@ -0,0 +1,8 @@
+// Place all the styles related to the lines controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
+@import "common";
+
+#workspace.users.edit, #workspace.lines.new
+{
+}
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index ae953a25a..8cde89db0 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -1,4 +1,15 @@
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :authenticate_user!
+
+ protected
+
+ def current_organisation
+ current_user.organisation if current_user
+ end
+ helper_method :current_organisation
+
+ def begin_of_association_chain
+ current_organisation
+ end
end
diff --git a/app/controllers/organisations_controller.rb b/app/controllers/organisations_controller.rb
new file mode 100644
index 000000000..daeb41837
--- /dev/null
+++ b/app/controllers/organisations_controller.rb
@@ -0,0 +1,10 @@
+class OrganisationsController < InheritedResources::Base
+ respond_to :html
+
+ private
+
+ def resource
+ @organisation = current_organisation
+ end
+end
+
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
new file mode 100644
index 000000000..ee9cbcda1
--- /dev/null
+++ b/app/controllers/users_controller.rb
@@ -0,0 +1,35 @@
+class UsersController < InheritedResources::Base
+
+ def create
+ Rails.logger.info( "call user_controller.create")
+ Rails.logger.info( "resource=#{build_resource.inspect}")
+ Rails.logger.info( "resourc.valid?e=#{build_resource.valid?}")
+ Rails.logger.info( "resourc.errors=#{build_resource.errors.inspect}")
+ create! do |success, failure|
+ success.html {
+ Rails.logger.info( "success user_controller")
+ mail = UserMailer.welcome(@user)
+ mail.deliver
+ redirect_to organisation_user_path(@user) }
+ 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 }
+ end
+ end
+
+ protected
+
+ def begin_of_association_chain
+ current_organisation
+ end
+
+end
diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb
new file mode 100644
index 000000000..4c831dae4
--- /dev/null
+++ b/app/mailers/user_mailer.rb
@@ -0,0 +1,11 @@
+class UserMailer < ActionMailer::Base
+ default :from => 'sim@dryade.net'
+
+ def welcome(user)
+ @user = user
+ mail(:subject => "Welcome to #{user.organisation.name}",
+ :to => user.email)
+ end
+
+end
+
diff --git a/app/models/organisation.rb b/app/models/organisation.rb
new file mode 100644
index 000000000..28d592fc9
--- /dev/null
+++ b/app/models/organisation.rb
@@ -0,0 +1,5 @@
+# -*- coding: utf-8 -*-
+class Organisation < ActiveRecord::Base
+ has_many :users, :dependent => :destroy
+ has_many :referentials, :dependent => :destroy
+end
diff --git a/app/models/referential.rb b/app/models/referential.rb
index 953038168..b87ba81e8 100644
--- a/app/models/referential.rb
+++ b/app/models/referential.rb
@@ -20,6 +20,8 @@ class Referential < ActiveRecord::Base
has_many :imports, :dependent => :destroy
has_many :exports, :dependent => :destroy
+
+ belongs_to :organisation
def slug_excluded_values
if ! slug.nil?
diff --git a/app/models/user.rb b/app/models/user.rb
index b2f7c8ec9..53853530f 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -6,4 +6,10 @@ class User < ActiveRecord::Base
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
+
+ belongs_to :organisation
+
+ before_validation(:on => :create) do
+ self.password ||= Devise.friendly_token.first(6)
+ end
end
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb
index 69d5be2a5..417f677c3 100644
--- a/app/views/layouts/application.html.erb
+++ b/app/views/layouts/application.html.erb
@@ -37,6 +37,7 @@
<% elsif ! selected_referential? %>
<li><%= link_to Referential.model_name.human(:count=>2), referentials_path, :class => ("current" if current_page?(referentials_path) || current_page?(root_url)) %></li>
<li><%= tab_link_to FileValidation.model_name.human(:count=>2), file_validations_path %></li>
+ <li class="admin"><%= tab_link_to Organisation.model_name.human, organisation_path %></li>
<% else %>
<li><%= link_to t("layouts.tabs.dashboard"), referential_path(@referential), :class => ("current" if current_page?(referential_path(@referential))) %></li>
<li><%= tab_link_to Chouette::Network, referential_networks_path(@referential) %></li>
diff --git a/app/views/organisations/show.html.erb b/app/views/organisations/show.html.erb
new file mode 100644
index 000000000..da895ea87
--- /dev/null
+++ b/app/views/organisations/show.html.erb
@@ -0,0 +1,16 @@
+<%= title_tag @organisation.name %>
+
+<div class="users">
+ <% @organisation.users.each do |user| %>
+ <%= div_for(user) do %>
+ <li><%= link_to "#{user.email}", organisation_user_path(user) %></li>
+ <% end %>
+ <% end %>
+</div>
+
+<% content_for :sidebar do %>
+<ul class="actions">
+ <%= link_to t('users.actions.new'), new_organisation_user_path, :class => "add" %>
+</ul>
+<% end %>
+
diff --git a/app/views/users/_form.html.erb b/app/views/users/_form.html.erb
new file mode 100644
index 000000000..2894b5c90
--- /dev/null
+++ b/app/views/users/_form.html.erb
@@ -0,0 +1,10 @@
+<%= semantic_form_for [:organisation, @user] do |form| %>
+ <%= form.inputs do %>
+ <%= form.input :email %>
+ <% end %>
+
+ <%= form.actions do %>
+ <%= form.action :submit, :as => :button %>
+ <%= form.action :cancel, :as => :link %>
+ <% end %>
+<% end %>
diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb
new file mode 100644
index 000000000..89d01b648
--- /dev/null
+++ b/app/views/users/edit.html.erb
@@ -0,0 +1,3 @@
+<%= title_tag t('.title', :user => @user.email) %>
+
+<%= render "form" %>
diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb
new file mode 100644
index 000000000..98986b4d6
--- /dev/null
+++ b/app/views/users/new.html.erb
@@ -0,0 +1,3 @@
+<%= title_tag t('.title') %>
+
+<%= render "form" %>
diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb
new file mode 100644
index 000000000..30f5cc4ba
--- /dev/null
+++ b/app/views/users/show.html.erb
@@ -0,0 +1,17 @@
+<%= title_tag @user.email %>
+
+<div class="user">
+<p>
+<label><%= User.human_attribute_name("email") %>: </label>
+<%= @user.email %>
+</p>
+</div>
+
+<% content_for(:sidebar) do %>
+ <ul class="actions">
+ <li><%= link_to t('users.actions.edit'), edit_organisation_user_path( @user), :class => "edit" %></li>
+ <% unless current_user.id==@user.id %>
+ <li><%= link_to t('users.actions.destroy'), organisation_user_path(@user),:method => :delete, :confirm => t('users.actions.destroy_confirm'), :class => "remove" %></li>
+ <% end %>
+ </ul>
+<% end %>