Skip to content
This repository was archived by the owner on Nov 11, 2025. It is now read-only.
This repository was archived by the owner on Nov 11, 2025. It is now read-only.

Do not apply roles if none is specified to get #9

@hendrul

Description

@hendrul

I need to restrict the visibility of some attributes to some roles, only when sending data to client, but I still need to access this properties from the instance using the readable "instance.attrib" syntax. So reading the documentation I see that with set() if you don't specify any role, by default it apply "self".

var user = sequelize.define('user', {
  ...
  rank: {
     type: Sequelize.STRING,
     roles: {
       self: {set: false, get: true}
       admin: true
     }
  }
}
user.set({rank: 'UBER'}, {role: 'self'||undefined}); // Will be ignored

So I thought the same apply for get(), and with this role definition:

password: {
  roles: {
    self: true,
    client: false
  }
}

I could achieve what I want

//getter with no roles defined defaults to 'self'
user.password //123
//when returning to client:
user.get({role: 'client'}) //password is hidden

In short, I want to be able to only hide attributes when I need it

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions