anchor.diff:      end.
   
   handle_get_users_with_domain(Req, DomainAtom, Path) ->
  +    RawPermission = proplists:get_value("permission", Req:parse_qs()),
  +    case maybe_parse_permission(RawPermission) of
  +        error ->
  +            menelaus_util:reply_json(Req, <<"Malformed permission.">>, 400);
  +        Permission ->
  +            handle_get_users_with_domain(Req, DomainAtom, Path, Permission)
  +    end.
  +
  +handle_get_users_with_domain(Req, DomainAtom, Path, Permission) ->
       Query = Req:parse_qs(),
  -
  +    FilteredRoles =
  +        case Permission of
  +            undefined -> all;
  +            _ -> get_roles_by_permission(Permission)
  +        end,
       case lists:keyfind("pageSize", 1, Query) of
           false ->
  -            handle_get_all_users(Req, {'_', DomainAtom});
  +            handle_get_all_users(Req, {'_', DomainAtom}, FilteredRoles);
           _ ->
               HasStartFrom = lists:keyfind("startFrom", 1, Query) =/= false,
               menelaus_util:execute_if_validated(
  
positive.code:                     menelaus_util:reply_json(Req, get_user_json(Identity))
              end
      end.
  
  filter_out_invalid_roles() ->
      Definitions = menelaus_roles:get_definitions(),
  
negative.code:              end, Users),
      menelaus_util:reply_json(Req, Json).
  
  handle_get_all_users(Req, Pattern, Roles) ->
      Passwordless = menelaus_users:get_passwordless(),
      pipes:run(menelaus_users:select_users(Pattern),
                [filter_out_invalid_roles(),
                 filter_by_roles(Roles),
                 jsonify_users(Passwordless),
                 sjson:encode_extended_json([{compact, false},
                                             {strict, false}]),
  