Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Populate Owner breaks owner Permission #210

Open
dottodot opened this issue Jan 21, 2016 · 2 comments
Open

Populate Owner breaks owner Permission #210

dottodot opened this issue Jan 21, 2016 · 2 comments

Comments

@dottodot
Copy link

I've set up a permission for the registered role on a model with the relation set to owner,and the models have the owner attribute set but when a registered user requests some models they own the response is empty when pass through res.ok() even though models are found.

find: function(req, res) {
    var page = req.param('page') || 1;
    var limit = req.param('limit') || 10000000;
    var defaultStatus = ['Pending', 'Can Cut Out', 'Already Cut Out', 'In Production', 'Design Sent', 'Production Picture Sent', 'Can Finish', 'Finished', 'Final Check', 'Shipped', 'Refunded'];
    var status = req.param('status') || defaultStatus;
    var owner = req.param('owner');
    var query = {
      status: status
    };
    if (owner) query.owner = owner;
    Order.count(query).then(function(count) {
      this.count = count;
      return Order.find(query).paginate({
        page: page,
        limit: limit
      }).populate('items').populate('owner').sort('createdAt DESC');
    }).then(function(orders) {
      console.log(orders);
      res.set('Access-Control-Expose-Headers', 'X-Total-Count');
      res.set('X-Total-Count', this.count);
      res.ok(orders);
    });
  }

This is using v1.4.5

@dottodot dottodot changed the title Owner can't get own Populate Owner breaks owner Permission Jan 22, 2016
@dottodot
Copy link
Author

OK I've found the problem. If you populate owner the CriteriaPolicy doesn't like it as the filter can't handle that it populated.

  var permitted = data.reduce(function(memo, item) {
    criteria.some(function(crit) {
      var filtered = wlFilter([item], {
        where: {
          or: [crit.where]
        }
      }).results;
      if (filtered.length) {

        if (crit.blacklist && crit.blacklist.length) {
          crit.blacklist.forEach(function(term) {
            delete item[term];
          });
        }
        memo.push(item);
        return true;
      }
    });
    return memo;
  }, []);

So how do I Populate Owner and have it respect the permissions.

@Eligible9653
Copy link

Having a similar issue here: sails waterline doesn't sem to be able to "deep search" for an ID. It only checks if the value equals the criteria.

This works!

var wlFilter = require('waterline-criteria');
var ok = wlFilter([{group: [3]}], {where: {or: [{group: 3}]}});

console.log(JSON.stringify(ok.results));

//logs to => [{"group":[3]}]

This doesn't work!

var wlFilter = require('waterline-criteria');
var ok = wlFilter([{group: [3]}], {where: {or: [{group: {id: 3}}]}});

console.log(JSON.stringify(ok.results));

//logs to => []

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants