How to remove all the User roles except Inactive role for Genilogix Template projects?

Posted: January 21, 2014 in Uncategorized

' Scripted by - Srihari Vanumu
' Application - Application LifeCycle Management 11
' Version - 1.0
' Business Flows provided - Yes
' Creation date : 13-Jan-2014
' Script flow--->
' 1) Connect to a project of the ALM application
' 2) Get Access to Customization
' 3) Retrieve all the Users under this project
' 4) Iterate through all the Users and perform the below operation based on a business condition
' 5) Business Condition: If Inactive role is not present for current user ; assign it!!
' Remove all the existing roles except TDAdmin.
' 6) Commit the changes performed to database and application.
' 7) Write the Progress status to Log File for Verfication Purpose.
Imports TDAPIOLELib

Module Module1
Sub Main()
Dim tdc
Dim custom As Customization
Dim users As CustomizationUsers
Dim eachuser As CustomizationUser
Dim GetAllCustomUsers As List
Dim GetAllGroupList As List
Dim fso, f
Dim com As TDAPIOLELib.Command
Dim RecSet As TDAPIOLELib.Recordset
Dim i As Integer
i = 1
Dim Count As Integer
fso = CreateObject("Scripting.FileSystemObject")
f = fso.OpenTextFile("C:\TEMP\Status_Log_File.txt", 2, True)
tdc = CreateObject("TDApiOle80.TDConnection")
tdc.InitConnectionEx("http://almdev/qcbin/")
'Note: For Quality Center, connect by using the URL below:
'td.InitConnectionEx "http://:port/qcbin"
tdc.ConnectProjectEx("DEFAULT", "M2_Users", "svanumu", "Password")
' Setting and executing the SQL
com = tdc.Command
com.CommandText = "select count(*) from users"
RecSet = com.Execute
' Displaying the 2nd column data
For Count = 1 To RecSet.RecordCount
Console.WriteLine("Total Count of Users in this Project::::::" + RecSet.FieldValue(0))
f.WriteLine("Total Count of Users in this Project::::::" + RecSet.FieldValue(0))
RecSet.Next()
Next
custom = tdc.Customization
users = custom.Users
GetAllCustomUsers = users.Users()
f.WriteLine("Task Started !!!! Below are the Operations to be Performed !!!!")
f.WriteLine("1) Connect to a project of the ALM application")
f.WriteLine("2) Get Access to Customization")
f.WriteLine("3) Retrieve all the Users under this project")
f.WriteLine("4) Iterate through all the Users and perform the below operation based on a business condition")
f.WriteLine("4.1) Business Condition: If Inactive role is not present for current user ; assign it!!")
f.WriteLine("4.2) Remove all the existing roles except TDAdmin.")
f.WriteLine("5) Commit the changes performed to database and application.")
f.WriteLine("6) Write the Progress status to Log File for Verfication Purpose. ")
Console.WriteLine("******************************PROGRAM EXECUTION STARTED************************************************************")
f.WriteLine("******************************PROGRAM EXECUTION STARTED************************************************************")
For Each eachuser In GetAllCustomUsers

'************************************************************************************************************************
' If eachuser.Name = "ragupta" Then

' Above Line If should be removed in case if you want to run this program for all the users
' Console.WriteLine("Adding View Only role to matre and removing all the other roles")
' Above Line Exit For should be removed in case if you want to run this program for all the users

Console.WriteLine("PROCESS FOR::::" + eachuser.Name.ToString + ":::::User::" + i.ToString + ":::::STARTED")
f.WriteLine("PROCESS FOR::::" + eachuser.Name.ToString + ":::::User::" + i.ToString + ":::::STARTED")
If eachuser.Name = "_system_user_" Then
Continue For
Console.WriteLine(eachuser.Name.ToString + "|" + "Skipped")
f.WriteLine(eachuser.Name.ToString + "|" + "Skipped")
End If
If eachuser.Name = "admin" Then
Continue For
Console.WriteLine(eachuser.Name.ToString + "|" + "Skipped")
f.WriteLine(eachuser.Name.ToString + "|" + "Skipped")
End If
If eachuser.Name = "svc-qcaccess" Then
Continue For
Console.WriteLine(eachuser.Name.ToString + "|" + "Skipped")
f.WriteLine(eachuser.Name.ToString + "|" + "Skipped")
End If
Console.WriteLine(eachuser.Name.ToString + "|" + "Activity Started")
f.WriteLine(eachuser.Name.ToString + "|" + "Activity Started")

