Last active
January 24, 2022 16:06
-
-
Save itst/075daa3feb2b41e651fdd468f3e83028 to your computer and use it in GitHub Desktop.
Checks project permissions for a user, based on a list of Jira projects and a list of permissions to check for.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
define("BASE", "https://<jira-api-url>"); | |
define("CHECKFOR", array( | |
'EDIT_SPRINT_NAME_AND_GOAL_PERMISSION', | |
'MANAGE_SPRINTS_PERMISSION', | |
'START_STOP_SPRINTS_PERMISSION' | |
)); | |
function prepareCall(&$curl, $query) { | |
curl_setopt($curl, CURLOPT_URL, BASE . $query); | |
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); | |
// Use user:passwd or a PAT to authenticate | |
// curl_setopt($curl, CURLOPT_USERPWD, '<user>:<passwd>'); | |
// curl_setopt($curl, CURLOPT_HTTPHEADER, array('Authorization: Bearer <Personal Access Token. See https://confluence.atlassian.com/enterprise/using-personal-access-tokens-1026032365.html>')); | |
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); | |
} | |
function getProjectPermission($projectKey) { | |
$ch = curl_init(); | |
prepareCall($ch, 'mypermissions?projectKey=' . $projectKey); | |
$result = curl_exec($ch); | |
return $result; | |
} | |
$projects = json_decode('[ | |
{ | |
"projectName": "AM-QS-Tools", | |
"projectKey": "AMTOOLS" | |
}, | |
]'); | |
echo "projectName;projectKey;" . implode(";", CHECKFOR) . "\n"; | |
foreach ($projects as $_project) { | |
echo $_project->projectName . ";" . $_project->projectKey . ";"; | |
$_permissions = json_decode(getProjectPermission($_project->projectKey)); | |
foreach (CHECKFOR as $_permission) { | |
echo ($_permissions->permissions->$_permission->havePermission ? "true" : "false") . ";"; | |
} | |
echo "\n"; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment