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

Deleting user kills interface and tickets #408

Closed
2 tasks done
nunodsfernandes opened this issue May 15, 2021 · 12 comments
Closed
2 tasks done

Deleting user kills interface and tickets #408

nunodsfernandes opened this issue May 15, 2021 · 12 comments

Comments

@nunodsfernandes
Copy link

nunodsfernandes commented May 15, 2021

Is this a BUG REPORT or FEATURE REQUEST?:

  • BUG
  • FEATURE

What happened:
User left team, we had to remove access.
Deleting the user broke interface. One of the tickets will not appear, and no stats are shown.

What did you expect to happen:
User should be disabled or removed without affecting other tickets.
As user goes away, other team members pick up his tasks and tickets.

How to reproduce it (as minimally and precisely as possible):
Create user, assign tickets, delete user.
Interface gets broken apparently.

Anything else we need to know?:
How can i fix this?
I attempted to create a user with same name and data, but issue remains.
Is there a DB query i can run to delete his tickets or assign them to other user?
Not Mongo DB knowledgeable at all.

Environment:

  • Trudesk Version: 1.1.2
  • OS (e.g. from /etc/os-release): Ubuntu
  • Node.JS Version: 10.24.0
  • MongoDB Version: 3.6.22
  • Is this hosted on cloud.trudesk.io: No
@polonel
Copy link
Owner

polonel commented May 31, 2021

How was the user removed? If the user is removed through the accounts page it should scan if they have any tickets and disable the user instead of deleting the user.

@nunodsfernandes
Copy link
Author

Hi @polonel

The user was removed via the accounts page.
If disabling was the intended behavior, something went wrong then.
How can i debug it? It kinda broke the whole stats GUI, and for tickets, i can't even open a ticket that had his assignment.

@polonel
Copy link
Owner

polonel commented May 31, 2021

Do you have access to the database? Need to get the ID of the user from a ticket he created or assigned to. Once you have that, you will need to "recreate" his user and then run a MongoDB query to replace the new user's _id value with the original _id you got from an existing ticket.

Something like:

> myId=db.accounts.findOne({_id:ObjectId("ID_OF_NEW_USER")});
> myId._id = ObjectId("ORIGINALID");
> db.accounts.insert(myID);
> db.accounts.remove({_id:ObjectId("ID_OF_NEW_USER")});

This will copy the data used from the newly created user and store it in a temp obj. Replaces the temp obj _id with the original id and then reinserts. Finally, it removes the user with the new _id while retaining the original.

@nunodsfernandes
Copy link
Author

nunodsfernandes commented May 31, 2021

Hi @polonel
Thanks for the explanation.

I've created another username for him, trying to recover the data in some way.
I was hoping the association was made using username and not some kind of token.
The old and new usernames are the same.

I do have access to DB, however, that query shows:

> myId=db.accounts.findOne({_id:ObjectId("oliveira")});
2021-05-31T21:01:12.885+0000 E QUERY    [thread1] Error: invalid object id: length :
@(shell):1:31
>

The user data for the ex-team member was:
image

So, should be myId=db.accounts.findOne({_id:ObjectId("oliveira")}); , right?

Edit:
Also, if i try to open any ticket with him assigned, it only shows me a blank page on the GUI.
Not sure how i'll get any data from it...

Thanks again for your time.

@polonel
Copy link
Owner

polonel commented May 31, 2021

Sorry, the _id and username are different fields. You can query the user by username with:
> db.accounts.findOne({username: "oliveira"});
which will return the full object. You can see what the _id is with the return value. Then use that _id in the queries above.

To get the _id of the original you will need to do something like:

> db.tickets.findOne({uid: 1001})
where uid is the ticket # of the ticket that he either created or assigned to. If he created the ticket it will show the _id under the owner field. If he was assigned to the ticket, it will be under the assignee field.

polonel added a commit that referenced this issue Jun 1, 2021
## [1.1.4](v1.1.3...v1.1.4) (2021-06-01)

### Bug Fixes

