Badgeyay has been progressing in a very good pace. There are a lot of features being developed and modified in this project. One such feature that has been added is the increasing allowed usage of a user by an admin.
What is Allowed Usage?
Allowed usage is an integer associated with a particular user that determines the number of badges that a person can generate using a single email id. This will allow us to keep track of the number of badges being produced by a particular ID and all.
Modifying the Allowed Usage
This feature is basically an Admin feature, that will allow an admin to increase or decrease the allowed usage of a particular user. This will ensure that if incase a particular user has his/her usage finished, then by contacting the admin, he/she can get the usage refilled.
Adding the functionality
The functionality required us to to add two things
- A schema for modifying allowed user
- A route in backend to carry out the functionality
So, Let us start by creating the schema
id = fields.Str(required=True, dump_only=True)
Once we have our schema created, then we can create a route to modify the allowed usage for a particular user.
This route will be made accessible to the admin of Badgeyay.
uid = data[‘uid’]
The add_usage route is given above. We can use this route to increase the usage of a particular user.
Given below is an image that shows the API working.
- The Pull Request for this issue : https://github.com/fossasia/badgeyay/pull/982
- The Issue related to this blog : https://github.com/fossasia/badgeyay/issues/981
- Read about adding routes Blueprint : http://flask.pocoo.org/docs/1.0/blueprints/
- Read about Schemas : https://github.com/marshmallow-code/marshmallow-jsonapi