ILIAS icon indicating copy to clipboard operation
ILIAS copied to clipboard

bugfix #39505: TypeError in SelfRegistration with reg-code & local roles

Open utesche opened this issue 1 year ago • 4 comments

The PR fixes 3 TypeErrors for issue: https://mantis.ilias.de/view.php?id=39505 forum: https://docu.ilias.de/goto_docu_frm_1875_8811.html .

utesche avatar Jan 29 '24 15:01 utesche

Thx for the PR @utesche . I suggest to cast the values in the variable assingment.

Instead of:

        $code_local_roles = [];

AND

                $code_data = ilRegistrationCode::getCodeData($code);
                if ($code_data["role_local"]) {
                    // need user id before we can assign role(s)
                    $code_local_roles = explode(";", $code_data["role_local"]);
                }

Should: All values of the $code_local_roles list should be of type int.

        /** @var list<int>|null $code_local_roles */
        $code_local_roles = [];

AND

                $code_data = ilRegistrationCode::getCodeData($code);
                if (isset($code_data['role_local']) && is_string($code_data['role_local'])) {
                    // need user id before we can assign role(s)
                    $code_local_roles = array_filter(array_map(
                        static fn (string $value): int => (int) $value,
                        explode(';', $code_data['role_local'])
                    ));
                }

Whenever $code_local_roles is used, the consuming code can expect all values to be of type int.


Of course, it is still not nice that consumers (like class.ilAccountRegistrationGUI.php) have to know internals (separator) of $code_data['role_local']. But that should not be part of this PR, this requires some deep refactorings.

Best regards, Michael

mjansenDatabay avatar Jan 30 '24 09:01 mjansenDatabay

@utesche Do have time/energy and want to include the review remarks into your PR?

mjansenDatabay avatar Mar 01 '24 07:03 mjansenDatabay

@mjansenDatabay, as suggested, the strict casting to int of separate local_role_ids at usage time is changed now to a conversion of the whole array of ids to int when creating the array (by exploding the given input).

utesche avatar Mar 04 '24 22:03 utesche

@pascalseeland Please check my suggested change and merge the PR afterwards, if you don't have any further objections.

mjansenDatabay avatar Mar 05 '24 07:03 mjansenDatabay