screwdriver-api 7.0.143 → 7.0.145
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/plugins/events/index.js +12 -10
- package/plugins/webhooks/helper.js +14 -8
package/package.json
CHANGED
package/plugins/events/index.js
CHANGED
|
@@ -27,10 +27,10 @@ const eventsPlugin = {
|
|
|
27
27
|
* @return {Promise} Updates the pipeline admins and throws an error if not an admin
|
|
28
28
|
*/
|
|
29
29
|
server.expose('updateAdmins', ({ permissions, pipeline, username }) => {
|
|
30
|
-
const newAdmins = pipeline.admins;
|
|
31
|
-
|
|
32
30
|
// Delete user from admin list if bad permissions
|
|
33
31
|
if (!permissions.push) {
|
|
32
|
+
const newAdmins = pipeline.admins;
|
|
33
|
+
|
|
34
34
|
delete newAdmins[username];
|
|
35
35
|
// This is needed to make admins dirty and update db
|
|
36
36
|
pipeline.admins = newAdmins;
|
|
@@ -40,16 +40,18 @@ const eventsPlugin = {
|
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
//
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
pipeline.admins = newAdmins;
|
|
43
|
+
// Put current user at the head of admins to use its SCM token after this
|
|
44
|
+
// SCM token is got from the first pipeline admin
|
|
45
|
+
const newAdminNames = [username, ...Object.keys(pipeline.admins)];
|
|
46
|
+
const newAdmins = {};
|
|
48
47
|
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
newAdminNames.forEach(name => {
|
|
49
|
+
newAdmins[name] = true;
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
pipeline.admins = newAdmins;
|
|
51
53
|
|
|
52
|
-
return
|
|
54
|
+
return pipeline.update();
|
|
53
55
|
});
|
|
54
56
|
|
|
55
57
|
server.route([
|
|
@@ -88,24 +88,30 @@ async function updateAdmins(userFactory, username, scmContext, pipeline, pipelin
|
|
|
88
88
|
try {
|
|
89
89
|
const user = await userFactory.get({ username, scmContext });
|
|
90
90
|
const userPermissions = await user.getPermissions(pipeline.scmUri);
|
|
91
|
-
const newAdmins = pipeline.admins;
|
|
92
91
|
|
|
93
92
|
// Delete user from admin list if bad permissions
|
|
94
93
|
if (!userPermissions.push) {
|
|
94
|
+
const newAdmins = pipeline.admins;
|
|
95
|
+
|
|
95
96
|
delete newAdmins[username];
|
|
96
97
|
// This is needed to make admins dirty and update db
|
|
97
98
|
pipeline.admins = newAdmins;
|
|
98
99
|
|
|
99
100
|
return pipeline.update();
|
|
100
101
|
}
|
|
101
|
-
// Add user as admin if permissions good and does not already exist
|
|
102
|
-
if (!pipeline.admins[username]) {
|
|
103
|
-
newAdmins[username] = true;
|
|
104
|
-
// This is needed to make admins dirty and update db
|
|
105
|
-
pipeline.admins = newAdmins;
|
|
106
102
|
|
|
107
|
-
|
|
108
|
-
|
|
103
|
+
// Put current user at the head of admins to use its SCM token after this
|
|
104
|
+
// SCM token is got from the first pipeline admin
|
|
105
|
+
const newAdminNames = [username, ...Object.keys(pipeline.admins)];
|
|
106
|
+
const newAdmins = {};
|
|
107
|
+
|
|
108
|
+
newAdminNames.forEach(name => {
|
|
109
|
+
newAdmins[name] = true;
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
pipeline.admins = newAdmins;
|
|
113
|
+
|
|
114
|
+
return pipeline.update();
|
|
109
115
|
} catch (err) {
|
|
110
116
|
logger.info(err.message);
|
|
111
117
|
}
|