Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent changing originalfile.mimetype from 'Directory' #1645

Merged
merged 1 commit into from
Oct 28, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 14 additions & 2 deletions components/dsl/resources/ome/dsl/psql-footer.vm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
16 changes: 14 additions & 2 deletions sql/psql/OMERO5.0DEV__6/psql-footer.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down