2

I am trying to prevent users from being able to irrevocably delete spaces in a Confluence wiki. My first quick thought was to rename the spaces table to allspaces, add a new column deleted, and create a view spaces in place of the old table. The view will only return non-deleted spaces. I have created three rules to allow INSERT, UPDATE, and DELETE on the spaces view. The DELETE rule just changes the deleted field and thus removes it from the view yet all the data stays in the database.

The problem is now DELETE statements on spaces return DELETE 0 from PostgreSQL. This causes Hibernate to flip out and toss an exception and Confluence blows up.

Is there anyway to have PostgreSQL return rows modified instead of rows deleted on an INSTEAD rule.

2
  • Why do your users have direct table access to Confluence tables?! Commented May 17, 2010 at 21:39
  • They don't, Confluence has a button inside "Remove Space" that will delete the space from the database. Currently this is permanent which IMHO is very anti-wiki. I'm attempting to fix this issue at the database level. Commented May 17, 2010 at 22:48

3 Answers 3

1

Not sure how well this would scale (depending on the number of spaces you have to manage), but I would periodically backup the space to XML. This can be done easily through the API using Confluence CLI:

confluence --action exportSpace --space "spaceName" --file "target/output/confluencecli/spaceName.xml"

You could rotate these backups based on age and keep only the most recent ones in the event of a space deletion by a user.

To take this a step further, you could modify the action (confluence/spaces/removespace.vm) that actually deletes the space and insert the logic to backup the space to XML before the removal is confirmed. This would scale much nicer!

Sign up to request clarification or add additional context in comments.

1 Comment

Unfortunately we have several thousand spaces so a scheduled export isn't feasible, but I do like the idea of just hijacking the remove space action.
1

You could add an ON DELETE trigger which saves the deleted row to an archive table. You can add a rescue feature to your application to recover deleted rows.

3 Comments

Yeah that was my first attempt too, although this has the same effect as my rules do except in the opposite direction, a single row delete returns two rows modified and Hibernate throws an exception.
I can't believe Hibernate does not allow to use triggers in the database, there must be an option somewhere !
Yes, Hibernate allows it, but it's a code change. And the whole problem is that this is a closed source product.
0

I'm not really following what you want to achieve, but perhaps you could put the delete statement in a function that returns VOID and then call it it.

CREATE OR REPLACE FUNCTION delete_space(pid integer)
  RETURNS void AS
$BODY$ 
DECLARE aid INTEGER;
BEGIN
    delete from spaces where id=pid;
    return;
END;
$BODY$
  LANGUAGE 'plpgsql';

To use:

select * from delete_space(3);  

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.