Access articles from a table if user belongs to qualified group
So, as I understand, the input to the query is:


a group name;
a user name.


And the output should be the list of all the articles belonging to the given group provided either of the following is true:


the group is open;
the given user belongs to the group.


If that is correct, I believe the missing condition could be implemented as an EXISTS predicate:

...
    OR EXISTS
    (
      SELECT
        *
      FROM
        myuser AS u
        INNER JOIN membership AS m ON u.id = m.myuser_id
      WHERE
        m.mygroup_id = g.id
        AND u.name = 'BAZ-ID'
    )
...


The join to membership in the main SELECT would then be redundant.

Alternatively, you could outer-join the result of membership INNER JOIN myuser and check for presence of a match in the WHERE clause, like this:

SELECT
  * 
FROM
  article AS a
  INNER JOIN mygroup AS g ON g.id = a.mygroup_id
  LEFT JOIN
    membership AS m
    INNER JOIN myuser AS u ON m.myuser_id = u.id
  ON m.mygroup_id = g.id AND u.name = 'BAZ-ID'
WHERE 
  (g.name = 'FOO-BAR') 
  AND
  (
    (g.open IS TRUE) 
    OR
    (u.id IS NOT NULL)
  )
;

An EXISTS predicate is often faster than an equivalent join, though, so you might prefer the former option, but test in your environment to see which is actually better.

If the user is specified by ID instead of a name, the query becomes simpler in each case. The EXISTS predicate would look like this:

EXISTS
(
  SELECT
    *
  FROM
    membership AS m
  WHERE
    m.mygroup_id = g.id
    AND m.myuser_id = &lt;input-user-ID&gt;
)


For the second option, using an ID instead of a name to specify the user would mean a simpler left join:

LEFT JOIN membership AS m
  ON  m.mygroup_id = g.id
  AND m.myuser_id = &lt;input-user-ID&gt;


And, of course, you would need to replace the u.id reference in the WHERE clause with a reference to a non-nullable membership column. The m.id would do, so:

WHERE 
  (g.name = 'FOO-BAR') 
  AND
  (
    (g.open IS TRUE) 
    OR
    (m.id IS NOT NULL)
  )