Jump to content

CDS Add/Remove User Groupmapping


Andreas_Hoffmann
 Share


Recommended Posts

Hi,

 

my following funktion working fine:

 

 Public Shared Sub AddUser(Group As String, User As String)

 

        Dim GroupToConfig As SWConfigDataClientLib.Proxies.Groups.GroupEntry
        Dim UserToConfig As SWConfigDataClientLib.Proxies.Users.UserEntry

 

        GroupToConfig = libManager.GetGroupEnum.AddUserToEnumByName(Group)
        UserToConfig = libManager.GetUserEnum.AddUserToEnumByName(User)

 

        Dim UserIDtoConfig As Int32 = UserToConfig.UserID
        Dim GroupIDtoConfig As Int32 = GroupToConfig.GroupID


        Dim GroupMapping As = New Proxies.Groups.MembershipEntry With {
        .GroupID = GroupIDtoConfig,
        .UserID = UserIDtoConfig,
        .Position = 0
        }

        GroupToConfig.MembershipEntryCollection.Add(GroupMapping)
        GroupToConfig.Update(True)

 

    End Sub

 

now I want to remove A User and have created a nearly same Sub - only the second last line is changed to

 

GroupToConfig.MembershipEntryCollection.Remove(GroupMapping)

 

nothing happening

 

when I Use .RemoveAll() All Members deleted from group - but i cant remove a single User

 

Any Idea what im doing wrong??

Im no developer an coding j4f like 30 years ago on c128d - thats why i do vb 😀 - no trace implementet yet

 

Link to comment
Share on other sites


This works

 

  Public Shared Sub RemoveUserFromGroup(Group As String, User As String)

 

        Dim GroupToConfig As SWConfigDataClientLib.Proxies.Groups.GroupEntry
        Dim UserToConfig As SWConfigDataClientLib.Proxies.Users.UserEntry

        GroupToConfig = libManager.GetGroupEnum.AddUserToEnumByName(Group)
        UserToConfig = libManager.GetUserEnum.AddUserToEnumByName(User)


        Dim UserIDtoConfig As Int32 = UserToConfig.UserID
        Dim GroupIDtoConfig As Int32 = GroupToConfig.GroupID

        Dim GroupList As SWConfigDataClientLib.Proxies.Groups.MembershipEntryCollection

        GroupList = GroupToConfig.MembershipEntryCollection
      

        Dim i As Integer = -1

 

        For Each groupentry In GroupList
           
i += 1
            If groupentry.ToString = UserIDtoConfig.ToString & GroupIDtoConfig.ToString Then
                Exit For
            End If
        Next

       

        GroupToConfig.MembershipEntryCollection.RemoveAt(i)
        GroupToConfig.Update(True)

 

    End Sub

Link to comment
Share on other sites


  • 1 year later...

Hi Andreas,

 

may I'm totally wrong here, but I need to ask. 

My target is to generate a menu for internal users to add themselves or remove from a group. 

 

There for I'm using your code in the gse start block.

As soon as I'm adding them there the complete rule is not working anymore.

 

Any Idea what I'm doing wrong??

Link to comment
Share on other sites


Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share


×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and have taken note of our Privacy Policy.
We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.