globaleaks / globaleaks-whistleblowing-software

GlobaLeaks is a free and open-source whistleblowing software enabling anyone to easily set up and maintain a secure reporting platform.
https://www.globaleaks.org
Other
1.23k stars 272 forks source link

Detect and notify users that removal of a resource is not possible because the resource is in use #2188

Open fpietrosanti opened 6 years ago

fpietrosanti commented 6 years ago

Current behavior

Version: 3.0.5

sqlalchemy.exc.IntegrityError Wraps a DB-API IntegrityError.

Traceback (most recent call last):

File "/usr/lib/python2.7/dist-packages/twisted/python/threadpool.py", line 246, in inContext result = inContext.theWork()

File "/usr/lib/python2.7/dist-packages/twisted/python/threadpool.py", line 262, in inContext.theWork = lambda: context.call(ctx, func, *args, **kw)

File "/usr/lib/python2.7/dist-packages/twisted/python/context.py", line 118, in callWithContext return self.currentContext().callWithContext(ctx, func, *args, **kw)

File "/usr/lib/python2.7/dist-packages/twisted/python/context.py", line 81, in callWithContext return func(*args,**kw)

File "/usr/lib/python2.7/dist-packages/globaleaks/orm.py", line 103, in _wrap result = function(session, *args, **kwargs)

File "/usr/lib/python2.7/dist-packages/globaleaks/models/init.py", line 61, in delete return db_delete(session, model, *args, **kwargs)

File "/usr/lib/python2.7/dist-packages/globaleaks/models/init.py", line 56, in db_delete session.query(model).filter(model.id == q.id).delete(synchronize_session='fetch')

File "/usr/lib/python2.7/dist-packages/sqlalchemy/orm/query.py", line 3048, in delete deleteop.exec()

File "/usr/lib/python2.7/dist-packages/sqlalchemy/orm/persistence.py", line 1127, in exec_ self._do_exec()

File "/usr/lib/python2.7/dist-packages/sqlalchemy/orm/persistence.py", line 1311, in _do_exec mapper=self.mapper)

File "/usr/lib/python2.7/dist-packages/sqlalchemy/orm/session.py", line 1046, in execute bind, close_with_result=True).execute(clause, params or {})

File "/usr/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 914, in execute return meth(self, multiparams, params)

File "/usr/lib/python2.7/dist-packages/sqlalchemy/sql/elements.py", line 323, in _execute_on_connection return connection._execute_clauseelement(self, multiparams, params)

File "/usr/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1010, in _execute_clauseelement compiled_sql, distilled_params

File "/usr/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1146, in _execute_context context)

File "/usr/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1341, in _handle_dbapi_exception exc_info

File "/usr/lib/python2.7/dist-packages/sqlalchemy/util/compat.py", line 200, in raise_from_cause reraise(type(exception), exception, tb=exc_tb)

File "/usr/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1139, in _execute_context context)

File "/usr/lib/python2.7/dist-packages/sqlalchemy/engine/default.py", line 450, in do_execute cursor.execute(statement, parameters)

IntegrityError: (sqlite3.IntegrityError) FOREIGN KEY constraint failed [SQL: u'DELETE FROM questionnaire WHERE questionnaire.id = ?'] [parameters: (u'ec4c6780-1b8f-46fb-9613-f017e7fbd218',)]

evilaliv3 commented 6 years ago

Actually this is not a bug but part of the current implementation that protects deletion of questionnaires that are in usage by a context.

As for other deletions we should implement additional checks and errors notifications.

The right generic error message here would be something like: "Cannot delete the resource: resource in use."

evilaliv3 commented 6 years ago

I've reformulated the scope of this ticket in order generically handle the situation on which a user requires to delete a resource and the operation is not possible because the resource is in use.

Proper handling of the deletion of a resource involving multiple nested resources would require to implement detection for any involved object.

To do that a generic ResourceInUseException exception should be created.

The exception could be generated by passing a user message that the interface should show in a specific interface (e.g. a modal).

This is currently known as an issue for: list to be kept updated

Implementation for this feature may benefit of the same exact approaches as for ticket https://github.com/globaleaks/GlobaLeaks/issues/2215