Page MenuHomePhorge

Add method to query if user is member of a list of projects
Open, Needs TriagePublic

Description

In our (rather open) downstream instance we have several places in the codebase in which we use custom code to check if a user is member of at least one project (similar to Trusted Contributors here but we have more than one of these) out of a list of projects, in order to give them more permissions.

I could imagine that in upstream, introducing a is_member_of_any_project(projname1, projname2) method in PhabricatorUser to return a bool could be acceptable? Couldn't find anything existing in the codebase...

If yes, let me try to cook up a patch.

Related Objects

Event Timeline

Maybe express it as allowed by Policy xxx? (Related to T15277)

So essentially this:

https://phabricator.wikimedia.org/source/phab-extensions/browse/wmf%252Fstable/src/policy/WMFSecurityPolicy.php$187

Except factoring out the list of projects into an argument like this:

function isMemberOfAnyProject($projects) {
    if (!$this->isLoggedIn()) {
      return false;
    }

    $trusted_project_names = func_get_args()
    $projects = self::getProjectByName($trusted_project_names, $this, true);
    $pid = $this->getPHID();
    foreach ($projects as $proj) {
      try {
        if ($proj instanceof PhabricatorProject &&
            $proj->isUserMember($phid)) {
          return true;
        }
      } catch(PhabricatorDataNotAttachedException $e) {
        continue;
      }
    }

    return false;
  }

Maybe express it as allowed by Policy xxx? (Related to T15277)

I do like the idea of T15277: Nameable, reusable Policies, that seems like something which wouldn't be difficult to do and would be really useful. It's pretty silly to have 100s (or more) copies of a policy rather than reusing them and I'm not sure why I never fixed that years ago. It was certainly something I considered when I wrote WMFSecurityPolicy.php