loopback icon indicating copy to clipboard operation
loopback copied to clipboard

Read only properties

Open ritch opened this issue 12 years ago • 55 comments

I've heard this requested a couple of times now. Creating an issue so people can discuss details. I'd like to have something like:

{"readOnly": {"propertyName": true}}

We could also make this a setting on the property itself... The version above allows us to implement it outside the scope of properties...

ritch avatar Sep 03 '14 19:09 ritch

would be a very handy feature. Maybe in combination with dynamic, calculated properties

arjan123 avatar Feb 17 '15 15:02 arjan123

Also very interested in this. My use case is to lock down properties that are used to define relationships so that the relationships can't be changed. For example, an address belongs to a person and is related to it through a personId property. I don't want to allow the address to be assigned to a different user by simply changing the personId value.

mrfelton avatar Apr 01 '15 09:04 mrfelton

+1

violet-day avatar Apr 01 '15 13:04 violet-day

I've implemented this as a mixin, available at https://www.npmjs.com/package/loopback-ds-readonly-mixin

mrfelton avatar May 10 '15 12:05 mrfelton

Yes, this seems like a huge security issue. I feel like I'm missing something that this can't be done out of the box.

Many thanks @mrfelton. Your mixin works great for now!

snapjay avatar May 30 '15 12:05 snapjay

+1

bebop23 avatar Jul 18 '15 01:07 bebop23

If the acting user has write privileges on a given entity, I don't see why wouldn't he be able to update its properties.

If the underlaying database engine had a FK on the field, then the only restricción would be to point to a valid master id. I don't agree on adding model behavior that doesn't map to a native behavior on the database engine. It breaks separation of concerns and introduces an unnecesary coupling between app and db.

Since this restricción doesn't belong to the model itself, it can only exist as a middleware or as a custom rule among the business logic, which in this case would be a remote hook.

ffflabs avatar Jul 18 '15 02:07 ffflabs

I would very much like this.

In our usecase, all model instances are associated with a Team, and on the basis of this association we derive both access rights as well as relations. This team association is set once when the instance is created, and by spec must never change after that (not even the user who owns the instance is able to change it). The association needs to be exposed via REST, however, since we use it on the client-side to query related data.

Currently we are solving this using mixins, but this almost certainly is a clumsy solution and it would be much more convenient to simply be able to mark the property as immutable.

csvan avatar Sep 10 '15 06:09 csvan

+1 Would also like to see a readOnly property. My use case is that we store a number of followers as a property to avoid having to compute it each time from a hasAndBelongsToMany relation wich can be intensive. But we don't want the user to be able to change the followersCount himself.

dotlouis avatar Nov 03 '15 15:11 dotlouis

@amenadiel an user would be able to abuse its own profile :)

barocsi avatar Nov 04 '15 14:11 barocsi

When created_ator updated_at are required and set at the db level by the PostgreSQL server (before_update trigger), you may want to expose the value to your users/admins but you do not want to be required to provide these values for an insert or an update. This is a pretty common use case.

It would make sense to be able to flag these 2 fields as 'readOnly'.

xapou avatar Nov 14 '15 00:11 xapou

+1 A readOnly property would be very useful for ids.

seanmangar avatar Dec 15 '15 09:12 seanmangar

+1 !

mishagray avatar Dec 30 '15 23:12 mishagray

+1

JensWinter avatar Jan 01 '16 11:01 JensWinter

+1

sisardor avatar Jan 19 '16 21:01 sisardor

+1

AnthonyYashchuk avatar Jan 26 '16 00:01 AnthonyYashchuk

Whell, you can undefine some fields in model.__data.

ffflabs avatar Jan 29 '16 04:01 ffflabs

+1

3l3n01 avatar Feb 29 '16 13:02 3l3n01

+1

WardBeullens avatar Mar 01 '16 18:03 WardBeullens

I want to make the security more explicit and define which properties are writable. So I'd like a whitelist of writable fields instead of a blacklist of readonly fields.

Would anybody mind (maybe @mrfelton ) or find it helpful if I fork https://github.com/fullcube/loopback-ds-readonly-mixin and invert it to https://github.com/devotis/loopback-ds-writable-mixin ?

christiaanwesterbeek avatar Mar 12 '16 22:03 christiaanwesterbeek