1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-17 06:52:27 +01:00

[managers] trainings management

This commit is contained in:
Sylvain 2020-04-27 17:28:11 +02:00
parent d376aa400c
commit 8c610ea336
5 changed files with 18 additions and 12 deletions

View File

@ -45,7 +45,7 @@
</div> </div>
<div class="col-sm-12 col-md-12 col-lg-3"> <div class="col-sm-12 col-md-12 col-lg-3">
<div class="m text-center" ng-show="AuthService.isAuthorized('admin')"> <div class="m text-center" ng-show="isAuthorized('admin')">
<a class="btn btn-default export-xls-button" <a class="btn btn-default export-xls-button"
ng-href="api/availabilities/export_index.xlsx" ng-href="api/availabilities/export_index.xlsx"
target="export-frame" target="export-frame"

View File

@ -35,7 +35,7 @@
<uib-tabset justified="true" active="tabs.active"> <uib-tabset justified="true" active="tabs.active">
<uib-tab heading="{{ 'app.admin.trainings.trainings' | translate }}" index="0" class="manage-trainings"> <uib-tab heading="{{ 'app.admin.trainings.trainings' | translate }}" index="0" class="manage-trainings">
<div class="m-t m-b"> <div class="m-t m-b">
<button type="button" class="btn btn-warning" ui-sref="app.admin.trainings_new"> <button type="button" class="btn btn-warning" ui-sref="app.admin.trainings_new" ng-show="isAuthorized('admin')">
<i class="fa fa-plus m-r"></i> <i class="fa fa-plus m-r"></i>
<span translate>{{ 'app.admin.trainings.add_a_new_training' }}</span> <span translate>{{ 'app.admin.trainings.add_a_new_training' }}</span>
</button> </button>
@ -64,7 +64,7 @@
<td>{{ showMachines(training) }}</td> <td>{{ showMachines(training) }}</td>
<td>{{ training.nb_total_places }}</td> <td>{{ training.nb_total_places }}</td>
<td> <td>
<div class="buttons"> <div class="buttons" ng-show="isAuthorized('admin')">
<button class="btn btn-default" ui-sref="app.admin.trainings_edit({id:training.id})"> <button class="btn btn-default" ui-sref="app.admin.trainings_edit({id:training.id})">
<i class="fa fa-edit"></i> {{ 'app.shared.buttons.edit' | translate }} <i class="fa fa-edit"></i> {{ 'app.shared.buttons.edit' | translate }}
</button> </button>

View File

@ -40,8 +40,8 @@
<li><a ui-sref="app.logged.dashboard.events" translate>{{ 'app.public.common.my_events' }}</a></li> <li><a ui-sref="app.logged.dashboard.events" translate>{{ 'app.public.common.my_events' }}</a></li>
<li><a ui-sref="app.logged.dashboard.invoices" ng-hide="fablabWithoutInvoices" translate>{{ 'app.public.common.my_invoices' }}</a></li> <li><a ui-sref="app.logged.dashboard.invoices" ng-hide="fablabWithoutInvoices" translate>{{ 'app.public.common.my_invoices' }}</a></li>
<li ng-hide="fablabWithoutWallet"><a ui-sref="app.logged.dashboard.wallet" translate>{{ 'app.public.common.my_wallet' }}</a></li> <li ng-hide="fablabWithoutWallet"><a ui-sref="app.logged.dashboard.wallet" translate>{{ 'app.public.common.my_wallet' }}</a></li>
<li class="divider" ng-if="currentUser.role === 'admin'"></li> <li class="divider" ng-if="isAuthorized(['admin', 'manager'])"></li>
<li><a class="text-black pointer" ng-click="help($event)" ng-if="currentUser.role === 'admin'"><i class="fa fa-question-circle"></i> <span translate>{{ 'app.public.common.help' }}</span> </a></li> <li><a class="text-black pointer" ng-click="help($event)" ng-if="isAuthorized(['admin', 'manager'])"><i class="fa fa-question-circle"></i> <span translate>{{ 'app.public.common.help' }}</span> </a></li>
<li class="divider"></li> <li class="divider"></li>
<li><a class="text-black pointer" ng-click="logout($event)"><i class="fa fa-power-off"></i> {{ 'app.public.common.sign_out' | translate }}</a></li> <li><a class="text-black pointer" ng-click="logout($event)"><i class="fa fa-power-off"></i> {{ 'app.public.common.sign_out' | translate }}</a></li>
</ul> </ul>

View File

@ -41,7 +41,8 @@ class API::TrainingsController < API::ApiController
end end
head :no_content head :no_content
elsif @training.update(training_params) elsif current_user.admin? && @training.update(training_params)
# only admins can fully update a training, not managers
render :show, status: :ok, location: @training render :show, status: :ok, location: @training
else else
render json: @training.errors, status: :unprocessable_entity render json: @training.errors, status: :unprocessable_entity

View File

@ -1,3 +1,6 @@
# frozen_string_literal: true
# Check the access policies for API::TrainingsController
class TrainingPolicy < ApplicationPolicy class TrainingPolicy < ApplicationPolicy
class Scope < Scope class Scope < Scope
def resolve def resolve
@ -5,17 +8,19 @@ class TrainingPolicy < ApplicationPolicy
end end
end end
%w(create update).each do |action| def create
define_method "#{action}?" do user.admin?
user.admin? end
end
def update?
user.admin? || user.manager?
end end
def destroy? def destroy?
user.admin? and record.destroyable? user.admin? && record.destroyable?
end end
def availabilities? def availabilities?
user.admin? user.admin? || user.manager?
end end
end end