Added ACL + unit tests
gitea/salix/pipeline/head Something is wrong with the build of this commit Details

This commit is contained in:
Joan Sanchez 2020-07-15 11:35:34 +02:00
parent 91e739547b
commit 2f9d80be7a
5 changed files with 78 additions and 6 deletions

View File

@ -4,8 +4,8 @@
auto-load="true"> auto-load="true">
</vn-crud-model> </vn-crud-model>
<div class="vn-w-lg"> <div class="vn-w-lg">
<vn-card class="vn-pa-sm calendars" style="position:relative" > <vn-card class="vn-pa-sm calendars">
<vn-icon icon="info" color-marginal style="position: absolute; top: 16px;right: 16px" <vn-icon ng-if="::$ctrl.isSubordinate" icon="info" color-marginal
vn-tooltip="To start adding absences, click an absence type from the right menu and then on the day you want to add an absence"> vn-tooltip="To start adding absences, click an absence type from the right menu and then on the day you want to add an absence">
</vn-icon> </vn-icon>
<vn-calendar <vn-calendar
@ -30,7 +30,7 @@
</div> </div>
</div> </div>
<div class="vn-pt-md" style="overflow: hidden;"> <div class="vn-pt-md" style="overflow: hidden;">
<vn-chip ng-repeat="absenceType in absenceTypes" class="selectable" <vn-chip ng-repeat="absenceType in absenceTypes" ng-class="::{'selectable': $ctrl.isSubordinate}"
ng-click="$ctrl.pick(absenceType)"> ng-click="$ctrl.pick(absenceType)">
<vn-avatar <vn-avatar
ng-style="{backgroundColor: absenceType.rgb}"> ng-style="{backgroundColor: absenceType.rgb}">

View File

@ -44,8 +44,16 @@ class Controller extends Section {
set worker(value) { set worker(value) {
this._worker = value; this._worker = value;
if (value) if (value) {
this.refresh().then(() => this.repaint()); this.refresh().then(() => this.repaint());
this.getIsSubordinate();
}
}
getIsSubordinate() {
this.$http.get(`Workers/${this.worker.id}/isSubordinate`).then(res =>
this.isSubordinate = res.data
);
} }
onData(data) { onData(data) {
@ -98,6 +106,7 @@ class Controller extends Section {
} }
pick(absenceType) { pick(absenceType) {
if (!this.isSubordinate) return;
if (absenceType == this.absenceType) if (absenceType == this.absenceType)
absenceType = null; absenceType = null;

View File

@ -12,8 +12,9 @@ describe('Worker', () => {
beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_) => { beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_) => {
$scope = $rootScope.$new(); $scope = $rootScope.$new();
$httpBackend = _$httpBackend_; $httpBackend = _$httpBackend_;
const $element = angular.element('<vn-worker-calencar></vn-worker-calencar>'); const $element = angular.element('<vn-worker-calendar></vn-worker-calendar>');
controller = $componentController('vnWorkerCalendar', {$element, $scope}); controller = $componentController('vnWorkerCalendar', {$element, $scope});
controller.isSubordinate = true;
})); }));
describe('started property', () => { describe('started property', () => {
@ -44,6 +45,8 @@ describe('Worker', () => {
describe('worker() setter', () => { describe('worker() setter', () => {
it(`should perform a get query and set the reponse data on the model`, () => { it(`should perform a get query and set the reponse data on the model`, () => {
jest.spyOn(controller, 'getIsSubordinate').mockReturnThis();
let today = new Date(); let today = new Date();
let tomorrow = new Date(today.getTime()); let tomorrow = new Date(today.getTime());
@ -73,11 +76,14 @@ describe('Worker', () => {
expect(events[tomorrow.getTime()].name).toEqual('Easter'); expect(events[tomorrow.getTime()].name).toEqual('Easter');
expect(events[yesterday.getTime()].name).toEqual('Leave'); expect(events[yesterday.getTime()].name).toEqual('Leave');
expect(events[yesterday.getTime()].color).toEqual('#bbb'); expect(events[yesterday.getTime()].color).toEqual('#bbb');
expect(controller.getIsSubordinate).toHaveBeenCalledWith();
}); });
}); });
describe('formatDay()', () => { describe('formatDay()', () => {
it(`should set the day element style`, () => { it(`should set the day element style`, () => {
jest.spyOn(controller, 'getIsSubordinate').mockReturnThis();
let today = new Date(); let today = new Date();
$httpBackend.whenRoute('GET', 'WorkerCalendars/absences') $httpBackend.whenRoute('GET', 'WorkerCalendars/absences')
@ -99,5 +105,54 @@ describe('Worker', () => {
expect(dayNumber.style.backgroundColor).toEqual('rgb(0, 0, 0)'); expect(dayNumber.style.backgroundColor).toEqual('rgb(0, 0, 0)');
}); });
}); });
describe('pick()', () => {
it(`should set the absenceType property to null if they match with the current one`, () => {
const absenceType = {id: 1, name: 'Holiday'};
controller.absenceType = absenceType;
controller.pick(absenceType);
expect(controller.absenceType).toBeNull();
});
it(`should set the absenceType property`, () => {
const absenceType = {id: 1, name: 'Holiday'};
const expectedAbsence = {id: 2, name: 'Leave of absence'};
controller.absenceType = absenceType;
controller.pick(expectedAbsence);
expect(controller.absenceType).toEqual(expectedAbsence);
});
});
describe('onSelection()', () => {
it(`should show an snackbar message if no absence type is selected`, () => {
jest.spyOn(controller.vnApp, 'showMessage').mockReturnThis();
const $event = {};
const $days = [];
controller.onSelection($event, $days);
expect(controller.vnApp.showMessage).toHaveBeenCalledWith('Choose an absence type from the right menu');
});
it(`should call to the create() method`, () => {
jest.spyOn(controller, 'create').mockReturnThis();
const selectedDay = new Date();
const $event = {
target: {
closest: () => {
return {$ctrl: {}};
}
}
};
const $days = [selectedDay];
controller.absenceType = {id: 1};
controller.onSelection($event, $days);
expect(controller.create).toHaveBeenCalledWith(jasmine.any(Object), selectedDay);
});
});
}); });
}); });

View File

@ -3,4 +3,5 @@ Holidays: Vacaciones
Used: Utilizados Used: Utilizados
of: de of: de
days: días days: días
Choose an absence type from the right menu: Elige un tipo de ausencia desde el menú de la derecha Choose an absence type from the right menu: Elige un tipo de ausencia desde el menú de la derecha
To start adding absences, click an absence type from the right menu and then on the day you want to add an absence: Para empezar a añadir ausencias, haz clic en un tipo de ausencia desde el menu de la derecha y después en el día que quieres añadir la ausencia

View File

@ -2,6 +2,7 @@
vn-worker-calendar { vn-worker-calendar {
.calendars { .calendars {
position: relative;
display: flex; display: flex;
flex-wrap: wrap; flex-wrap: wrap;
justify-content: center; justify-content: center;
@ -29,4 +30,10 @@ vn-worker-calendar {
text-align: center; text-align: center;
color: white color: white
} }
vn-icon[icon="info"] {
position: absolute;
top: 16px;
right: 16px
}
} }