Skip to content

Commit 3d57bfb

Browse files
committed
Merge branch 'master' into 10794-replication-fails
# Conflicts: # api/tests/mocha/controllers/replication-limit-log.spec.js # api/tests/mocha/controllers/users.spec.js
2 parents 75b7133 + f35733b commit 3d57bfb

74 files changed

Lines changed: 578 additions & 640 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,11 @@ jobs:
167167
with:
168168
mask-password: 'true'
169169

170+
- uses: actions/checkout@v4
170171
- name: Use Node.js ${{ env.NODE_VERSION }}
171172
uses: actions/setup-node@v4
172173
with:
173174
node-version: ${{ env.NODE_VERSION }}
174-
- uses: actions/checkout@v4
175175

176176
- name: Set system ulimit
177177
uses: ./.github/actions/bump-system-ulimit
@@ -294,11 +294,11 @@ jobs:
294294
with:
295295
mask-password: 'true'
296296

297+
- uses: actions/checkout@v4
297298
- name: Use Node.js ${{ env.NODE_VERSION }}
298299
uses: actions/setup-node@v4
299300
with:
300301
node-version: ${{ env.NODE_VERSION }}
301-
- uses: actions/checkout@v4
302302
- name: Download docker images artifacts
303303
uses: actions/download-artifact@v4
304304
with:

