knktc's Notes

python, cloud, linux...

0%

Change a YApi User Role Manually

YApi is not exactly a very active project anymore, but since a lot of internal projects and APIs are already stored there, it still has to stay in service.

One odd part of YApi’s design is that only the user created during installation is an administrator. Any users created later are normal members by default, and there is no obvious place in the UI to change that. If you need another admin account, the practical solution is to update the database directly.

YApi uses MongoDB on the backend, so start by entering the Mongo shell:

1
mongo

Then switch to the yapi database:

1
use yapi

Next, find the target user’s ID by username:

1
db.getCollection("user").find({"username":"knktc"})

You can also search by email:

1
db.getCollection("user").find({"email":"hello@world.com"})

Look at the returned _id field. That is the user ID you need.

Finally, update that user’s role to admin:

1
db.getCollection("user").update({"_id":2}, {$set: {"role":"admin"}})

If you ever need to revoke admin privileges, change role back to member.

如果我的文字帮到了您,那么可不可以请我喝罐可乐?