'***********************IF USER DOESNOT HAVE VIEW ONLY ROLE ASSIGN THAT ROLE*********************************************
If eachuser.InGroup("Inactive") = False Then
eachuser.AddToGroup("Inactive")
Console.WriteLine(eachuser.Name.ToString + "|" + "Inactive" + "|" + "Added")
f.WriteLine(eachuser.Name.ToString + "|" + "Inactive" + "|" + "Added")
End If

If eachuser.InGroup("View Only") = True Then
eachuser.RemoveFromGroup("View Only")
Console.WriteLine(eachuser.Name.ToString + "|" + "View Only" + "|" + "Removed")
f.WriteLine(eachuser.Name.ToString + "|" + "View Only" + "|" + "Removed")
End If

If eachuser.InGroup("Business Owner") = True Then
eachuser.RemoveFromGroup("Business Owner")
Console.WriteLine(eachuser.Name.ToString + "|" + "Business Owner" + "|" + "Removed")
f.WriteLine(eachuser.Name.ToString + "|" + "Business Owner" + "|" + "Removed")
End If
If eachuser.InGroup("Business Reviewer") Then
eachuser.RemoveFromGroup("Business Reviewer")
Console.WriteLine(eachuser.Name.ToString + "|" + "Business Reviewer" + "|" + "Removed")
f.WriteLine(eachuser.Name.ToString + "|" + "Business Reviewer" + "|" + "Removed")
End If
If eachuser.InGroup("Defect Resolver") Then
eachuser.RemoveFromGroup("Defect Resolver")
Console.WriteLine(eachuser.Name.ToString + "|" + "Defect Resolver" + "|" + "Removed")
f.WriteLine(eachuser.Name.ToString + "|" + "Defect Resolver" + "|" + "Removed")
End If
If eachuser.InGroup("Developer") Then
eachuser.RemoveFromGroup("Developer")
Console.WriteLine(eachuser.Name.ToString + "|" + "Developer" + "|" + "Removed")
f.WriteLine(eachuser.Name.ToString + "|" + "Developer" + "|" + "Removed")
End If
If eachuser.InGroup("eApprove Administrator") Then
eachuser.RemoveFromGroup("eApprove Administrator")
Console.WriteLine(eachuser.Name.ToString + "|" + "eApprove Administrator" + "|" + "Removed")
f.WriteLine(eachuser.Name.ToString + "|" + "eApprove Administrator" + "|" + "Removed")
End If
If eachuser.InGroup("Lead Test Manager") Then
eachuser.RemoveFromGroup("Lead Test Manager")
Console.WriteLine(eachuser.Name.ToString + "|" + "Lead Test Manager" + "|" + "Removed")
f.WriteLine(eachuser.Name.ToString + "|" + "Lead Test Manager" + "|" + "Removed")
End If
If eachuser.InGroup("Project Manager") Then
eachuser.RemoveFromGroup("Project Manager")
Console.WriteLine(eachuser.Name.ToString + "|" + "Project Manager" + "|" + "Removed")
f.WriteLine(eachuser.Name.ToString + "|" + "Project Manager" + "|" + "Removed")
End If
If eachuser.InGroup("QATester") Then
eachuser.RemoveFromGroup("QATester")
Console.WriteLine(eachuser.Name.ToString + "|" + "QATester" + "|" + "Removed")
f.WriteLine(eachuser.Name.ToString + "|" + "QATester" + "|" + "Removed")
End If
If eachuser.InGroup("Quality") Then
eachuser.RemoveFromGroup("Quality")
Console.WriteLine(eachuser.Name.ToString + "|" + "Quality" + "|" + "Removed")
f.WriteLine(eachuser.Name.ToString + "|" + "Quality" + "|" + "Removed")
End If
If eachuser.InGroup("Technical Reviewer") Then
eachuser.RemoveFromGroup("Technical Reviewer")
Console.WriteLine(eachuser.Name.ToString + "|" + "Technical Reviewer" + "|" + "Removed")
f.WriteLine(eachuser.Name.ToString + "|" + "Technical Reviewer" + "|" + "Removed")
End If
If eachuser.InGroup("Test Analyst") Then
eachuser.RemoveFromGroup("Test Analyst")
Console.WriteLine(eachuser.Name.ToString + "|" + "Test Analyst" + "|" + "Removed")
f.WriteLine(eachuser.Name.ToString + "|" + "Test Analyst" + "|" + "Removed")
End If
If eachuser.InGroup("Test Automation") Then
eachuser.RemoveFromGroup("Test Automation")
Console.WriteLine(eachuser.Name.ToString + "|" + "Test Automation" + "|" + "Removed")
f.WriteLine(eachuser.Name.ToString + "|" + "Test Automation" + "|" + "Removed")
End If
If eachuser.InGroup("Test Manager") Then
eachuser.RemoveFromGroup("Test Manager")
Console.WriteLine(eachuser.Name.ToString + "|" + "Test Manager" + "|" + "Removed")
f.WriteLine(eachuser.Name.ToString + "|" + "Test Manager" + "|" + "Removed")
End If
If eachuser.InGroup("Tester") Then
eachuser.RemoveFromGroup("Tester")
Console.WriteLine(eachuser.Name.ToString + "|" + "Tester" + "|" + "Removed")
f.WriteLine(eachuser.Name.ToString + "|" + "Tester" + "|" + "Removed")
End If
If eachuser.InGroup("Viewer") Then
eachuser.RemoveFromGroup("Viewer")
Console.WriteLine(eachuser.Name.ToString + "|" + "Viewer" + "|" + "Removed")
f.WriteLine(eachuser.Name.ToString + "|" + "Viewer" + "|" + "Removed")
End If
If eachuser.InGroup("Requirement Author") Then
eachuser.RemoveFromGroup("Requirement Author")
Console.WriteLine(eachuser.Name.ToString + "|" + "Requirement Author" + "|" + "Removed")
f.WriteLine(eachuser.Name.ToString + "|" + "Requirement Author" + "|" + "Removed")
End If
' custom.Commit()
Console.WriteLine(eachuser.Name.ToString + "|" + "Changes Commited")
f.WriteLine(eachuser.Name.ToString + "|" + "Changes Commited")

Console.WriteLine(eachuser.Name.ToString + "|" + "Activity Ended")
f.WriteLine(eachuser.Name.ToString + "|" + "Activity Ended")

Console.WriteLine("PROCESS FOR::::" + eachuser.Name.ToString + ":::::User::" + i.ToString + ":::::ENDED")
f.WriteLine("PROCESS FOR::::" + eachuser.Name.ToString + ":::::User::" + i.ToString + ":::::ENDED")

i = i + 1

' Exit For
' Above Line Exit For should be removed in case if you want to run this program for all the users
' End If
' Above Line End If should be removed in case if you want to run this program for all the users
'************************************************************************************************************************
Next
custom.Commit()
Console.WriteLine("Changes Commited for All Users")
f.WriteLine("Changes Commited for All Users")
Console.WriteLine("******************************PROGRAM EXECUTION COMPLETED************************************************************")
f.WriteLine("******************************PROGRAM EXECUTION COMPLETED************************************************************")
f.Close()
fso = Nothing
f = Nothing
custom = Nothing
users = Nothing
eachuser = Nothing
GetAllCustomUsers = Nothing
GetAllGroupList = Nothing
tdc = Nothing
Console.ReadLine()
End Sub
End Module

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s