From 909ffb3e7a433403f3c699a345859020f3079ae7 Mon Sep 17 00:00:00 2001 From: Mark Carroll Date: Tue, 22 Oct 2013 10:20:04 +0100 Subject: [PATCH] prevent changing originalfile.mimetype from 'Directory' --- components/dsl/resources/ome/dsl/psql-footer.vm | 16 ++++++++++++++-- sql/psql/OMERO5.0DEV__6/psql-footer.sql | 16 ++++++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/components/dsl/resources/ome/dsl/psql-footer.vm b/components/dsl/resources/ome/dsl/psql-footer.vm index 6f3cc1f0717..3461d2a07b9 100644 --- a/components/dsl/resources/ome/dsl/psql-footer.vm +++ b/components/dsl/resources/ome/dsl/psql-footer.vm @@ -496,8 +496,6 @@ insert into password values (1,''); -- -- Prevent the deletion of mimetype = "Directory" objects --- TODO: also evaluate preventing the change of mimetype --- for Directory objects. create or replace function _fs_dir_delete() returns trigger AS $_fs_dir_delete$ begin if OLD.repo is not null then @@ -523,6 +521,20 @@ create trigger _fs_dir_delete before delete on originalfile for each row execute procedure _fs_dir_delete(); +-- Prevent Directory entries in the originalfile table from having their mimetype changed. +CREATE OR REPLACE FUNCTION _fs_directory_mimetype() RETURNS "trigger" AS $$ + BEGIN + IF OLD.mimetype = 'Directory' AND NEW.mimetype != 'Directory' THEN + RAISE EXCEPTION '%%', 'Directory('||OLD.id||')='||OLD.path||OLD.name||'/ must remain a Directory'; + END IF; + RETURN NEW; + END; +$$ LANGUAGE plpgsql; + +CREATE TRIGGER _fs_directory_mimetype + BEFORE UPDATE ON originalfile + FOR EACH ROW EXECUTE PROCEDURE _fs_directory_mimetype(); + create table _fs_deletelog ( event_id bigint not null, file_id bigint not null, diff --git a/sql/psql/OMERO5.0DEV__6/psql-footer.sql b/sql/psql/OMERO5.0DEV__6/psql-footer.sql index cfc9e8101ef..f17b749258d 100644 --- a/sql/psql/OMERO5.0DEV__6/psql-footer.sql +++ b/sql/psql/OMERO5.0DEV__6/psql-footer.sql @@ -2089,8 +2089,6 @@ insert into password values (1,''); -- -- Prevent the deletion of mimetype = "Directory" objects --- TODO: also evaluate preventing the change of mimetype --- for Directory objects. create or replace function _fs_dir_delete() returns trigger AS $_fs_dir_delete$ begin if OLD.repo is not null then @@ -2116,6 +2114,20 @@ create trigger _fs_dir_delete before delete on originalfile for each row execute procedure _fs_dir_delete(); +-- Prevent Directory entries in the originalfile table from having their mimetype changed. +CREATE OR REPLACE FUNCTION _fs_directory_mimetype() RETURNS "trigger" AS $$ + BEGIN + IF OLD.mimetype = 'Directory' AND NEW.mimetype != 'Directory' THEN + RAISE EXCEPTION '%%', 'Directory('||OLD.id||')='||OLD.path||OLD.name||'/ must remain a Directory'; + END IF; + RETURN NEW; + END; +$$ LANGUAGE plpgsql; + +CREATE TRIGGER _fs_directory_mimetype + BEFORE UPDATE ON originalfile + FOR EACH ROW EXECUTE PROCEDURE _fs_directory_mimetype(); + create table _fs_deletelog ( event_id bigint not null, file_id bigint not null,