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

Support many: true for @keystonejs/fields-authed-relationship #2809

Closed
jesstelford opened this issue Apr 23, 2020 · 1 comment
Closed

Support many: true for @keystonejs/fields-authed-relationship #2809

jesstelford opened this issue Apr 23, 2020 · 1 comment

Comments

@jesstelford
Copy link
Contributor

jesstelford commented Apr 23, 2020

Feature request

Is your feature request related to a problem? Please describe.

I'm currently using @keystonejs/fields-authed-relationship successfully to connect the currently logged in user when creating a new Subscription:

keystone.createList('Subscription', {
  fields: {
    group: { type: Relationship, isRequired: true, ref: 'Group.subscriptions' },
    user: {
      type: AuthedRelationship,
      isRequired: true,
      ref: 'User.subscriptions',
      access: {
        create: accessIsUserSu,
        update: accessIsUserSu,
      },
    },
  },
});

However, I cannot use this when the relationship has a many: true, for example adding the user as an owner of a Group.

Describe the solution you'd like

keystone.createList('Group', {
  fields: {
    subscriptions: { type: Relationship, isRequired: true, ref: 'Subscription.group' },
    owners: {
      type: AuthedRelationship,
      isRequired: true,
      many: true,
      ref: 'User.ownedGroups',
      access: {
        create: accessIsUserSu,
        update: accessIsUserSu,
      },
    },
  },
});

Describe alternatives you've considered

  1. Have the client set the value, then use a resolveInput or maybe validateInput hook to check that it matches the currently logged in user
  2. Create a new list which acts as a many-to-many:
    keystone.createList('GroupOwner', {
      fields: {
        group: { type: Relationship, isRequired: true, ref: 'Group.ownerships' },
        user: {
          type: AuthedRelationship,
          isRequired: true,
          ref: 'User.groupOwnerships',
          access: {
            create: accessIsUserSu,
            update: accessIsUserSu,
          },
        },
      },
    });

Additional context

Why is owners many: true? Because a Group could have more than one owner. Think of them like the "Admins" of a group; there could be one, or there could be many.

When a new group is created, I want the currently logged in user to be automatically assigned as an owner.

@stale
Copy link

stale bot commented Aug 21, 2020

It looks like there hasn't been any activity here in over 6 months. Sorry about that! We've flagged this issue for special attention. It wil be manually reviewed by maintainers, not automatically closed. If you have any additional information please leave us a comment. It really helps! Thank you for you contribution. :)

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