Skip to content

allow function, selector is undefined #432

@KusokDobra12

Description

@KusokDobra12

Hello i used allow function as the autor mentioned to filter the other users out, so they won't sensitive data.

I use like this:

new Tabular.Table({
    name: "Teams",
    collection: Teams,
    allow: function (userId, selector) {
        if (selector.userId !== userId && selector.userId !== +selector.userId) {
            return false; // not allowed to access another user's products
        }
    },
    columns: [
        {data: "team", title: "Team Name"},
        {data: "counter", title: "Players count"},
        {data: "last_played", title: "Last played"}
    ]
});

Then on client i use template called teams with selector defined like this:

Template.teams.helpers({
    selector() {
        return { counter: this.players_num, userId: Meteor.userId() }; 
    }
});
<template name="teams">
<div class="row">
   {{> tabular table=TabularTables.Teams selector=selector id="teams" class="table table-bordered"}}
 </div>
</template>

So i pass counter and userId fol filtering, but when i break point on allow i can see that second paramter selector is undefined, please help, how to properly pass this ? Or i misunderstood this? Basically i need to pass a filter by players + security so only current user can see his team.

Also another question, can i use allow to filter additional fields? Like for example i want to get from collection using team id, this team id is tored in Meteor.user.profile, so can i do something like this?

    allow: function (userId, selector) {
        if (selector.team_id !== Meteor.user().profile.team_id) {
            return false; // not allowed to access another user's products
        }
    }

Can i filter like that?

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