<filename>ibmcnx/cnx/ProfilesAddExtRole.py
'''
Add extended role to a user

Author:        <NAME>
Mail:          <EMAIL>
Documentation: http://scripting101.stoeps.de

Version:       5.0.1
Date:          09/19/2015

License:       Apache 2.0
'''

import sys
import ConfigParser

global globdict
globdict = globals()


def getMailAddress():
    '''
    Ask for mail address to add role

    Returns
        mail - string
    '''
    mail = raw_input('Adding extended role to user (provide mailaddress): ')
    return mail


def main():
    mailAddress = getMailAddress()
    '''
    Idea would be to check if the user already has the role, but getRoles() do not return a value it only prints the actual value

    try:
        role = ProfilesService.getRoles(mailAddress)
    except:
        print 'User not found!'

    if role == '[employee]':
        try:
            ProfilesService.setRole(mailaddress)
        except:
            print "Error occured"
    elif role == '[employee.extended]':
        print 'User has alreay role: ' + role
    else:
        print 'User not found in peopleDB.'
    '''
    ProfilesService.setRole(mailAddress, EMPLOYEE_EXTENDED)

# Get configuration from properties file
configParser = ConfigParser.ConfigParser()
configFilePath = r'ibmcnx/ibmcnx.properties'
configParser.read(configFilePath)

try:
    # get admin id to check profiles commands
    connadmin = configParser.get('Generic', 'j2ee.cnxadmin').split('|')
except:
    print "Did you rename ibmcnx_sample.properties?"

try:
    # Check if Profiles Scripts are loaded
    temp = ProfilesService.getRolesByUserId(connadmin[0])
except:
    print "\tLoading Profiles Admin Commands:"
    execfile("profilesAdmin.py")

main()

<filename>ibmcnx/cnx/ProfilesAddExtRole.py
'''
Add extended role to a user

Author:        <NAME>
Mail:          <EMAIL>
Documentation: http://scripting101.stoeps.de

Version:       5.0.1
Date:          09/19/2015

License:       Apache 2.0
'''

import sys
import ConfigParser

global globdict
globdict = globals()


def getMailAddress():
    '''
    Ask for mail address to add role

    Returns
        mail - string
    '''
    mail = raw_input('Adding extended role to user (provide mailaddress): ')
    return mail


def main():
    mailAddress = getMailAddress()
    '''
    Idea would be to check if the user already has the role, but getRoles() do not return a value it only prints the actual value

    try:
        role = ProfilesService.getRoles(mailAddress)
    except:
        print 'User not found!'

    if role == '[employee]':
        try:
            ProfilesService.setRole(mailaddress)
        except:
            print "Error occured"
    elif role == '[employee.extended]':
        print 'User has alreay role: ' + role
    else:
        print 'User not found in peopleDB.'
    '''
    ProfilesService.setRole(mailAddress, EMPLOYEE_EXTENDED)

# Get configuration from properties file
configParser = ConfigParser.ConfigParser()
configFilePath = r'ibmcnx/ibmcnx.properties'
configParser.read(configFilePath)

try:
    # get admin id to check profiles commands
    connadmin = configParser.get('Generic', 'j2ee.cnxadmin').split('|')
except:
    print "Did you rename ibmcnx_sample.properties?"

try:
    # Check if Profiles Scripts are loaded
    temp = ProfilesService.getRolesByUserId(connadmin[0])
except:
    print "\tLoading Profiles Admin Commands:"
    execfile("profilesAdmin.py")

main()

Add extended role to a user  Author:        <NAME> Mail:          <EMAIL> Documentation: http://scripting101.stoeps.de  Version:       5.0.1 Date:          09/19/2015  License:       Apache 2.0 Ask for mail address to add role      Returns         mail - string Idea would be to check if the user already has the role, but getRoles() do not return a value it only prints the actual value      try:         role = ProfilesService.getRoles(mailAddress)     except:         print 'User not found!'      if role == '[employee]':         try:             ProfilesService.setRole(mailaddress)         except:             print "Error occured"     elif role == '[employee.extended]':         print 'User has alreay role: ' + role     else:         print 'User not found in peopleDB.' # Get configuration from properties file # get admin id to check profiles commands # Check if Profiles Scripts are loaded