summaryrefslogtreecommitdiffstats
path: root/src/schema.c
diff options
context:
space:
mode:
authorOpenGnSys Support Team <soporte-og@soleta.eu>2024-07-17 14:19:39 +0200
committerOpenGnSys Support Team <soporte-og@soleta.eu>2024-07-17 17:15:27 +0200
commite9a8f467f1d805348df66c6a4bee1d145fdd85db (patch)
tree215b505fb5ad060eceb2524ccda25c262d38373a /src/schema.c
parente62a55ae37bfdb2aba86696dde5bc27555dd5cf8 (diff)
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.
Diffstat (limited to 'src/schema.c')
-rw-r--r--src/schema.c35
1 files changed, 35 insertions, 0 deletions
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 },
};