* **accounts:** check if agent is assignee before deleting agent. [#408](#408) ([81fd6ea](81fd6ea))
* **build:** stop nightly build ([fefb8de](fefb8de))
* **tickets:** third party ([c954ba0](c954ba0))
@nunodsfernandes
Copy link
Author

nunodsfernandes commented Jun 1, 2021

Hi @polonel

Thanks for the help.
I retrieved the data:

db.accounts.findOne({username: "oliveira"});

{
        "_id" : ObjectId("609c3d4e155f934e12de314d"),
        "preferences" : {
                "tourCompleted" : false,
                "autoRefreshTicketGrid" : true,
                "openChatWindows" : [ ]
        },
        "hasL2Auth" : false,
        "deleted" : false,
        "username" : "oliveira",
        "email" : "[email protected]",
        "password" : "$2b$10$EXY6f6CBeYOxUClbt4/oJOuRlLYUNXchU23DKlEX/NCWO5rf8W5tq",
        "fullname" : "Ricardo Oliveira",
        "title" : "Support Engineer",
        "role" : ObjectId("6046c31858eaf16e2df24cb3"),
        "accessToken" : "4104e6d5cc0afa967e2858d066a218906ba33eb2",
        "__v" : 0
}
>

db.tickets.findOne({uid: 1012})

{
        "_id" : ObjectId("6063881ca594b9469f5ddec0"),
        "deleted" : false,
        "status" : 2,
        "tags" : [
                ObjectId("605b39c0a594b9469f5dde1e")
        ],
        "subscribers" : [
                ObjectId("604a59e00fd7154f5eb19d56"),
                ObjectId("604a5bb70fd7154f5eb19d63")
        ],
        "owner" : ObjectId("604a59e00fd7154f5eb19d56"),
        "subject" : "EO Backup and Restore",
        "group" : ObjectId("6046d44487b1e728ae9167d0"),
        "type" : ObjectId("6046c31858eaf16e2df24cb1"),
        "priority" : ObjectId("6046c32087b1e728ae9167b6"),
        "issue" : "<p>Please review the GitHub issue and let us know the status and what is needed to move forward</p>\n",
        "date" : ISODate("2021-03-30T20:20:44.828Z"),
        "comments" : [



(... a lot more content on the history)

}

So, if i'm getting this straight, the queries should be:

> myId=db.accounts.findOne({_id:ObjectId("609c3d4e155f934e12de314d")});
> myId._id = ObjectId("604a59e00fd7154f5eb19d56");
> db.accounts.insert(myID);
> db.accounts.remove({_id:ObjectId("609c3d4e155f934e12de314d")});

However, db.accounts.insert(myID); shows:

> db.accounts.insert(myID);
2021-06-01T15:57:47.110+0000 E QUERY    [thread1] ReferenceError: myID is not defined :
@(shell):1:1

Do i define the variables inside the mongodb cli?

@polonel
Copy link
Owner

polonel commented Jun 1, 2021

Yes inside the Mongo CLI. But it is case-sensitive. it was declared as myId but used as myID.

@nunodsfernandes
Copy link
Author

Hi, it did not work at all.. And now I think I orphaned the tickets, as the ID is no longer there.

Is there a way to find all references to that object ID and change them to a new one?
Like a for loop or something?

I've seen this https://gist.github.com/vonox7/9fd5054ad9fcbf39d6c1071800647b7b
But not sure if it's applicable..

@polonel
Copy link
Owner

polonel commented Jun 1, 2021

Those queries should have not updated anything to do with the tickets. Did the user's _id update correctly? With the duplicate user removed?

The tickets were already orphaned as it was unable to find a user linked. Thus that's why you were seeing the blank gui page. (errors were probably showing in browser's console)

Changing all the references on all the tickets is the wrong approach. Recreating a user with the missing ID is the correct approach.

I just physically tested the queries with the same situation where the owner was removed forceably. I successfully added the user back using this mention without having to change anything on the tickets. The only thing I had to do differently was remove the user before added them as the username were duplicate and the index wouldn't allow me to add it back. So in your case the queries should be.

> myId=db.accounts.findOne({username: "oliveira"});
> myId._id = ObjectId("604a59e00fd7154f5eb19d56");
> db.accounts.remove({username: "oliveira"});
> db.accounts.insert(myId);

@nunodsfernandes
Copy link
Author

Hi @polonel
Thanks for the super-detailed explanation and your patience with a noob!

For the tickets, i can access the previously blank tickets again.
All good!! :)

However, for the dashboard, everything still shows blank.
Is it related?

image

@nunodsfernandes
Copy link
Author

Aaaaand nevermind...
It decided to work :)
It was a cache issue.

image

Once again, thank you so much for your help @polonel
You're epic :D

We can close.

@polonel
Copy link
Owner

polonel commented Jun 2, 2021

Thanks. Yea I was about to tell you to restart the server or wait an hour and the stats should refresh once the cache invalidates. Glad I could help.

@polonel polonel closed this as completed Jun 2, 2021
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