--- /dev/null
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://coffeescript.org/
--- /dev/null
+// Place all the styles related to the User controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
--- /dev/null
+class UsersController < ApplicationController
+ before_action :set_user, only: [:show, :edit, :update, :destroy]
+
+ def index
+ authorize User
+
+ @users = current_user.organisation.users
+
+ unless params[:email].blank?
+ @users = @users.where("UPPER(email) like ?", "%#{params[:email].upcase}%")
+ end
+
+ @users = @users.paginate(page: params[:page])
+ end
+
+ # GET /users/1
+ # GET /users/1.json
+ def show
+ authorize User
+ end
+
+ # GET /users/new
+ def new
+ authorize User
+
+ @user = User.new
+ @user.organisation = current_user.organisation
+ end
+
+ # GET /users/1/edit
+ def edit
+ authorize User
+ end
+
+ # POST /users
+ # POST /users.json
+ def create
+ authorize User
+
+ @user = User.new(user_params)
+
+ respond_to do |format|
+ if @user.save
+ format.html { redirect_to users_url, notice: 'Utilisateur créé avec succès.' }
+ format.json { render :show, status: :created, location: @user }
+ else
+ format.html { render :new }
+ format.json { render json: @user.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PATCH/PUT /users/1
+ # PATCH/PUT /users/1.json
+ def update
+ authorize User
+
+ respond_to do |format|
+ if @user.update(user_params)
+ format.html { redirect_to users_url, notice: 'Utilisateur modifié avec succès.' }
+ format.json { render :show, status: :ok, location: @user }
+ else
+ format.html { render :edit }
+ format.json { render json: @user.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /users/1
+ # DELETE /users/1.json
+ def destroy
+ authorize User
+
+ @user.destroy
+ respond_to do |format|
+ format.html { redirect_to users_url, notice: 'Utilisateur supprimé avec succès.' }
+ format.json { head :no_content }
+ end
+ end
+
+ private
+ # Use callbacks to share common setup or constraints between actions.
+ def set_user
+ @user = User.find(params[:id])
+ end
+
+ # Never trust parameters from the scary internet, only allow the white list through.
+ def user_params
+ params.require(:user).permit(:email, :admin, :organisation_id, :password, :password_confirmation)
+ end
+
+end
--- /dev/null
+module UserHelper
+end
:registerable,
:recoverable,
:rememberable,
- :validatable
+ :validatable,
+ :trackable
audited
belongs_to :organisation
+ validates :email, presence: true
+
+ self.per_page = 10
+
end
--- /dev/null
+class UserPolicy < ApplicationPolicy
+ class Scope < Scope
+ def resolve
+ scope.all
+ end
+ end
+end
<div class="col">
<ul class="list-group">
<li class="list-group-item">
- <%= link_to admin_ajout_prestations_path, class: "text-dark" do %>
- <h4><i class="fas fa-calendar-day"></i> Comptabilisation des prestations</h4>
+ <%= link_to organisation_url(current_user.organisation), class: "text-dark" do %>
+ <h4><i class="fas fa-city"></i></span> Organisation</h4>
<% end %>
</li>
<li class="list-group-item">
- <%= link_to admin_ajout_factures_path, class: "text-dark" do %>
- <h4><i class="fas fa-calendar-day"></i> Facturation des prestations</h4>
+ <%= link_to users_path, class: "text-dark" do %>
+ <h4><i class="fas fa-user-friends"></i> Utilisateurs</h4>
<% end %>
</li>
<li class="list-group-item">
- _
+ <%= link_to admin_ajout_prestations_path, class: "text-dark" do %>
+ <h4><i class="fas fa-calendar-day"></i> Comptabilisation prestations du jour</h4>
+ <% end %>
</li>
<li class="list-group-item">
- _
+ <%= link_to admin_ajout_factures_path, class: "text-dark" do %>
+ <h4><i class="fas fa-calendar-day"></i> Facturation prestations</h4>
+ <% end %>
</li>
</ul>
</div>
</ul>
<ul class="navbar-nav navbar-right">
<% if current_user %>
- <li class="nav-item <%= (params[:controller]=='organisations' ? 'active' : '') %>">
- <%= link_to organisation_url(current_user.organisation), class: "nav-link" do %><i class="fas fa-city"></i></span> Organisation<% end %>
- </li>
<li class="nav-item <%= (params[:controller]=='admin' ? 'active' : '') %>">
<%= link_to admin_index_url, class: "nav-link" do %><i class="fas fa-users-cog"></i></span> Admin<% end %>
</li>
+ <li class="nav-item">
+ <%= link_to destroy_user_session_path, method: :delete, class: "nav-link" do %><i class="fas fa-sign-out-alt"></i></span> Déconnexion<% end %>
+ </li>
<% end %>
- <li class="nav-item">
- <a class="nav-link disabled" href="#">Disabled</a>
- </li>
</ul>
</div>
</nav>
--- /dev/null
+<%= bootstrap_form_with(model: user, local: true) do |form| %>
+
+ <%= form.hidden_field :organisation_id %>
+ <%= form.text_field :email, required: true %>
+ <%= form.password_field :password, required: true %>
+ <%= form.password_field :password_confirmation, required: true %>
+
+ <%= form.check_box :admin, custom: :switch %>
+ <br />
+
+ <%= form.submit "Enregistrer", class: "btn btn-success" %>
+<% end %>
--- /dev/null
+<tr>
+ <td><%= user.email %></td>
+ <td class="text-center"><i class="<%= user.admin? ? "far fa-check-circle" : "" %>"></i></td>
+ <td><% if policy(user).edit? %>
+ <%= link_to edit_user_path(user) do %>
+ <i class="far fa-edit"></i>
+ <% end %>
+ <% end %>
+ </td>
+ <td>
+ <% if policy(user).destroy? %>
+ <%= link_to user, method: :delete, data: { confirm: 'Etes-vous bien certain.e ???' } do %>
+ <i class="fas fa-trash-alt"></i>
+ <% end %>
+ <% end %>
+ </td>
+</tr>
--- /dev/null
+<h1>Editer Utilisateur</h1>
+
+<%= render 'form', user: @user %>
+
+<%= link_to 'Retour', users_path %>
--- /dev/null
+<div class="pb-2 mt-4 mb-2 border-bottom">
+ <% if policy(User).new? %>
+ <%= link_to new_user_path, class: 'btn text-primary float-right' do %>
+ <i class="fas fa-plus-circle"></i> Utilisateur
+ <% end %>
+ <% end %>
+
+ <h1><i class="fas fa-user-friends"></i> Utilisateurs</h1>
+</div>
+
+<%= bootstrap_form_tag url: users_path, method: :get do |f| %>
+ <div class="row">
+ <div class="col"><%= f.text_field :email, value: params[:email], onchange: "this.form.submit()" %></div>
+ </div>
+<% end %>
+
+<table class="table table-striped table-hover">
+ <thead>
+ <tr>
+ <th>Email</th>
+ <th>Admin?</th>
+ <th colspan="3"></th>
+ </tr>
+ </thead>
+
+ <tbody>
+ <%= render @users %>
+ </tbody>
+</table>
+
+<%= will_paginate @users, renderer: WillPaginate::ActionView::BootstrapLinkRenderer %>
+<br>
\ No newline at end of file
--- /dev/null
+<h1>Nouvel Utilisateur</h1>
+
+<%= render 'form', user: @user %>
+
# Use an evented file watcher to asynchronously detect changes in source code,
# routes, locales, etc. This feature depends on the listen gem.
config.file_watcher = ActiveSupport::EventedFileUpdateChecker
+
+ config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
end
# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false
+
+ config.action_mailer.default_url_options = { host: 'www.opencantine.net' }
end
get 'admin/ajout_factures'
post 'admin/ajout_factures_do'
+ devise_for :users
+
resources :factures
resources :prestations
resources :tarifs
resources :comptes
resources :structures
resources :organisations
-
- devise_for :users
+ resources :users
root 'comptes#index'
--- /dev/null
+class AddTrackableAttributeToUser < ActiveRecord::Migration[5.2]
+ def change
+
+ change_table :users do |t|
+
+ ## Trackable
+ t.integer :sign_in_count, default: 0, null: false
+ t.datetime :current_sign_in_at
+ t.datetime :last_sign_in_at
+ t.inet :current_sign_in_ip
+ t.inet :last_sign_in_ip
+
+ end
+
+ end
+end
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 2019_09_12_075043) do
+ActiveRecord::Schema.define(version: 2019_09_13_123746) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
t.datetime "updated_at", null: false
t.bigint "organisation_id"
t.boolean "admin", default: false
+ t.integer "sign_in_count", default: 0, null: false
+ t.datetime "current_sign_in_at"
+ t.datetime "last_sign_in_at"
+ t.inet "current_sign_in_ip"
+ t.inet "last_sign_in_ip"
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["organisation_id"], name: "index_users_on_organisation_id"
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true