From e9a8f467f1d805348df66c6a4bee1d145fdd85db Mon Sep 17 00:00:00 2001 From: OpenGnSys Support Team Date: Wed, 17 Jul 2024 14:19:39 +0200 Subject: rest: add GET,POST /image/restrict Allow to restrict image to scope: POST /image/restrict { "image" : 49, "scopes" : [ 1,3 ] } response: 200 OK This restricts image with ID 49 to scopes 1 and 3. You can also fetch the current list of restrictions: GET /image/restrict { "image" : 49 } response: 200 OK { "image" : 49, "scopes" : [ 1,3 ] } Existing limitations in this interface: - Only restriction of image to center is possible at this moment. - This is only used by ogCP to validate if this is possible, no existing code in the ogserver uses this to restrict POST image/restore. This is a usability feature. --- src/schema.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'src/schema.c') diff --git a/src/schema.c b/src/schema.c index 002fd56..7390e27 100644 --- a/src/schema.c +++ b/src/schema.c @@ -335,6 +335,40 @@ static int og_dbi_schema_v7(struct og_dbi *dbi) return 0; } +static int og_dbi_schema_v8(struct og_dbi *dbi) +{ + const char *msglog; + dbi_result result; + + syslog(LOG_DEBUG, "Creating table image_scope\n"); + result = dbi_conn_query(dbi->conn, "CREATE TABLE `image_scope` (" + "`id` int NOT NULL AUTO_INCREMENT," + "`image_id` int NOT NULL," + "`scope_id` int NOT NULL," + "PRIMARY KEY (`id`)," + "FOREIGN KEY (`image_id`) REFERENCES `imagenes` (`idimagen`) ON DELETE CASCADE," + "FOREIGN KEY (`scope_id`) REFERENCES `centros` (`idcentro`) ON DELETE CASCADE" + ") AUTO_INCREMENT=1;"); + if (!result) { + dbi_conn_error(dbi->conn, &msglog); + syslog(LOG_INFO, "Error when creating image_scope (%s:%d) %s\n", + __func__, __LINE__, msglog); + return -1; + } + dbi_result_free(result); + + result = dbi_conn_query(dbi->conn, "UPDATE version SET version = 8"); + if (!result) { + dbi_conn_error(dbi->conn, &msglog); + syslog(LOG_INFO, "Could not update version row (%s:%d) %s\n", + __func__, __LINE__, msglog); + return -1; + } + dbi_result_free(result); + + return 0; +} + static struct og_schema_version { int version; int (*update)(struct og_dbi *dbi); @@ -346,6 +380,7 @@ static struct og_schema_version { { .version = 5, .update = og_dbi_schema_v5 }, { .version = 6, .update = og_dbi_schema_v6 }, { .version = 7, .update = og_dbi_schema_v7, }, + { .version = 8, .update = og_dbi_schema_v8, }, { 0, NULL }, }; -- cgit v1.2.3-18-g5258