diff --git a/lib/database/adapters/UserAdapter.js b/lib/database/adapters/UserAdapter.js index 38e3e87ea8..15ef006ab8 100644 --- a/lib/database/adapters/UserAdapter.js +++ b/lib/database/adapters/UserAdapter.js @@ -21,8 +21,20 @@ class UserAdapter { * @param {Object} databaseObject Object to convert. * @returns {Object} Converted entity object. */ - static toEntity({ id, externalId, name }) { - return { id, externalId, name }; + static toEntity(databaseObject) { + if (databaseObject) { + return { + id: databaseObject.id, + externalId: databaseObject.externalId, + name: databaseObject.name, + }; + } else { + return { + id: 0, + externalId: 0, + name: 'Anonymous', + }; + } } /** diff --git a/lib/database/migrations/20200914120527-logs-remove-user-constraint.js b/lib/database/migrations/20200914120527-logs-remove-user-constraint.js new file mode 100644 index 0000000000..e98dfd1e18 --- /dev/null +++ b/lib/database/migrations/20200914120527-logs-remove-user-constraint.js @@ -0,0 +1,25 @@ +/** + * @license + * Copyright CERN and copyright holders of ALICE O2. This software is + * distributed under the terms of the GNU General Public License v3 (GPL + * Version 3), copied verbatim in the file "COPYING". + * + * See http://alice-o2.web.cern.ch/license for full licensing information. + * + * In applying this license CERN does not waive the privileges and immunities + * granted to it by virtue of its status as an Intergovernmental Organization + * or submit itself to any jurisdiction. + */ + +module.exports = { + up: (queryInterface, Sequelize) => queryInterface.changeColumn('logs', 'user_id', { + type: Sequelize.INTEGER, + allowNull: true, + }), + + down: (queryInterface, Sequelize) => queryInterface.changeColumn('logs', 'user_id', { + type: Sequelize.INTEGER, + allowNull: false, + }), + +}; diff --git a/lib/database/seeders/20200508094502-logs.js b/lib/database/seeders/20200508094502-logs.js index 32b08f9c05..f0e5df0b44 100644 --- a/lib/database/seeders/20200508094502-logs.js +++ b/lib/database/seeders/20200508094502-logs.js @@ -35,7 +35,6 @@ module.exports = { title: 'Third entry', subtype: 'announcement', origin: 'human', - user_id: 1, text: 'Cake at the particle accelerator!', parent_log_id: 1, root_log_id: 1, diff --git a/lib/public/components/Post/index.js b/lib/public/components/Post/index.js index 3db36d5d84..6f2063d6bd 100644 --- a/lib/public/components/Post/index.js +++ b/lib/public/components/Post/index.js @@ -60,7 +60,6 @@ const activeFields = (model) => ({ name: 'Tags', visible: true, format: (tags) => tags.length > 0 ? tags.map(({ text }) => text).join(', ') : 'None', - }, runs: { name: 'Runs', @@ -115,7 +114,7 @@ const entry = (model, post, index, highlight) => { h('tbody', Object.entries(postFields) .map(([key, { name, format, visible }]) => visible && h(`tr#post${index}-${key}`, [ h('td.text-right', { style: 'font-weight: bold' }, `${name}:`), - h('td', post[key] && format ? format(post[key]) : post[key] || 'None'), + h('td', format ? format(post[key]) : post[key]), ]))), ]), ]), diff --git a/lib/usecases/log/CreateLogUseCase.js b/lib/usecases/log/CreateLogUseCase.js index 5e55371c21..3657ac24aa 100644 --- a/lib/usecases/log/CreateLogUseCase.js +++ b/lib/usecases/log/CreateLogUseCase.js @@ -46,7 +46,7 @@ class CreateLogUseCase { const { parentLogId, tags } = body; const log = await TransactionHelper.provide(async () => { - body.userId = dto.session.id; + body.userId = dto.session.id || null; if (parentLogId) { const parentLog = await new GetLogUseCase().execute({ params: { logId: parentLogId } }); diff --git a/spec/openapi-source.yaml b/spec/openapi-source.yaml index 319f926603..b7b9d12957 100644 --- a/spec/openapi-source.yaml +++ b/spec/openapi-source.yaml @@ -1196,19 +1196,24 @@ components: additionalProperties: false User: allOf: - - $ref: '#/components/schemas/Entity' - description: Describes an intervention or an event that happened. type: object properties: + id: + description: The unique identifier of this entity. + type: integer + format: int64 + minimum: 0 externalId: description: The unique CERN identifier of this user. type: integer format: int64 - minimum: 1 + minimum: 0 name: type: string description: Name of the user. required: + - id - externalId - name additionalProperties: false diff --git a/spec/openapi.yaml b/spec/openapi.yaml index 1d2d6ec5f0..a0468c7193 100644 --- a/spec/openapi.yaml +++ b/spec/openapi.yaml @@ -1,4 +1,4 @@ -# Generated on Sun, 30 Aug 2020 09:11:14 GMT +# Generated on Mon, 14 Sep 2020 22:40:53 GMT openapi: 3.0.0 info: @@ -1342,24 +1342,19 @@ components: description: Describes an intervention or an event that happened. type: object properties: - createdAt: - description: Unix timestamp when this entity was created. - type: integer - format: int64 externalId: description: The unique CERN identifier of this user. type: integer format: int64 - minimum: 1 + minimum: 0 id: - $ref: '#/components/schemas/EntityId' + description: The unique identifier of this entity. + type: integer + format: int64 + minimum: 0 name: type: string description: Name of the user. - updatedAt: - description: Unix timestamp when this entity was last updated. - type: integer - format: int64 required: - externalId - id