admin/src/js/controllers/edit-user.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ const moment = require('moment');
22
const passwordTester = require('simple-password-tester');
33
const phoneNumber = require('@medic/phone-number');
44
const CHT = require('@medic/cht-datasource');
5+
const constants = require('@medic/constants');
6+
const USER_ROLES = constants.USER_ROLES;
57
const PASSWORD_MINIMUM_LENGTH = 8;
68
const PASSWORD_MINIMUM_SCORE = 50;
79
const SHOW_PASSWORD_ICON = '/login/images/show-password.svg';
810
const HIDE_PASSWORD_ICON = '/login/images/hide-password.svg';
911
const USERNAME_ALLOWED_CHARS = /^[a-z0-9_-]+$/;
10-
const ADMIN_ROLE = '_admin';
12+
const ADMIN_ROLE = USER_ROLES.COUCHDB_ADMIN;
1113
const FIELDS_TO_IGNORE = [
1214
'currentPassword',
1315
'passwordConfirm',

admin/src/js/controllers/images-branding.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
const constants = require('@medic/constants');
2+
const DOC_IDS = constants.DOC_IDS;
3+
14
angular.module('controllers').controller('ImagesBrandingCtrl',
25
function(
36
$log,
@@ -11,7 +14,7 @@ angular.module('controllers').controller('ImagesBrandingCtrl',
1114
'ngInject';
1215
'use strict';
1316

14-
const DOC_ID = 'branding';
17+
const DOC_ID = DOC_IDS.BRANDING;
1518
const MAX_FILE_SIZE = 100000; // 100KB
1619

1720
$('#images-branding .choose').on('click', ev => {

admin/src/js/filters/resource-icon.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ angular.module('inboxFilters').filter('headerLogo',
2121
'use strict';
2222
'ngInject';
2323
return function(name) {
24-
return $sce.trustAsHtml(ResourceIcons.getImg(name, 'branding'));
24+
return $sce.trustAsHtml(ResourceIcons.getImg(name, DOC_IDS.BRANDING));
2525
};
2626
});
2727

admin/src/js/services/resource-icons.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ angular.module('inboxServices').factory('ResourceIcons',
1212
'ngInject';
1313

1414
const CSS_CLASS = ['resource-icon', 'header-logo', 'partner-image'];
15-
const ICON_DOC_IDS = [DOC_IDS.RESOURCES, 'branding', DOC_IDS.PARTNERS];
15+
const ICON_DOC_IDS = [DOC_IDS.RESOURCES, DOC_IDS.BRANDING, DOC_IDS.PARTNERS];
1616

1717
const cache = {
1818
resources: {

admin/src/js/services/session.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
const _ = require('lodash/core');
22
const constants = require('@medic/constants');
3+
const USER_ROLES = constants.USER_ROLES;
34
const COOKIE_NAME = 'userCtx';
4-
const ONLINE_ROLE = constants.USER_ROLES.ONLINE;
5+
const ONLINE_ROLE = USER_ROLES.ONLINE;
56

67
(function () {
78

@@ -96,7 +97,7 @@ const ONLINE_ROLE = constants.USER_ROLES.ONLINE;
9697

9798
const isAdmin = function(userCtx) {
9899
userCtx = userCtx || getUserCtx();
99-
return hasRole(userCtx, '_admin');
100+
return hasRole(userCtx, USER_ROLES.COUCHDB_ADMIN);
100101
};
101102

102103
return {

admin/tests/unit/controllers/images-branding.spec.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const { DOC_IDS } = require('@medic/constants');
2+
13
describe('ImagesBrandingCtrl', function () {
24

35
'use strict';
@@ -40,7 +42,7 @@ describe('ImagesBrandingCtrl', function () {
4042
//https://github.com/medic/cht-core/issues/8026
4143
it('should not fail when branding doc is empty', async () => {
4244

43-
db.get.withArgs('branding', {attachments: true}).resolves({});
45+
db.get.withArgs(DOC_IDS.BRANDING, {attachments: true}).resolves({});
4446
$translate.resolves('some message');
4547
Translate.fieldIsRequired.resolves('some validation messsage');
4648

@@ -52,7 +54,7 @@ describe('ImagesBrandingCtrl', function () {
5254
});
5355
it('should not fail when resources is null', async () => {
5456

55-
db.get.withArgs('branding', {attachments: true}).resolves({resources: null});
57+
db.get.withArgs(DOC_IDS.BRANDING, {attachments: true}).resolves({resources: null});
5658
$translate.resolves('some message');
5759
Translate.fieldIsRequired.resolves('some validation messsage');
5860

admin/tests/unit/services/auth.spec.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const { USER_ROLES: { COUCHDB_ADMIN } } = require('@medic/constants');
2+
13
describe('Auth service', function() {
24

35
'use strict';
@@ -58,7 +60,7 @@ describe('Auth service', function() {
5860
});
5961

6062
it('true when user is db admin', async () => {
61-
userCtx.returns({ roles: ['_admin'] });
63+
userCtx.returns({ roles: [COUCHDB_ADMIN] });
6264
Settings.resolves({ permissions: { can_edit: [ 'chw' ] } });
6365
const result = await service.has(['can_backup_facilities']);
6466
chai.expect(result).to.be.true;
@@ -176,7 +178,7 @@ describe('Auth service', function() {
176178
});
177179

178180
it('false when admin and !permission', async () => {
179-
userCtx.returns({ roles: ['_admin'] });
181+
userCtx.returns({ roles: [COUCHDB_ADMIN] });
180182
Settings.resolves({ permissions: {} });
181183
const result = await service.has(['!can_backup_facilities']);
182184
chai.expect(result).to.be.false;
@@ -246,21 +248,21 @@ describe('Auth service', function() {
246248
});
247249

248250
it('true when admin and no disallowed permissions', async () => {
249-
userCtx.returns({ roles: ['_admin'] });
251+
userCtx.returns({ roles: [COUCHDB_ADMIN] });
250252
Settings.resolves({ permissions: { can_edit: [ 'chw' ] } });
251253
const result = await service.any([['can_backup_facilities'], ['can_export_messages'], ['somepermission']]);
252254
chai.expect(result).to.be.true;
253255
});
254256

255257
it('true when admin and some disallowed permissions', async () => {
256-
userCtx.returns({ roles: ['_admin'] });
258+
userCtx.returns({ roles: [COUCHDB_ADMIN] });
257259
Settings.resolves({ permissions: { can_edit: [ 'chw' ] } });
258260
const result = await service.any([['!can_backup_facilities'], ['!can_export_messages'], ['somepermission']]);
259261
chai.expect(result).to.be.true;
260262
});
261263

262264
it('false when admin and all disallowed permissions', async () => {
263-
userCtx.returns({ roles: ['_admin'] });
265+
userCtx.returns({ roles: [COUCHDB_ADMIN] });
264266
Settings.resolves({ permissions: {} });
265267
const result = await service.any([['!can_backup_facilities'], ['!can_export_messages'], ['!somepermission']]);
266268
chai.expect(result).to.be.false;

admin/tests/unit/services/session.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
describe('Session service', function() {
22

33
'use strict';
4+
const { USER_ROLES: { COUCHDB_ADMIN } } = require('@medic/constants');
45

56
let service;
67
let ipCookie;
@@ -149,7 +150,7 @@ describe('Session service', function() {
149150
});
150151

151152
it('returns true for _admin', function(done) {
152-
ipCookie.returns({ roles: [ '_admin' ] });
153+
ipCookie.returns({ roles: [COUCHDB_ADMIN] });
153154
const actual = service.isAdmin();
154155
chai.expect(actual).to.equal(true);
155156
done();

api/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ COPY --chown=root:root --chmod=755 api ./api
1818
RUN chown -R root:1000 /service/api/build/static/webapp && \
1919
chmod -R 775 /service/api/build/static/webapp
2020

21+
ENV NODE_ENV=production
2122
ENV NODE_PATH=/service/api/node_modules
2223
USER 1000
2324
ENTRYPOINT ["/bin/bash", "/service/api/docker-entrypoint.sh", "main"]

0 commit comments

Comments
 (0)