Skip to content

Invite a none elgg member by email in a subgroup should generate an error message #20

@oseg

Description

@oseg

Group_tools plugin allows a group owner to invite new members in a group through their email addresses (directly or through a csv file) which is a very useful feature if you want to invite people which are not yet members of your elgg site.

However, you cannot invite external users into a subgroup: obviously these external users are not members of the parent group. In this case, the plugin should display an error message.

Suggested fix in lib/hooks.php

function group_invite($hook, $type, $return, $params) {
	$user_guid = get_input('user_guid');
	$group_guid = get_input('group_guid');
	$group = get_entity($group_guid);

	$parent = get_parent_group($group);

	// if $parent, then this is a subgroup they're being invited to
	// make sure they're a member of the parent
	if ($parent) {
		if (!is_array($user_guid)) {
			$user_guid = array($user_guid);
		}

		$invalid_users = array();
                $unknown_users = false;
		foreach ($user_guid as $guid) {
			$user = get_user($guid);
                        if (!$user) {
                            $unknown_users = true;
                        } else if (!$parent->isMember($user)) {
                                $invalid_users[] = $user;                                                                    
                                }
                            }

                if ($unknown_users) {
			register_error(elgg_echo('au_subgroups:error:invite_noelggmember'));
			return false;
                } else if (count($invalid_users)) {
			$error_suffix = "<ul>";
			foreach ($invalid_users as $user) {
				$error_suffix .= "<li>{$user->name}</li>";
			}
			$error_suffix .= "</ul>";

			register_error(elgg_echo('au_subgroups:error:invite') . $error_suffix);
			return false;
		}
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions