clowder-framework / clowder

A data management system that allows users to share, annotate, organize and analyze large collections of datasets. It provides support for extensible metadata annotation using JSON-LD and a distribute analytics event bus for automatic curation of uploaded data.
https://clowderframework.org/
University of Illinois/NCSA Open Source License
37 stars 17 forks source link

Roles categories show twice #318

Closed lmarini closed 2 years ago

lmarini commented 2 years ago

Space roles page show categories twice. Seen on v1.19.2 CINET instance

Screen Shot 2022-01-27 at 10 41 16 AM

.

longshuicy commented 2 years ago

hmm i can't duplicate this on my local though: image

this is branching off the latest develop branch

robkooper commented 2 years ago

this seems to be related to a migration of the mongo database, and not dropping the table (or starting clowder before import is finished) when importing a mongo dump.

You can see this by running:

db.roles.find().forEach(function(d) { print(d._id + " " + d.name + " " + db.social.users.count({"spaceandrole.role._id": d._id}))})
61301dafe4b0bf6768a4b517 Admin 2
61301dafe4b0bf6768a4b518 Editor 0
61301dafe4b0bf6768a4b519 Viewer 0
5744cb6de4b01f66da43df9a Admin 33
5744cb6de4b01f66da43df9c Viewer 14
5744cb6de4b01f66da43df9b Editor 4

This shows that there are 2 admin roles, one with 2 and one with 33 users. Next step is to merge the two admin roles:

db.social.users.updateOne({"spaceandrole.role._id": ObjectId("61301dafe4b0bf6768a4b517")}, {$set: {"spaceandrole.$.role._id": ObjectId("5744cb6de4b01f66da43df9a")}}, {multi:1})

Running the first query shows it worked:

db.roles.find().forEach(function(d) { print(d._id + " " + d.name + " " + db.social.users.count({"spaceandrole.role._id": d._id}))})
61301dafe4b0bf6768a4b517 Admin 0
61301dafe4b0bf6768a4b518 Editor 0
61301dafe4b0bf6768a4b519 Viewer 0
5744cb6de4b01f66da43df9a Admin 34
5744cb6de4b01f66da43df9c Viewer 14
5744cb6de4b01f66da43df9b Editor 4

finally we can remove the extra roles (i picked the smallest id of the new roles):

db.roles.remove({"_id": {$gte: ObjectId("61301dafe4b0bf6768a4b517")}})
WriteResult({ "nRemoved" : 3 })