Commit 3988d2f4 authored by steven robert's avatar steven robert

ajout de la gestion des invitation pour les pads (en cours non fonctionnel)

parent 3b2f0fa2
This diff is collapsed.
// Place all the styles related to the PadsGroups controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
// Place all the styles related to the PadsUsers controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
......@@ -27,7 +27,7 @@ a {
&:hover {
color: #fff;
//background-color: #000;
background-color: #000;
}
}
......
class PadsController < ApplicationController
before_action :only_logged_users
before_action :set_pad, only: [:show, :edit, :update, :destroy]
before_action :set_pad, only: [:show, :edit, :update, :destroy , :invitation]
# GET /pads
# GET /pads.json
......@@ -34,6 +34,50 @@ class PadsController < ApplicationController
def edit
end
# GET /pads/1/invitation
def invitation
redirect_to "/pad", notice: "Droits insuffisants" unless @pad.owner_id == @current_user.id
end
# GET /pads/1/users.json
def users
groups = PadsGroup.where(pad_id: params[:id])
users = PadsUser.where(pad_id: params[:id])
@users_groups = []
groups.each do |group|
@users_groups << {name: Group.find(group.group_id).name, id: group.id, title: "Groupes"}
end
users.each do |user|
@users_groups << {name: user.mail, id: user.id, title: user.uuid ? "Membre" : "Externe"}
end
end
# DELETE /pads/1/users.json
def destroy_users
groupe_ids = params[:pads][:pad_groups]
if PadsGroup.where(id: groupe_ids).destroy_all
user_ids = params[:pads][:pad_users]
if PadsUser.where(id: user_ids).destroy_all
respond_to do |format|
format.json { head :no_content }
end
else
respond_to do |format|
format.json { render json: "Impossible de supprimer les utilisateurs sélectionnés", status: :unprocessable_entity }
end
end
else
respond_to do |format|
format.json { render json: "Impossible de supprimer les groupes sélectionnés", status: :unprocessable_entity }
end
end
end
# POST /pads
# POST /pads.json
def create
......
class PadsGroupsController < ApplicationController
before_action :set_pads_group, only: [:destroy]
# POST /pads_groups
# POST /pads_groups.json
def create
@pads_group = PadsGroup.new(pads_group_params)
@nb_pads_groups = PadsGroup.where(group_id: @pads_group.group_id, pad_id: @pads_group.pad_id).count
groupe = Group.find(@pads_group.group_id)
respond_to do |format|
if @pads_group.save
format.html { redirect_to @pads_group, notice: 'Pads group was successfully created.' }
format.json { render :show, status: :created, location: @pads_group }
else
format.html { render :new }
format.json { render json: @pads_group.errors, status: :unprocessable_entity }
end
end
end
# DELETE /pads_groups/1
# DELETE /pads_groups/1.json
def destroy
@pads_group.destroy
respond_to do |format|
format.html { redirect_to pads_groups_url, notice: 'Pads group was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_pads_group
@pads_group = PadsGroup.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def pads_group_params
params.require(:pads_group).permit(:group_id, :pad_id)
end
end
class PadsUsersController < ApplicationController
before_action :set_pads_user, only: [:destroy]
# POST /pads_users
# POST /pads_users.json
def create
@pads_user = PadsUser.new(pads_user_params)
@pads_user.mail = User.find(@pads_user.uuid).email if @pads_user.uuid
respond_to do |format|
if @pads_user.save
format.html { redirect_to @pads_user, notice: 'Pads user was successfully created.' }
format.json { render :show, status: :created, location: @pads_user }
else
format.html { render :new }
format.json { render json: @pads_user.errors, status: :unprocessable_entity }
end
end
end
# DELETE /pads_users/1
# DELETE /pads_users/1.json
def destroy
@pads_user.destroy
respond_to do |format|
format.html { redirect_to pads_users_url, notice: 'Pads user was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_pads_user
@pads_user = PadsUser.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def pads_user_params
params.require(:pads_user).permit(:user_id, :pad_id)
end
end
module PadsGroupsHelper
end
module PadsUsersHelper
end
class Pad < ActiveRecord::Base
has_many :pads_users, dependent: :destroy
has_many :pads_groups, dependent: :destroy
end
class PadsGroup < ActiveRecord::Base
belongs_to :pad
end
class PadsUser < ActiveRecord::Base
belongs_to :pad
validates :mail, presence: true, allow_blank: false
end
<!--
Copyright (c) 2017 Robert Jean Steven <robert.steven.974@gmail.com>
This file is part of Zourit.
Zourit is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Zourit is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Zourit. If not, see <http://www.gnu.org/licenses/>.
-->
<div class="z-index-page">
<div class="container">
<div class="panel panel-warning shadow">
<div class="panel-heading clearfix">
<h1>
<%= I18n.t "terms.invitationpad"%>
</h1>
</div>
<div class="panel-body">
<div class="col-sm-12 col-md-12 text-left">
<div class="well well-sm text-center">
<div id="Pad-add-user-toolbar">
<button type="button" id="Pad-ajout-UG" class="btn btn-primary">
<i class="fa fa-plus"></i> <%= I18n.t "terms.adduserorgroup"%>
</button>
<button id="Pad-supprime-UG" class="btn btn-primary z-supprime-utilisateur" disabled>
<i class="glyphicon glyphicon-remove"></i> <%= I18n.t "terms.deleteuserorgroup"%>
</button>
<button id="Pad-email-UG" class="btn btn-primary z-supprime-utilisateur" disabled>
<i class="fa fa-envelope"></i> <%= I18n.t "terms.sendinvit"%>
</button>
</div>
<table id="Pads_users_table" data-params-id="<%= @pad.id %>" data-classes="table table-no-bordered" ></table>
</div>
</div>
</div>
</div>
</div>
<div id="modal-saisie-Pad-UG" class="modal fade z-superadmin-modal-saisie-domaine" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel">
<div class="modal-dialog modal-m">
<div class="modal-content">
<div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> <h4 class="modal-title" id="mySmallModalLabel"><%= I18n.t "terms.adduservisio"%></h4> </div>
<div class="modal-body">
<label><i class="fa fa-users"></i> <%= I18n.t "terms.addgroupuser"%></label><br>
<div class="well well-sm">
<table id="Groups-modale-Pad-table" data-classes="table table-no-bordered" data-pagination="true" ></table>
</div>
<label><i class="fa fa-user"></i> <%= I18n.t "terms.addfielduser"%></label><br>
<div class="well well-sm">
<table id="Users-modale-Pad-table" data-classes="table table-no-bordered" data-pagination="true" ></table>
</div>
<label><i class="fa fa-globe"></i> <%= I18n.t "terms.addexternuser"%></label><br>
<div class="well well-sm">
<div class="field">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-pencil-square-o" aria-hidden="true"></i></span>
<textarea id="External-Users-modal-Pad" class="form-control" placeholder="<%= I18n.t "terms.saisirmail"%>"/></textarea>
</div>
</div>
</div>
<div class="text-left">
<button id="add-users-modal-button" class="btn btn-primary">
<i class="fa fa-check"></i> <%= I18n.t "terms.valid"%>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
# Copyright (c) 2017 Robert Jean Steven <robert.steven.974@gmail.com>
#
# This file is part of Zourit.
#
# Zourit is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Zourit is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Zourit. If not, see <http://www.gnu.org/licenses/>.
json.array!(@users_groups) do |ug|
json.name ug[:name]
json.id ug[:id]
json.title ug[:title]
end
json.extract! pads_group, :id, :group_id, :pad_id, :created_at, :updated_at
json.url pads_group_url(pads_group, format: :json)
json.array!(@pads_groups) do |pads_group|
json.extract! pads_group, :id, :group_id, :pad_id
json.url pads_group_url(pads_group, format: :json)
end
\ No newline at end of file
json.partial! "pads_groups/pads_group", pads_group: @pads_group
json.array!(@pads_users) do |pads_user|
json.extract! pads_user, :id, :mail, :visio_id
json.url pads_user_url(pads_user, format: :json)
end
\ No newline at end of file
json.extract! @pads_user, :id, :mail, :pad_id, :created_at, :updated_at
......@@ -258,6 +258,7 @@ fr:
padname: "Nom du pad"
padlist: "Liste des pads"
modifpad: "Modifier le pad"
invitationpad: "Liste des personnes invité"
#about
version: "Version"
......
Rails.application.routes.draw do
resources :pads_users
resources :pads_groups
resources :pads
resources :visios
resources :domains
resources :users
#root 'accueil#index'
get 'users/:id/alias' => 'users#alias', :defaults => { :format => :json }
delete '/alias/delete.json' => 'users#delete_alias', :defaults => { :format => :json }
post '/alias/create.json' => 'users#create_alias', :defaults => { :format => :json }
......@@ -33,7 +36,9 @@ Rails.application.routes.draw do
post '/visios_users' => 'visios_users#create', :defaults => { :format => :json }
delete 'visios_users/:id' => 'visios_users#destroy', :defaults => { :format => :json }
get 'pads/:id/invitation' => 'pads#invitation'
get 'pads/:id/users' => 'pads#users', :defaults => { :format => :json }
delete 'pads/:id/users' => 'pads#destroy_users', :defaults => { :format => :json }
get 'dates' => "dates#index"
get 'pads' => "pads#show"
get 'compta' => "compta#index"
......
class CreatePadsGroups < ActiveRecord::Migration
def change
create_table :pads_groups do |t|
t.string :group_id
t.references :pad, index: true, foreign_key: true
t.timestamps null: false
end
end
end
class CreatePadsUsers < ActiveRecord::Migration
def change
create_table :pads_users do |t|
t.string :user_id
t.references :pad, index: true, foreign_key: true
t.timestamps null: false
end
end
end
class AddEmailAndUuidToPadUSers < ActiveRecord::Migration
def change
add_column :pads_users, :uuid, :string
add_column :pads_users, :mail, :string
end
end
class RemoveEmailToPadUSers < ActiveRecord::Migration
def change
remove_column :pads_users, :user_id, :string
end
end
......@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20190514053805) do
ActiveRecord::Schema.define(version: 20190515071530) do
create_table "config_modules", force: :cascade do |t|
t.string "name"
......@@ -46,6 +46,25 @@ ActiveRecord::Schema.define(version: 20190514053805) do
t.datetime "updated_at", null: false
end
create_table "pads_groups", force: :cascade do |t|
t.string "group_id"
t.integer "pad_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "pads_groups", ["pad_id"], name: "index_pads_groups_on_pad_id"
create_table "pads_users", force: :cascade do |t|
t.integer "pad_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "uuid"
t.string "mail"
end
add_index "pads_users", ["pad_id"], name: "index_pads_users_on_pad_id"
create_table "visios", force: :cascade do |t|
t.string "name"
t.text "comment"
......
require 'test_helper'
class PadsGroupsControllerTest < ActionController::TestCase
setup do
@pads_group = pads_groups(:one)
end
test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:pads_groups)
end
test "should get new" do
get :new
assert_response :success
end
test "should create pads_group" do
assert_difference('PadsGroup.count') do
post :create, pads_group: { group_id: @pads_group.group_id, pad_id: @pads_group.pad_id }
end
assert_redirected_to pads_group_path(assigns(:pads_group))
end
test "should show pads_group" do
get :show, id: @pads_group
assert_response :success
end
test "should get edit" do
get :edit, id: @pads_group
assert_response :success
end
test "should update pads_group" do
patch :update, id: @pads_group, pads_group: { group_id: @pads_group.group_id, pad_id: @pads_group.pad_id }
assert_redirected_to pads_group_path(assigns(:pads_group))
end
test "should destroy pads_group" do
assert_difference('PadsGroup.count', -1) do
delete :destroy, id: @pads_group
end
assert_redirected_to pads_groups_path
end
end
require 'test_helper'
class PadsUsersControllerTest < ActionController::TestCase
setup do
@pads_user = pads_users(:one)
end
test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:pads_users)
end
test "should get new" do
get :new
assert_response :success
end
test "should create pads_user" do
assert_difference('PadsUser.count') do
post :create, pads_user: { pad_id: @pads_user.pad_id, user_id: @pads_user.user_id }
end
assert_redirected_to pads_user_path(assigns(:pads_user))
end
test "should show pads_user" do
get :show, id: @pads_user
assert_response :success
end
test "should get edit" do
get :edit, id: @pads_user
assert_response :success
end
test "should update pads_user" do
patch :update, id: @pads_user, pads_user: { pad_id: @pads_user.pad_id, user_id: @pads_user.user_id }
assert_redirected_to pads_user_path(assigns(:pads_user))
end
test "should destroy pads_user" do
assert_difference('PadsUser.count', -1) do
delete :destroy, id: @pads_user
end
assert_redirected_to pads_users_path
end
end
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
group_id: MyString
pad_id:
two:
group_id: MyString
pad_id:
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
user_id: MyString
pad_id:
two:
user_id: MyString
pad_id:
require 'test_helper'
class PadsGroupTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
require 'test_helper'
class PadsUserTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment