Skip to content

Commit

Permalink
AC#1102/custom annotations (#291)
Browse files Browse the repository at this point in the history
* feat: create annotation table with default annotations

* feat: add system annotation get endpoint

* chore: add test for system annotation get endpoint

* feat: add endpoint + test for single annotation config

* fix: permissions for annotation configs

* refactor: rename AnnotationModel -> CellAnnotationConfigModel

* feat add delete endpoint for annotation config + test

* feat: add update endpoint for annotation config + test

* feat: add create endpoint for annotation config + tests

* fix: linter errors

* Update src/main/resources/schema/schema_v38.sql

Co-authored-by: Zingl Manfred <mz@campudus.com>

* chore: remove todos for messaging client

* fix: use db to set priority if missing in payload

* fix: set correct priority

* fix: codacy problem

* chore: add tests for empty/missing payload on create and update

* feat: only allow removal of custom annotation configs

* fix: spotless errors

* feat: add column `annotation_name` in `user_table_annotations` with migration

* Update src/main/resources/schema/schema_v38.sql

Co-authored-by: Zingl Manfred <mz@campudus.com>

* Update src/main/resources/schema/schema_v38.sql

Co-authored-by: Zingl Manfred <mz@campudus.com>

* fix: pr fixes

---------

Co-authored-by: Zingl Manfred <mz@campudus.com>
  • Loading branch information
smnhgn and zingmane authored Feb 4, 2025
1 parent 27e37cd commit 94de019
Show file tree
Hide file tree
Showing 18 changed files with 1,207 additions and 35 deletions.
6 changes: 5 additions & 1 deletion role-permissions-example.json
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,11 @@
"editServiceDisplayProperty",
"createMedia",
"editMedia",
"deleteMedia"
"deleteMedia",
"createCellAnnotationConfig",
"viewCellAnnotationConfig",
"deleteCellAnnotationConfig",
"editCellAnnotationConfig"
]
}
]
Expand Down
11 changes: 10 additions & 1 deletion role-permissions-test.json
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,15 @@
"editServiceStructureProperty",
"editServiceDisplayProperty"
]
},
{
"type": "grant",
"action": [
"createCellAnnotationConfig",
"viewCellAnnotationConfig",
"deleteCellAnnotationConfig",
"editCellAnnotationConfig"
]
}
]
}
}
36 changes: 36 additions & 0 deletions src/main/resources/schema/schema_v38.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
CREATE TABLE system_annotations (
name VARCHAR(50) NOT NULL,
priority SERIAL,
fg_color VARCHAR(50) NULL,
bg_color VARCHAR(50) NULL,
display_name JSON,
is_multilang BOOLEAN NOT NULL DEFAULT FALSE,
is_dashboard BOOLEAN NOT NULL DEFAULT TRUE,
is_custom BOOLEAN NOT NULL DEFAULT TRUE,

PRIMARY KEY (name)
);

INSERT INTO system_annotations
(name, priority, fg_color, bg_color, display_name, is_multilang, is_dashboard, is_custom)
VALUES
('important', 1, '#ffffff', '#ff7474', '{"de":"Wichtig","en":"Important"}', FALSE, TRUE, TRUE),
('check-me', 2, '#ffffff', '#c274ff', '{"de":"Bitte überprüfen","en":"Please double-check"}', FALSE, TRUE, TRUE),
('postpone', 3, '#ffffff', '#999999', '{"de":"Später","en":"Later"}', FALSE, TRUE, TRUE),
('needs_translation', 4, '#ffffff', '#ffae74', '{"de":"Übersetzung nötig","en":"Translation necessary"}', TRUE, TRUE, FALSE);

CREATE OR REPLACE FUNCTION add_annotation_name_column(tableid BIGINT)
RETURNS TEXT AS $$
BEGIN
EXECUTE 'ALTER TABLE user_table_annotations_' || tableid || ' ADD COLUMN annotation_name TEXT NULL';
EXECUTE 'ALTER TABLE user_table_annotations_' || tableid || ' ADD FOREIGN KEY (annotation_name) REFERENCES system_annotations (name) ON DELETE CASCADE ON UPDATE CASCADE';
EXECUTE 'UPDATE user_table_annotations_' || tableid || ' SET annotation_name = value WHERE type = ''flag''';
EXECUTE 'UPDATE user_table_annotations_' || tableid || ' SET value = NULL WHERE type = ''flag''';
RETURN 'user_table_annotations_' || tableid :: TEXT;
END
$$ LANGUAGE plpgsql;

SELECT add_annotation_name_column(table_id)
FROM system_table;

DROP FUNCTION add_annotation_name_column( BIGINT );
266 changes: 266 additions & 0 deletions src/main/resources/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,138 @@
}
}
},
"/system/annotations": {
"get": {
"summary": "Get all annotation configs",
"description": "Returns an array containing all available annotation configs.",
"tags": [
"system"
],
"operationId": "get-all-annotation-configs",
"consumes": [],
"produces": [
"application/json"
],
"parameters": [],
"responses": {
"200": {
"description": "The annotations",
"schema": {
"$ref": "#/definitions/Response: Annotation Configs"
}
},
"default": {
"description": "Unexpected error",
"schema": {
"$ref": "#/responses/unknown-error"
}
}
}
},
"post": {
"summary": "Create a new annotation config",
"description": "Creates the annotation config.",
"tags": [
"system"
],
"operationId": "create-new-annotation-config",
"parameters": [
{
"name": "annotation config",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/Request: Create annotation config"
}
}
],
"responses": {
"200": {
"description": "The new annotation config",
"schema": {
"$ref": "#/definitions/CellAnnotationConfig"
}
},
"default": {
"description": "Unexpected error",
"schema": {
"$ref": "#/responses/unknown-error"
}
}
}
}
},
"/system/annotations/{annotationName}": {
"parameters": [
{
"$ref": "#/parameters/annotationName"
}
],
"get": {
"summary": "Get annotation config",
"description": "Returns the config of an annotation.",
"tags": [
"system"
],
"operationId": "get-annotation-config",
"responses": {
"200": {
"description": "Config of the annotation",
"schema": {
"$ref": "#/definitions/CellAnnotationConfig"
}
},
"404": {
"$ref": "#/responses/not-found-in-database"
}
}
},
"patch": {
"summary": "Update annotation config",
"description": "Updates an annotation config.",
"tags": [
"system"
],
"operationId": "update-annotation-config",
"parameters": [
{
"name": "annotation config",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/CellAnnotationConfig"
}
}
],
"responses": {
"200": {
"description": "Config of the annotation",
"schema": {
"$ref": "#/definitions/CellAnnotationConfig"
}
},
"404": {
"$ref": "#/responses/not-found-in-database"
}
}
},
"delete": {
"summary": "Delete an annotation config",
"description": "Deletes the config of an annotation.",
"tags": [
"system"
],
"operationId": "delete-annotation-config",
"responses": {
"200": {
"$ref": "#/responses/ok-empty-body"
},
"404": {
"$ref": "#/responses/not-found-in-database"
}
}
}
},
"/system/update": {
"post": {
"summary": "Update system tables",
Expand Down Expand Up @@ -2219,6 +2351,63 @@
}
}
},
"CellAnnotationConfig": {
"type": "object",
"required": [
"name",
"priority",
"fgColor",
"bgColor",
"displayName",
"isMultilang",
"isDashboard"
],
"properties": {
"name": {
"description": "name of the annotation",
"type": "string",
"example": "important"
},
"priority": {
"description": "priority of the annotation",
"type": "number",
"example": 1
},
"fgColor": {
"description": "foreground color of the annotation",
"type": "string",
"example": "#ffffff"
},
"bgColor": {
"description": "background color of the annotation",
"type": "string",
"example": "#ff7474"
},
"displayName": {
"description": "display name of the annotation as multilang obj",
"type": "object",
"example": {
"de": "Wichtig",
"en": "Important"
}
},
"isMultilang": {
"description": "multilang flag for the annotation",
"type": "boolean",
"example": false
},
"isDashboard": {
"description": "dashboard flag for the annotation",
"type": "boolean",
"example": true
},
"isCustom": {
"description": "custom flag for the annotation",
"type": "boolean",
"example": true
}
}
},
"Pagination": {
"type": "object",
"required": [
Expand Down Expand Up @@ -2475,6 +2664,25 @@
"services"
]
},
"Response: Annotation Configs": {
"type": "object",
"allOf": [
{
"$ref": "#/definitions/Property:Status"
}
],
"properties": {
"annotations": {
"type": "array",
"items": {
"$ref": "#/definitions/CellAnnotationConfig"
}
}
},
"required": [
"annotations"
]
},
"Response:Cell": {
"description": "The cell value.",
"type": "object",
Expand Down Expand Up @@ -3091,6 +3299,56 @@
}
}
},
"Request: Create annotation config": {
"type": "object",
"required": [
"name",
"fgColor",
"bgColor",
"displayName"
],
"properties": {
"name": {
"description": "name of the annotation",
"type": "string",
"example": "important"
},
"priority": {
"description": "priority of the annotation",
"type": "number",
"example": 1
},
"fgColor": {
"description": "foreground color of the annotation",
"type": "string",
"example": "#ffffff"
},
"bgColor": {
"description": "background color of the annotation",
"type": "string",
"example": "#ff7474"
},
"displayName": {
"description": "display name of the annotation as multilang obj",
"type": "object",
"example": {
"de": "Wichtig",
"en": "Important"
}
},
"isMultilang": {
"description": "multilang flag for the annotation",
"type": "boolean",
"example": false
},
"isDashboard": {
"description": "dashboard flag for the annotation",
"type": "boolean",
"example": true
}
},
"description": "Creates a new annotation config."
},
"Response: Complete table": {
"type": "object",
"required": [
Expand Down Expand Up @@ -4206,6 +4464,14 @@
"in": "query",
"type": "boolean",
"required": false
},
"annotationName": {
"name": "annotationName",
"description": "The name of the annotation",
"in": "path",
"required": true,
"type": "string",
"example": "postpone"
}
},
"responses": {
Expand Down
Loading

0 comments on commit 94de019

Please sign in to comment.