Skip to content

Commit e86ebca

Browse files
committed
feat: Anonymous logs are now possible
1 parent 0eec605 commit e86ebca

7 files changed

Lines changed: 54 additions & 19 deletions

File tree

lib/database/adapters/UserAdapter.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,20 @@ class UserAdapter {
2121
* @param {Object} databaseObject Object to convert.
2222
* @returns {Object} Converted entity object.
2323
*/
24-
static toEntity({ id, externalId, name }) {
25-
return { id, externalId, name };
24+
static toEntity(databaseObject) {
25+
if (databaseObject) {
26+
return {
27+
id: databaseObject.id,
28+
externalId: databaseObject.externalId,
29+
name: databaseObject.name,
30+
};
31+
} else {
32+
return {
33+
id: 0,
34+
externalId: 0,
35+
name: 'Anonymous',
36+
};
37+
}
2638
}
2739

2840
/**
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* @license
3+
* Copyright CERN and copyright holders of ALICE O2. This software is
4+
* distributed under the terms of the GNU General Public License v3 (GPL
5+
* Version 3), copied verbatim in the file "COPYING".
6+
*
7+
* See http://alice-o2.web.cern.ch/license for full licensing information.
8+
*
9+
* In applying this license CERN does not waive the privileges and immunities
10+
* granted to it by virtue of its status as an Intergovernmental Organization
11+
* or submit itself to any jurisdiction.
12+
*/
13+
14+
module.exports = {
15+
up: (queryInterface, Sequelize) => queryInterface.changeColumn('logs', 'user_id', {
16+
type: Sequelize.INTEGER,
17+
allowNull: true,
18+
}),
19+
20+
down: (queryInterface, Sequelize) => queryInterface.changeColumn('logs', 'user_id', {
21+
type: Sequelize.INTEGER,
22+
allowNull: false,
23+
}),
24+
25+
};

lib/database/seeders/20200508094502-logs.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ module.exports = {
3535
title: 'Third entry',
3636
subtype: 'announcement',
3737
origin: 'human',
38-
user_id: 1,
3938
text: 'Cake at the particle accelerator!',
4039
parent_log_id: 1,
4140
root_log_id: 1,

lib/public/components/Post/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ const activeFields = (model) => ({
6060
name: 'Tags',
6161
visible: true,
6262
format: (tags) => tags.length > 0 ? tags.map(({ text }) => text).join(', ') : 'None',
63-
6463
},
6564
runs: {
6665
name: 'Runs',
@@ -115,7 +114,7 @@ const entry = (model, post, index, highlight) => {
115114
h('tbody', Object.entries(postFields)
116115
.map(([key, { name, format, visible }]) => visible && h(`tr#post${index}-${key}`, [
117116
h('td.text-right', { style: 'font-weight: bold' }, `${name}:`),
118-
h('td', post[key] && format ? format(post[key]) : post[key] || 'None'),
117+
h('td', format ? format(post[key]) : post[key]),
119118
]))),
120119
]),
121120
]),

lib/usecases/log/CreateLogUseCase.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class CreateLogUseCase {
4646
const { parentLogId, tags } = body;
4747

4848
const log = await TransactionHelper.provide(async () => {
49-
body.userId = dto.session.id;
49+
body.userId = dto.session.id || null;
5050

5151
if (parentLogId) {
5252
const parentLog = await new GetLogUseCase().execute({ params: { logId: parentLogId } });

spec/openapi-source.yaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,19 +1196,24 @@ components:
11961196
additionalProperties: false
11971197
User:
11981198
allOf:
1199-
- $ref: '#/components/schemas/Entity'
12001199
- description: Describes an intervention or an event that happened.
12011200
type: object
12021201
properties:
1202+
id:
1203+
description: The unique identifier of this entity.
1204+
type: integer
1205+
format: int64
1206+
minimum: 0
12031207
externalId:
12041208
description: The unique CERN identifier of this user.
12051209
type: integer
12061210
format: int64
1207-
minimum: 1
1211+
minimum: 0
12081212
name:
12091213
type: string
12101214
description: Name of the user.
12111215
required:
1216+
- id
12121217
- externalId
12131218
- name
12141219
additionalProperties: false

spec/openapi.yaml

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Generated on Sun, 30 Aug 2020 09:11:14 GMT
1+
# Generated on Mon, 14 Sep 2020 22:40:53 GMT
22

33
openapi: 3.0.0
44
info:
@@ -1342,24 +1342,19 @@ components:
13421342
description: Describes an intervention or an event that happened.
13431343
type: object
13441344
properties:
1345-
createdAt:
1346-
description: Unix timestamp when this entity was created.
1347-
type: integer
1348-
format: int64
13491345
externalId:
13501346
description: The unique CERN identifier of this user.
13511347
type: integer
13521348
format: int64
1353-
minimum: 1
1349+
minimum: 0
13541350
id:
1355-
$ref: '#/components/schemas/EntityId'
1351+
description: The unique identifier of this entity.
1352+
type: integer
1353+
format: int64
1354+
minimum: 0
13561355
name:
13571356
type: string
13581357
description: Name of the user.
1359-
updatedAt:
1360-
description: Unix timestamp when this entity was last updated.
1361-
type: integer
1362-
format: int64
13631358
required:
13641359
- externalId
13651360
- id

0 commit comments

Comments
 (0)