Skip to content

Make roles search for user in classhelper a dropdown/select element #33

@rouilj

Description

@rouilj

From issue #27: #27 (comment)

====

[...]roles are a property, but they are not a linked class that you can query. The answer is hinted at by:

https://roundup-tracker.org/docs/rest.html#controlling-access-to-backend-data

by adding a REST endpoint. I am not sure if you can use that method to add:

tracker.../data/user/role

I'll try it. However, you can set up searching on an issue by title (text search) and keyword, status or priority as dropdowns as keyword, status and priority are true classes.

====

From: #27 (comment)

====

I can't get '/rest/data/user/role' or '/rest/data/role' to work, but I do have '/rest/role' working.

Create the file interfaces.py in your tracker home directory and add:

from roundup.rest import Routing, RestfulInstance,  _data_decorator

class RestfulInstance:

    @Routing.route("/roles", 'GET')
    @_data_decorator
    def get_roles(self, input):
        """Return all defined roles. The User class property
           roles is a string but simulate it as a MultiLink
           to an actual Roles class.
        """
        return 200, {"collection": [ {"id": rolename, "name": rolename}
                  for rolename in list(self.db.security.role.keys())]}

Restart your tracker and query:

http://localhost:8080/demo/rest/roles

which returns a list of roles like:

{
    "data": {
        "collection": [
            {
                "id": "user",
                "name": "user"
            },
            {
                "id": "admin",
                "name": "admin"
            },
            {
                "id": "anonymous",
                "name": "anonymous"
            }
        ]
    }
}

Note that the id can't be interpreted as an integer because we are faking a real database
class. The shape of the data can be made simpler if we want. I chose this shape to match
what you see when querying a real class endpoint like /rest/data/status.

====

Note you need to hit the endpoint /demo/rest/roles not /demo/rest/data/roles. This may be an issue
as I think the existing REST query methods assume the /rest/data/ component of the URL.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions