question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add functions to add users/admins to a group

See original GitHub issue

The group addUsers operation is not yet covered in this library and it is an important feature to add.

The ArcGIS REST API has one single endpoint to add both users and admins. But for simplicity, we can add two functions addGroupAdmins(groupId, admins) and addGroupUsers(groupId, users), which take an array of usernames as the second parameter.

A limitation of the original endpoint is that it only accepts up to 25 usernames per request and throws an error if the developer passes a long array. In practice, the developer needs to send multiple requests if there are many group members to add. The logic is like this:

// pass a groupId and a long array of usernames
function addManyGroupUsers (groupId, usernames) {
  // break the long array into smaller ones, each has up to 25 elements
  const chunks = _.chunk(usernames, 25);

  // send multiple requests at the same time (or maybe sequentially)
  const promises = chunks.map((users) => sendAddUserRequest(groupId, users));

  return Promise.all(promises);
}

This batch request logic can be included the new functions and the user can forget the endpoint limitation.

The problem of batching requests is from the request error. Fortunately, the addUsers operation is idempotent and the developer can retry many times until succeed, without worrying about duplicate members. So I think it can simply fail the whole function if one request fails.

Otherwise, the request error can be caught as

const promises = chunks.map(
  (users) => sendAddUserRequest(groupId, users)
    .catch(err => {
      return {
        // these usernames are not added because of the request failure
        notAdded: chunks,
        // it needs a flag to indicate whether the "notAdded" is from a request
        // failure or a user issue (already added, group member limit reached,
        // etc)
        requestFailure: true
      }
    })
);

The original issue is posted at https://github.com/Esri/ember-arcgis-portal-services/issues/157

@tomwayson for review

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
haoliangyucommented, Jun 13, 2019

@tomwayson All great points!

I’d be tempted to mimic the REST API’s parameters (i.e. one fn that takes optional users, and/or admins)

I agree. We can send separate requests for admins and users, but the function parameters should be the same as the REST API.

I think the most helpful thing for the user would be to aggregate all the successful and error response into a single hash

👍

I wonder if it would be better to call this something other than notAdded?

or attach the request body and URL?

0reactions
haoliangyucommented, Jun 14, 2019

👍 thanks @tomwayson. I think I have enough information to start with.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add users, groups, or devices to an administrative unit
Add users, groups, or devices to a single administrative unit · Sign in to the Azure portal or Azure AD admin center. ·...
Read more >
PowerShell – add User to Group with Add-ADGroupMember
The Add-ADGroupMember cmdlet can be used to add users, service accounts, computers, or even other groups to an AD Group. The cmdlet only ......
Read more >
Adding a User to the Administrators Group - Oracle Help Center
From the User Manager main window, double-click the Administrators group. · On Administrators Properties, click Add. · On Select Users or Groups, select...
Read more >
Windows 10 - Adding Users to the Administrators Group
This tutorial explains how to add users to the administrators group in multiple ways.
Read more >
How to Assign and Remove Admin Functions from a User
For information about managing users and groups, see our Users ... Click the drop-down arrow next to the user and select Add Admin...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found