[fix #1601] accept demandes in manager

This commit is contained in:
simon lehericey 2018-03-21 10:28:17 +01:00
parent 9e566596fa
commit 9eb28faa10
3 changed files with 35 additions and 0 deletions

View file

@ -3,13 +3,40 @@ module Manager
PIPEDRIVE_PEOPLE_URL = 'https://api.pipedrive.com/v1/persons'
PIPEDRIVE_POSTE_ATTRIBUTE_ID = '33a790746f1713d712fe97bcce9ac1ca6374a4d6'
PIPEDRIVE_DEV_ID = '2748449'
PIPEDRIVE_CAMILLE_ID = '3189424'
def index
@pending_demandes = pending_demandes
end
def create_administrateur
administrateur = current_administration.invite_admin(create_administrateur_params[:email])
if administrateur.errors.empty?
change_person_owner(create_administrateur_params[:person_id], PIPEDRIVE_CAMILLE_ID)
flash.notice = "Administrateur créé"
redirect_to manager_demandes_path
else
flash.now.alert = administrateur.errors.full_messages
@pending_demandes = pending_demandes
render :index
end
end
private
def change_person_owner(person_id, owner_id)
url = PIPEDRIVE_PEOPLE_URL + "/#{person_id}?api_token=#{PIPEDRIVE_TOKEN}"
params = { 'owner_id': owner_id }
RestClient.put(url, params.to_json, { content_type: :json })
end
def create_administrateur_params
params.require(:administrateur).permit(:email, :person_id)
end
def pending_demandes
already_approved_emails = Administrateur
.where(email: demandes.map { |d| d[:email] })

View file

@ -18,6 +18,8 @@
<%= key %>
</th>
<% end %>
<th class="cell-label cell-label--string cell-label--false" scope="col" role="columnheader" aria-sort="none">
</th>
</thead>
<tbody>
<% @pending_demandes.each do |demande| %>
@ -27,6 +29,11 @@
<%= demande[key] %>
</td>
<% end %>
<td class="cell-data cell-data--string">
<%= button_to('Créer',
manager_demandes_create_administrateur_path,
params: { administrateur: { email: demande[:email], person_id: demande[:person_id] } }) %>
</td>
</tr>
<% end %>
</tbody>

View file

@ -11,6 +11,7 @@ Rails.application.routes.draw do
end
resources :demandes, only: [:index]
post 'demandes/create_administrateur'
authenticate :administration do
match "/delayed_job" => DelayedJobWeb, :anchor => false, :via => [:get, :post]