Showing
2 changed files
with
53 additions
and
10 deletions
@@ -52,28 +52,57 @@ if ($isGoodSignature === false) { | @@ -52,28 +52,57 @@ if ($isGoodSignature === false) { | ||
52 | $redmine_admin = new Redmine\Client('https://redmine.ut.mephi.ru', REDMINE_LOGIN, REDMINE_PASSWORD); | 52 | $redmine_admin = new Redmine\Client('https://redmine.ut.mephi.ru', REDMINE_LOGIN, REDMINE_PASSWORD); |
53 | $issue = $redmine_admin->api('issue')->show($_GET['issueId'])['issue']; | 53 | $issue = $redmine_admin->api('issue')->show($_GET['issueId'])['issue']; |
54 | 54 | ||
55 | -$assignedTo = $redmine_admin->api('user' )->show($issue['assigned_to']['id']); | 55 | +$assignedTo = $redmine_admin->api('user' )->show($issue['assigned_to']['id'])['user']; |
56 | 56 | ||
57 | -$api_key = $assignedTo['user']['api_key']; | 57 | +$api_key = $assignedTo['api_key']; |
58 | $redmine = new Redmine\Client('https://redmine.ut.mephi.ru', $api_key); | 58 | $redmine = new Redmine\Client('https://redmine.ut.mephi.ru', $api_key); |
59 | 59 | ||
60 | -function addUserToProject(&$redmine, $user_id, $project_id) { | 60 | +function addUserToProject(&$redmine, $user_id, $project_id, $role_id) { |
61 | + error_log("addUserToProject(redmine, $user_id, $project_id, $role_id)"); | ||
61 | $current_membership = $redmine->api('membership')->all($project_id); | 62 | $current_membership = $redmine->api('membership')->all($project_id); |
62 | foreach ($current_membership['memberships'] as $global_key => $member){ | 63 | foreach ($current_membership['memberships'] as $global_key => $member){ |
63 | if ($member['user']['id'] == $user_id){ | 64 | if ($member['user']['id'] == $user_id){ |
64 | $cur_roles=array(); | 65 | $cur_roles=array(); |
65 | $membership_id = $current_membership['memberships'][$global_key]['id']; | 66 | $membership_id = $current_membership['memberships'][$global_key]['id']; |
66 | foreach($current_membership['memberships'][$global_key]['roles'] as $role) { | 67 | foreach($current_membership['memberships'][$global_key]['roles'] as $role) { |
68 | + if ($role['id'] == $role_id) { | ||
69 | + //print "already there!\n"; | ||
70 | + return true; | ||
71 | + } | ||
67 | $cur_roles[] = $role['id']; | 72 | $cur_roles[] = $role['id']; |
68 | } | 73 | } |
69 | - return $redmine->api('membership')->update($membership_id, array ('role_ids' => array_merge($cur_roles, array(ROLE_CUSTOMER)))); | 74 | + $role_ids = array('role_ids' => array_merge($cur_roles, array($role_id))); |
75 | + //print "updating\n"; | ||
76 | + //print_r($role_ids); | ||
77 | + return $redmine->api('membership')->update($membership_id, $role_ids); | ||
70 | } | 78 | } |
71 | } | 79 | } |
72 | - return $redmine->api('membership')->create($project_id, array('user_id' => $user_id, 'role_ids' => array(ROLE_CUSTOMER))); | 80 | + //print "creating\n"; |
81 | + return $redmine->api('membership')->create($project_id, array('user_id' => $user_id, 'role_ids' => array($role_id))); | ||
82 | +} | ||
83 | + | ||
84 | +function removeUserFromProject(&$redmine, $user_id, $project_id, $role_id) { | ||
85 | + error_log("removeUserFromProject(redmine, $user_id, $project_id, $role_id)"); | ||
86 | + $current_membership = $redmine->api('membership')->all($project_id); | ||
87 | + foreach ($current_membership['memberships'] as $global_key => $member){ | ||
88 | + if ($member['user']['id'] == $user_id){ | ||
89 | + $role_ids=array(); | ||
90 | + $membership_id = $current_membership['memberships'][$global_key]['id']; | ||
91 | + foreach($current_membership['memberships'][$global_key]['roles'] as $role) { | ||
92 | + if ($role['id'] == $role_id) { | ||
93 | + continue; | ||
94 | + } | ||
95 | + $role_ids[] = $role['id']; | ||
96 | + } | ||
97 | + return $redmine->api('membership')->update($membership_id, $role_ids); | ||
98 | + } | ||
99 | + } | ||
100 | + return true; | ||
73 | } | 101 | } |
74 | 102 | ||
75 | switch ($_GET['action']) { | 103 | switch ($_GET['action']) { |
76 | case 'agree': | 104 | case 'agree': |
105 | + case 'move': | ||
77 | header('Content-Type: text/plain'); | 106 | header('Content-Type: text/plain'); |
78 | 107 | ||
79 | $recipientId = NULL; | 108 | $recipientId = NULL; |
@@ -95,15 +124,29 @@ switch ($_GET['action']) { | @@ -95,15 +124,29 @@ switch ($_GET['action']) { | ||
95 | die('Произошла ошибка. Пожалуйста, повторите попытку позже. Cannot find login of user with ID: '.$recipientId); | 124 | die('Произошла ошибка. Пожалуйста, повторите попытку позже. Cannot find login of user with ID: '.$recipientId); |
96 | } | 125 | } |
97 | 126 | ||
98 | - //print_r($issue);die(); | 127 | + $project_id = redmine_proj_identifier2id(strtolower(explode('@', $recipient['mail'])[0])); |
99 | - /*$result = addUserToProject($redmine, $recipientId, $issue['project']['id']); | 128 | + |
100 | - if ($result !== TRUE) { | 129 | + addUserToProject($redmine_admin, $assignedTo['id'], $project_id, ROLE_CUSTOMER); |
130 | + addUserToProject($redmine_admin, $assignedTo['id'], $project_id, ROLE_MOVER); | ||
131 | + /*$result =*/ | ||
132 | + /*if ($result !== TRUE) { | ||
101 | mail('admin@ut.mephi.ru', 'Got error on decide-note.php', print_r($_GET, 1)); | 133 | mail('admin@ut.mephi.ru', 'Got error on decide-note.php', print_r($_GET, 1)); |
102 | die('Произошла ошибка. Пожалуйста, повторите попытку позже. Cannot add user '.$recipientId.' to project '.$issue['project']['id'].': '.print_r($result, 1)); | 134 | die('Произошла ошибка. Пожалуйста, повторите попытку позже. Cannot add user '.$recipientId.' to project '.$issue['project']['id'].': '.print_r($result, 1)); |
103 | }*/ | 135 | }*/ |
104 | 136 | ||
105 | //print @json_encode($redmine->api('issue')->update($issue['id'], array('status_id' => STATUSID_NEW, 'project_id' => redmine_proj_identifier2id(strtolower(explode('@', $recipient['mail'])[0])), 'assigned_to_id' => $recipient['id']))); | 137 | //print @json_encode($redmine->api('issue')->update($issue['id'], array('status_id' => STATUSID_NEW, 'project_id' => redmine_proj_identifier2id(strtolower(explode('@', $recipient['mail'])[0])), 'assigned_to_id' => $recipient['id']))); |
106 | - $result = $redmine->api('issue')->update($issue['id'], array('status_id' => STATUSID_NEW, 'project_id' => redmine_proj_identifier2id(strtolower(explode('@', $recipient['mail'])[0])), 'assigned_to_id' => $recipient['id'])); | 138 | + |
139 | + $issue_props = array( | ||
140 | + 'project_id' => $project_id, | ||
141 | + 'assigned_to_id' => $recipient['id'] | ||
142 | + ); | ||
143 | + | ||
144 | + if ($_GET['action'] == 'agree') | ||
145 | + $issue_props['status_id'] = STATUSID_NEW; | ||
146 | + //print_r($issue_props);die(); | ||
147 | + | ||
148 | + $result = $redmine->api('issue')->update($issue['id'], $issue_props); | ||
149 | + removeUserFromProject($redmine_admin, $assignedTo['id'], $project_id, ROLE_MOVER); | ||
107 | if ($result !== TRUE) { | 150 | if ($result !== TRUE) { |
108 | mail('admin@ut.mephi.ru', 'Got error on decide-note.php', print_r($_GET, 1)); | 151 | mail('admin@ut.mephi.ru', 'Got error on decide-note.php', print_r($_GET, 1)); |
109 | die('Произошла ошибка. Пожалуйста, повторите попытку позже. Cannot update the issue '.$issue['project']['id'].': '.print_r($result, 1)); | 152 | die('Произошла ошибка. Пожалуйста, повторите попытку позже. Cannot update the issue '.$issue['project']['id'].': '.print_r($result, 1)); |
-
Please register or login to post a comment