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

Export resource_class_map and fix bug in Role.add_user() #1002

Conversation

wlupton
Copy link
Contributor

@wlupton wlupton commented Feb 26, 2021

The reason for exporting resource_class_map is to allow an external module to support additional resource types without the need to edit resources.py (I had edited it previously but this became a maintenance nightmare).

The Role.add_user() bug is (I hope) an obvious one: the groups argument was ignored.


Some of my local extensions conflict with more recent extensions in master. For example, I supported notification schemes and permission schemes, but I took a different approach: I also added new resource types, and the methods return resources rather than dictionaries. For example:

Master:

    @lru_cache(maxsize=None)
    def notificationschemes(self):
        # TODO(ssbarnea): implement pagination support
        url = self._options["server"] + "/rest/api/3/notificationscheme"

        r = self._session.get(url)
        data = json_loads(r)
        return data["values"]

Mine:

    def notificationschemes(self) -> List[NotificationScheme]:
        """Get a list of notificationscheme Resources."""
        r_json = self._get_json('notificationscheme')
        notificationschemes = [
            NotificationScheme(self._options, self._session, raw_res_json) for
            raw_res_json in r_json['values']]
        return notificationschemes

There was already some level of Role support, and I took this approach to extending the interface (this is in a wrapper class that calls methods from the existing master class when it can):

    @translate_resource_args
    def project_roles(self, project: IDorName, *, as_list: bool = False,
                      as_resources: bool = False):
        assert self._mode == 'online'
        # this returns a Dict[str, Dict[str, Any]]
        roles = self._jira.project_roles(project)
        # add a 'name' key (needed if will return a list)
        roles = {name: {**value, 'name': name} for name, value in
                 roles.items()}
        # if requested, convert to Dict[str, ProjectRole]
        if as_resources:
            roles = {name: ProjectRole(self._options, self._session, value) for
                     name, value in roles.items()}
        # if requested, convert to List[]
        if as_list:
            roles = list(roles.values())
        return roles

Please let me know if you'd like me to contribute any of these extensions.

The reason for exporting resource_class_map is to allow an external module to support additional resource types without the need to edit resources.py (I had edited it previously but this became a maintenance nightmare).

The Role.add_user() bug is (I hope) an obvious one: the groups argument was ignored.
@studioj
Copy link
Collaborator

studioj commented Apr 4, 2021

looks like the maintainers want to have the ci system back up and running before agreeing to any new merges.

if you want to contribute to get yr pr through have a look here => #896

@ssbarnea
Copy link
Member

@wlupton Closing due to of updates. If you can rebase it tell us to reopen it.

@ssbarnea ssbarnea closed this May 18, 2021
@helpatbbf
Copy link

That's fine @ssbarnea, but is the reason for closure because it needs rebasing (easy to fix) or the reason given earlier about getting the ci system back up?

@ssbarnea
Copy link
Member

CI was fixed, I closed as it needed rebase. If you find it useful just make another PR. Only the original OP can update it so that is why I closed it.

@helpatbbf
Copy link

Great (sorry, I didn't realize). I've rebased and pushed. Thanks.

@helpatbbf
Copy link

@ssbarnea, I don't see an option to re-open it. Are you able to do this? If not, I can easily create a new PR.

@ssbarnea
Copy link
Member

Create new one, I am unable to press the button either, not sure why.

@helpatbbf
Copy link

OK. Will do.

Also, did you have any thoughts on the other items in the PR's initial commen?

@ssbarnea
Copy link
Member

nope

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants