question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Admin UI]OneToMany field relate didn't work when login in AdminUI

See original GitHub issue

Bug report

Describe the bug

For example: User List:

keystone.createList('User', {
  label: 'User',
  fields: {
    name: {
      type: Text,
      isUnique: true
    },
    email: {
      type: Text,
    },
    password: {
      type: Password
    },
    userGroup: {
      type: Relationship,
      ref: "Group.users"
    }
  },
});

UserGroup List:

keystone.createList('Group', {
  label: 'UserGroup',
  fields: {
    name: {
      type: Text,
      isUnique: true
    },
    users: {
      type: Relationship,
      ref: "User.userGroup",
      many: true,
    },
    enableSystem: {
      type: Checkbox
    },
});

authStrategy:

const authStrategy = keystone.createAuthStrategy({
  type: PasswordAuthStrategy,
  list: 'User',
});

AdminUI app:

    new AdminUIApp({
      authStrategy,
      isAccessAllowed: ({
        authentication: {
          item: user,
          listKey: list
        }
      }) => !!user && !!user.userGroup.enableSystem
    })

Error:

TypeError: Cannot read property 'enableSystem' of undefined
    at AdminUIApp.isAccessAllowed [as _isAccessAllowed] (/test/index.js:480:40)
    at AdminUIApp.isAccessAllowed (/test/node_modules/@keystonejs/app-admin-ui/index.js:69:12)
    at app.use (/test/node_modules/@keystonejs/app-admin-ui/index.js:201:23)
    at Layer.handle [as handle_request] (/test/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/test/node_modules/express/lib/router/index.js:317:13)
    at /rat query (/test/node_modules/express/lib/middleware/query.js:45:5)
    at Layer.handle [as handle_request] (/test/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/root/topdocs/test/node_modules/express/lib/router/index.js:317:13)
    at /root/topdocs/test/node_modules/express/lib/router/index.js:284:7
    at Function.process_params (/test/node_modules/express/lib/router/index.js:335:12)
    at next (/test/node_modules/express/lib/router/index.js:275:10)

To Reproduce

open in browser

Expected behaviour

It can work.

Screenshots

If applicable, add screenshots to help explain your problem.

System information

  • OS: Windows
  • Browser Chrome

Additional context

For avoid this bug, I have to add isAdmin field in User list 😦

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Vultrazcommented, Mar 19, 2020

Yes. In my testing the userGroup field only gives you the ID of the Group entry, not the actual group data.

Pinging @MadeByMike since he added the isAccessAllowed feature.

0reactions
stale[bot]commented, Oct 3, 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. 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Django admin site not displaying ManyToManyField relationship
I've tried adding the TechInline class to the inlines list, but that causes a. 'TechInLine' not defined. Is that a straight copy-paste?
Read more >
Django admin: how to enable add/edit buttons for many-to ...
My mistake was that I didn't register related model OfferGeo in admin.py . After adding admin.site.register(OfferGeo) add/edit buttons appeared.
Read more >
FAQ: The admin - Django documentation
The admin site only allows access to users with those two fields both set to True. ... the filter for a ManyToManyField if...
Read more >
How to Implement Multiple User Types with Django
A very common case is to have a regular user and an admin user. ... ManyToManyField(Quiz, through='TakenQuiz') interests = models.
Read more >
Using the Admin Interface - Tutorial - Vskills
filter_horizontal and filter_vertical only work on ManyToManyField fields, not ForeignKey fields. By default, the admin site uses simple <select> boxes for ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found