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

Congregation delete fails if any user has a congregation restriction #663

Closed
jefft opened this issue Aug 14, 2020 · 2 comments
Closed

Congregation delete fails if any user has a congregation restriction #663

jefft opened this issue Aug 14, 2020 · 2 comments

Comments

@jefft
Copy link
Contributor

jefft commented Aug 14, 2020

A small bug we've hit in 2.28.1: a congregation cannot be deleted if any user is restricted to it.

To replicate:

  1. Go to Admin -> Congregations and add a new congregation:

image

  1. Under Admin -> User Accounts, pick any user and Edit. In the 'Restrictions' section tick the newly created congregation:

image

  1. Back in Admin -> Congregations, click 'Delete' on the new congregation.
    image

The user now sees " An error occurred. Please contact your system administrator for help. " and a stacktrace is generated:

SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (`jethro`.`account_congregation_restriction`, CONSTRAINT `account_group_restriction_congregationid` FOREIGN KEY (`congregationid`) REFERENCES `congregation` (`id`))
Line 440 of /srv/www/coastec.net.au/jethro/2.28.1/include/db_object.class.php

USER:       536
REFERER:    https://jethro.coastec.net.au/?view=admin__congregations
USER_AGENT: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:79.0) Gecko/20100101 Firefox/79.0

REQUEST:
Array
(
    [view] => admin__congregations
    [action] => delete
    [congregationid] => 16
)


BACKTRACE:
Array
(
    [0] => Array
        (
            [file] => /srv/www/coastec.net.au/jethro/2.28.1/include/db_object.class.php
            [line] => 440
            [function] => query
            [class] => PDO
            [type] => ->
            [args] => Array
                (
                    [0] => DELETE FROM congregation WHERE id='16'
                )

        )

    [1] => Array
        (
            [file] => /srv/www/coastec.net.au/jethro/2.28.1/views/view_10_admin__1_congregations.class.php
            [line] => 23
            [function] => delete
            [class] => db_object
            [type] => ->
            [args] => Array
                (
                )

        )

    [2] => Array
        (
            [file] => /srv/www/coastec.net.au/jethro/2.28.1/include/system_controller.class.php
            [line] => 130
            [function] => processView
            [class] => View_Admin__Congregations
            [type] => ->
            [args] => Array
                (
                )

        )

    [3] => Array
        (
            [file] => /srv/www/coastec.net.au/jethro/2.28.1/index.php
            [line] => 58
            [function] => run
            [class] => System_Controller
            [type] => ->
            [args] => Array
                (
                )

        )

)
@jefft
Copy link
Contributor Author

jefft commented Aug 14, 2020

The workaround is to note the ID of the congregation you're trying to delete, as shown in the stacktrace:

                    [0] => DELETE FROM congregation WHERE id='16'

and manually delete the restrictions:

MariaDB [jethro]> delete from account_congregation_restriction where congregationid=16;
Query OK, 1 rows affected (0.01 sec)

@tbar0970
Copy link
Owner

Thanks for the report.
Jethro needs to handle this scenario more gracefully.
But cascade-deleting the account restrictions wouldn't be the way to go. An account with no congregation restrictions remaining has access to every congregation - which would not have been the original intention!
Jethro should instead block the delete and explain why. The user can then adjust account restrictions as necessary before deleting the congregation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants