fabbricadigitale / scimd

SCIM v2 golang implementation
MIT License
5 stars 1 forks source link

About $ref attribute and relations between resources #75

Open alelb opened 6 years ago

alelb commented 6 years ago

Referring to the specific case of the Users-Groups relationship, I would like to focus on the relationship between resources in general.

The User resource has a "groups" attribute that represents a list of all the groups to which the user belongs. Note that this is an attribute with mutability readOnly. The possibility of adding a relationship is left to the Gruop resource which has a list of "members" with a mutability readWrite.

Currently, the part of logic that for a new group member, adding this information to the corresponding User resource is missing.

I'm thinking about two solutions:

  1. the information is stored in the user resource, so in the Create Group something must be activated so the corresponding User resource is changed.

  2. the membership information is kept only in the Group resource and every time the user resource is requested the relationship in the Group resource is searched.

I think the latter is the most suitable in a mongodb context.

Please @leodido @leogr tell me what you think.

leogr commented 6 years ago

The readOnly mutability for users indicates that RCF is assuming that the membership information belongs to Group, but RFC does not mandate how to implement that. However, this implies some scalability issues (how could we return a Group's JSON representation that has millions of users?).

Furthermore, do not forget "redundancy". We're using a non-relation DB so both ways could co-exist.

alelb commented 6 years ago

@leogr My idea is to use listener to assign a group to the user (or an organization to a department, etc) and, in general, to assign a reference to a resource with a specific readOnly attribute when you're creating (or updating, or deleting) a resource with the referenced readWrite attribute (the members in Group).

leodido commented 6 years ago

Sorry @alelb remind me. When you are talking about listeners you are referring to hooks, right?

alelb commented 6 years ago

@leodido Yes, I am referring to hooks.

leogr commented 6 years ago

Assuming hooks are used in order to sync the $ref within the User's document and membership will be stored within the Group's document, isn't it? If so, Group's document could grow indefinitely, that's a scalability issue. However, temporarily we may go on this way, but we shall fix it later. What do you think about that?

alelb commented 6 years ago

@leogr you are right. Notice that both in the User's groups attribute and in the Group's members attribute the $ref attribute is and remains an identifier. There is no incapsulation of one document into another.