Open scott-hpe opened 2 years ago
Thanks for the details! As you say this is definitely a bug on this side handling the GDPR change.
As an FYI, you would probably need to use jira_conn.add_user_to_group(user.accountId, grp.name)
once we implement a fix that would look like this:
def add_user_to_group(
self, username: str, group: str
) -> Union[bool, Dict[str, Any]]:
"""Add a user to an existing group.
Args:
username (str): Username that will be added to specified group.
group (str): Group that the user will be added to.
Returns:
Union[bool,Dict[str,Any]]: json response from Jira server for success or a value that evaluates as False in case of failure.
"""
url = self._get_latest_url("group/user")
x = {"groupname": group}
y = {"accountId" if self._is_cloud else "name": username}
payload = json.dumps(y)
r: Dict[str, Any] = json_loads(self._session.post(url, params=x, data=payload))
if "name" not in r or r["name"] != group:
return False
else:
return r
The same error is being returned on trying to delete user from a group like this:
from jira.config import get_jira
from jira import JIRA
jira = get_jira(profile='enterprise-pro')
jira.remove_user_from_group('5e66020a1238f60cfe66ba98', 'advanced-roadmaps')
This is the error being returned:
PS C:\Users\pulgarig\Documents\JiraCloudREST> & c:/Users/pulgarig/Documents/JiraCloudREST/venv/Scripts/python.exe c:/Users/pulgarig/Documents/JiraCloudREST/jiralibrary.py Traceback (most recent call last): File "c:\Users\pulgarig\Documents\JiraCloudREST\jiralibrary.py", line 6, in
jira.remove_user_from_group('5e66020a1238f60cfe66ba98', 'advanced-roadmaps') File "C:\Users\pulgarig\Documents\JiraCloudREST\venv\lib\site-packages\jira\client.py", line 4421, in remove_user_from_group self._session.delete(url, params=x) File "C:\Users\pulgarig\Documents\JiraCloudREST\venv\lib\site-packages\jira\resilientsession.py", line 204, in delete
return self.verb("DELETE", str(url), **kwargs) File "C:\Users\pulgarig\Documents\JiraCloudREST\venv\lib\site-packages\jira\resilientsession.py", line 189, in verb
raise_on_error(response, verb=verb, *kwargs) File "C:\Users\pulgarig\Documents\JiraCloudREST\venv\lib\site-packages\jira\resilientsession.py", line 64, in raise_on_error raise JIRAError( jira.exceptions.JIRAError: JiraError HTTP 404 url: https://vorwerk.atlassian.net/rest/api/latest/group/user?groupname=advanced-roadmaps&username=5e66020a1238f60cfe66ba98 text: Specified user does not exist or you do not have required permissions response headers = {'Date': 'Fri, 10 Jun 2022 12:17:56 GMT', 'Content-Type': 'application/json;charset=UTF-8', 'Server': 'globaledge-envoy', 'Timing-Allow-Origin': '', 'X-Arequestid': '0e0ebc88-f390-42fd-b78d-ffa4442d8f8e', 'X-Aaccountid': '60bf3808b1f93b0069603b4b', 'Cache-Control': 'no-cache, no-store, no-transform', 'Content-Encoding': 'gzip', 'X-Envoy-Upstream-Service-Time': '42', 'Expect-Ct': 'report-uri="https://web-security-reports.services.atlassian.com/expect-ct-report/atlassian-proxy", max-age=86400', 'Strict-Transport-Security': 'max-age=63072000; preload', 'X-Content-Type-Options': 'nosniff', 'X-Xss-Protection': '1; mode=block', 'Atl-Traceid': 'b3742f1570c7c0bc', 'Report-To': '{"group": "endpoint-1", "max_age": 600, "endpoints": [{"url": "https://dj9s4kmieytgz.cloudfront.net"}], "include_subdomains": true}', 'Nel': '{"report_to": "endpoint-1", "max_age": 600, "include_subdomains": true, "failure_fraction": 0.001}', 'Transfer-Encoding': 'chunked'} response text = {"errorMessages":["Specified user does not exist or you do not have required permissions"],"errors":{}}
@adehad the fix you proposed works on our side. Can this code snippet be directly pushed to the package ?
+1 I can confirm this works as a patch to the module.
+1, The patch worked for me too. Will it be in the next update? When is that coming out?
there is the possibility I can work on it this weekend, but happy to review/approve any PRs that might come before then. Glad to have confirmation the patch works, so I may implement it without a test (which was the main reason it isn't here already)
Bug summary
When adding a user to group in Jira cloud it fails with 404 and stacktrace shown below. Possibly related to GDPR changes and username not being valid any more. Confirmed working when using curl example:
Is there an existing issue for this?
Jira Instance type
Jira Cloud (Hosted by Atlassian)
Jira instance version
No response
jira-python version
main
Python Interpreter version
3.10
Which operating systems have you used?
Reproduction steps
Stack trace
Expected behaviour
User should be added to group.
Additional Context
No response