Skip to content

Commit

Permalink
[EVENT-845] Disable editing staff profile info (#854)
Browse files Browse the repository at this point in the history
* Disable editing staff profile info

* Handle null profile
  • Loading branch information
canac authored May 1, 2024
1 parent 91c26d5 commit 1fe57f8
Show file tree
Hide file tree
Showing 4 changed files with 180 additions and 4 deletions.
13 changes: 12 additions & 1 deletion app/scripts/directives/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@ angular.module('confRegistrationWebApp').directive('nameQuestion', function () {
return {
templateUrl: nameQuestionTemplate,
restrict: 'E',
controller: function ($scope) {
controller: function ($rootScope, $scope) {
if (!$scope.answer && !$scope.answer.value) {
$scope.answer.value = {};
}

const user = $rootScope.globalUser();
$scope.lockedStaffProfileBlock = Boolean(
user && user.employeeId && $scope.block.profileType === 'NAME',
);
},
};
});
Expand Down Expand Up @@ -64,6 +69,12 @@ angular
return {
templateUrl: emailQuestionTemplate,
restrict: 'E',
controller: function ($rootScope, $scope) {
const user = $rootScope.globalUser();
$scope.lockedStaffProfileBlock = Boolean(
user && user.employeeId && $scope.block.profileType === 'EMAIL',
);
},
};
});

Expand Down
2 changes: 1 addition & 1 deletion app/views/blocks/emailQuestion.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
ng-model="answer.value"
ng-model-options="{ debounce: 1000 }"
ng-required="block.required"
ng-disabled="editBlock"
ng-disabled="editBlock || lockedStaffProfileBlock"
/>
<span class="help-block help-block-hidden" translate
>Please enter a valid email such as: example@example.com</span
Expand Down
4 changes: 2 additions & 2 deletions app/views/blocks/nameQuestion.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
ng-model="answer.value.firstName"
ng-model-options="{ debounce: 300 }"
ng-required="block.required"
ng-disabled="editBlock"
ng-disabled="editBlock || lockedStaffProfileBlock"
/>
</div>
<div class="col-sm-6">
Expand All @@ -20,7 +20,7 @@
ng-model="answer.value.lastName"
ng-model-options="{ debounce: 300 }"
ng-required="block.required"
ng-disabled="editBlock"
ng-disabled="editBlock || lockedStaffProfileBlock"
/>
</div>
</div>
165 changes: 165 additions & 0 deletions test/spec/directives/block.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,171 @@ import _ from 'lodash';
describe('Directive: blocks', () => {
beforeEach(angular.mock.module('confRegistrationWebApp'));

describe('nameQuestion', () => {
let $compile, $rootScope, $scope;
beforeEach(inject((_$compile_, _$rootScope_, $templateCache, testData) => {
$compile = _$compile_;
$rootScope = _$rootScope_;

$scope = $rootScope.$new();
$scope.answer = {};
$templateCache.put('views/blocks/nameQuestion.html', '');

$scope.block = _.cloneDeep(
testData.conference.registrationPages[1].blocks[1],
);
}));

describe('lockedStaffProfileBlock', () => {
describe('for staff', () => {
beforeEach(() => {
spyOn($rootScope, 'globalUser').and.returnValue({
employeeId: '0123456',
});
});

it('is true when the profile type is NAME', () => {
$compile('<name-question></name-question>')($scope);
$scope.$digest();

expect($scope.lockedStaffProfileBlock).toBe(true);
});

it('is false when the profile type is not NAME', () => {
$scope.block.profileType = null;
$compile('<name-question></name-question>')($scope);
$scope.$digest();

expect($scope.lockedStaffProfileBlock).toBe(false);
});
});

describe('for non-staff', () => {
beforeEach(() => {
spyOn($rootScope, 'globalUser').and.returnValue({ employeeId: null });
});

it('is false when the profile type is NAME', () => {
$compile('<name-question></name-question>')($scope);
$scope.$digest();

expect($scope.lockedStaffProfileBlock).toBe(false);
});

it('is false when the profile type is not NAME', () => {
$scope.block.profileType = null;
$compile('<name-question></name-question>')($scope);
$scope.$digest();

expect($scope.lockedStaffProfileBlock).toBe(false);
});
});

describe('with no profile', () => {
beforeEach(() => {
spyOn($rootScope, 'globalUser').and.returnValue(null);
});

it('is false when the profile type is NAME', () => {
$compile('<name-question></name-question>')($scope);
$scope.$digest();

expect($scope.lockedStaffProfileBlock).toBe(false);
});

it('is false when the profile type is not NAME', () => {
$scope.block.profileType = null;
$compile('<name-question></name-question>')($scope);
$scope.$digest();

expect($scope.lockedStaffProfileBlock).toBe(false);
});
});
});
});

describe('emailQuestion', () => {
let $compile, $rootScope, $scope;
beforeEach(inject((_$compile_, _$rootScope_, $templateCache, testData) => {
$compile = _$compile_;
$rootScope = _$rootScope_;

$scope = $rootScope.$new();
$templateCache.put('views/blocks/emailQuestion.html', '');

$scope.block = _.cloneDeep(
testData.conference.registrationPages[0].blocks[0],
);
}));

describe('lockedStaffProfileBlock', () => {
describe('for staff', () => {
beforeEach(() => {
spyOn($rootScope, 'globalUser').and.returnValue({
employeeId: '0123456',
});
});

it('is true when the profile type is EMAIL', () => {
$compile('<email-question></email-question>')($scope);
$scope.$digest();

expect($scope.lockedStaffProfileBlock).toBe(true);
});

it('is false when the profile type is not EMAIL', () => {
$scope.block.profileType = null;
$compile('<email-question></email-question>')($scope);
$scope.$digest();

expect($scope.lockedStaffProfileBlock).toBe(false);
});
});

describe('for non-staff', () => {
beforeEach(() => {
spyOn($rootScope, 'globalUser').and.returnValue({ employeeId: null });
});

it('is false when the profile type is EMAIL', () => {
$compile('<email-question></email-question>')($scope);
$scope.$digest();

expect($scope.lockedStaffProfileBlock).toBe(false);
});

it('is false when the profile type is not EMAIL', () => {
$scope.block.profileType = null;
$compile('<email-question></email-question>')($scope);
$scope.$digest();

expect($scope.lockedStaffProfileBlock).toBe(false);
});
});

describe('with no profile', () => {
beforeEach(() => {
spyOn($rootScope, 'globalUser').and.returnValue(null);
});

it('is false when the profile type is EMAIL', () => {
$compile('<email-question></email-question>')($scope);
$scope.$digest();

expect($scope.lockedStaffProfileBlock).toBe(false);
});

it('is false when the profile type is not EMAIL', () => {
$scope.block.profileType = null;
$compile('<email-question></email-question>')($scope);
$scope.$digest();

expect($scope.lockedStaffProfileBlock).toBe(false);
});
});
});
});

describe('radioQuestion', () => {
let $compile, $rootScope, $scope, $timeout;
beforeEach(inject((
Expand Down

0 comments on commit 1fe57f8

Please sign in to comment.