From 02069f60d2b3da2e6972084ce1b755ba5be1071b Mon Sep 17 00:00:00 2001 From: Louis Cherel Date: Wed, 17 Oct 2018 12:33:05 +0200 Subject: [PATCH 1/2] doc: explain Sudo header --- README.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/README.md b/README.md index 1d1515f8..00847999 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ - [Bundle Imports](#bundle-imports) - [Examples](#examples) - [Pagination](#pagination) + - [Sudo](#sudo) - [Migrating from node-gitlab](#migrating-from-node-gitlabnode-gitlab) - [Docs](#docs) - [Development](#development) @@ -378,6 +379,28 @@ pagination: { } ``` +### Sudo +For private gitlab instances, administrators are able to impersonate users through the API. To do so, you have to set the 'Sudo' header on the services you want to impersonate the user for. + +For example, if you want to disable notifications for a specific user: +```javascript +import Gitlab from 'gitlab'; + +const api = new Gitlab({ + url: 'http://example.com', // Defaults to http://gitlab.com + token: 'abcdefghij123456' // Can be created in your profile. +}); + +api.NotificationSettings.headers.Sudo = userid_or_username; // eg: 1 or 'username' + +await api.NotificationSettings.edit({ + level: api.NotificationSettings.LEVELS.DISABLED +}) + +delete api.NotificationSettings.headers.Sudo // clear impersonation header afterwards + +``` + ## Migrating from node-gitlab/node-gitlab With the success of this library thanks to the community, this has become the main npm package to interact with the Gitlab API. As such, there will be a little bit of growing pains for those upgrading from the original node-gitlab v1.8 to our newest 3.0.0 release, far too many to list here. I hope the library is written clearly enough to ease this transition, but if there is anything that you're having trouble with please feel free to create an issue! If not myself, someone will definitely have the answer to help get you all setup up as quickly as possible. @@ -495,3 +518,5 @@ This started off as a fork from [node-gitlab](https://github.com/node-gitlab/nod ## Changelog [Here](https://github.com/jdalrymple/node-gitlab/blob/master/CHANGELOG.md) + + From d2a142caa2dabcffcfd66cffc3d92045281cbc82 Mon Sep 17 00:00:00 2001 From: Louis Cherel Date: Wed, 17 Oct 2018 21:42:09 +0200 Subject: [PATCH 2/2] README.md: fix use of sudo --- README.md | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 00847999..eb4e64ae 100644 --- a/README.md +++ b/README.md @@ -386,19 +386,15 @@ For example, if you want to disable notifications for a specific user: ```javascript import Gitlab from 'gitlab'; -const api = new Gitlab({ +const { NotificationSettings } = new Gitlab({ url: 'http://example.com', // Defaults to http://gitlab.com token: 'abcdefghij123456' // Can be created in your profile. + sudo: userid_or_username }); -api.NotificationSettings.headers.Sudo = userid_or_username; // eg: 1 or 'username' - await api.NotificationSettings.edit({ level: api.NotificationSettings.LEVELS.DISABLED }) - -delete api.NotificationSettings.headers.Sudo // clear impersonation header afterwards - ``` ## Migrating from node-gitlab/node-gitlab