diff --git a/README.md b/README.md index 68f6a5e..8a757d4 100644 --- a/README.md +++ b/README.md @@ -177,6 +177,8 @@ optional arguments: usage: yimportgroups [-h] [-y {1.7,1.8,1.9}] -i INTERNAL_DOMAINS [--offline-check | --online-check] [--allow-update] [--delete] [--verbose] [--no-validate-domains] + [--creator-user CREATOR_USER] + [--creator-zone CREATOR_ZONE] csvfile Creates a list of groups based on a CSV file @@ -197,6 +199,10 @@ optional arguments: --verbose, -v Show information as extracted from CSV file --no-validate-domains, -n Do not validate email address domains + --creator-user CREATOR_USER + User who creates user + --creator-zone CREATOR_ZONE + Zone of the user who creates user The CSV file is expected to include the following labels in its header (the first row): 'category' = category for the group diff --git a/yclienttools/common_rules.py b/yclienttools/common_rules.py index 90719ea..92876e6 100644 --- a/yclienttools/common_rules.py +++ b/yclienttools/common_rules.py @@ -100,6 +100,22 @@ def call_uuGroupGetMemberType(self, groupname, user): ( 'user', user) ]) return self.call_rule('uuGroupGetMemberType', parms, 1)[0] + def call_uuGroupUserAddByOtherCreator(self, groupname, username, creator_user, creator_zone): + """Adds user to group on the behalf of a creator user. + + :param: groupname + :param: username + :param: creator_user + :param: creator_zone + :returns: (status, message) ; status !=0 is error + """ + parms = OrderedDict([ + ('groupname', groupname), + ('username', username), + ('creatorUser', creator_user), + ('creatorZone', creator_zone)]) + return self.call_rule('uuGroupUserAdd', parms, 2) + def call_uuGroupUserAdd(self, groupname, username): """Adds user to group. @@ -176,9 +192,11 @@ def call_uuGroupAdd(self, groupname, category, ('category', category), ('subcategory', subcategory), ('schema_id', 'default-2'), - ('expirationdate', ''), + ('expiration_date', ''), ('description', description), - ('classification', classification)]) + ('dataClassification', classification), + ('co_identifier', '') + ]) return self.call_rule('uuGroupAdd', parms, 2) diff --git a/yclienttools/importgroups.py b/yclienttools/importgroups.py index 172f3d7..8a875ce 100644 --- a/yclienttools/importgroups.py +++ b/yclienttools/importgroups.py @@ -184,8 +184,9 @@ def validate_data(rule_interface, args, data): for user in managers + members + viewers: if not is_internal_user(user, args.internal_domains.split(",")): # ensure that external users already have an iRODS account - # we do not want to be the actor that creates them - if not rule_interface.call_uuUserExists(user): + # we do not want to be the actor that creates them (unless + # we are creating them in the name of a creator user) + if not rule_interface.call_uuUserExists(user)and not args.creator_user: errors.append( 'Group {} has nonexisting external user {}'.format(groupname, user)) @@ -222,7 +223,10 @@ def apply_data(rule_interface, args, data): currentrole = rule_interface.call_uuGroupGetMemberType(groupname, username) if currentrole == "none": - [status, msg] = rule_interface.call_uuGroupUserAdd(groupname, username) + if args.creator_user: + [status, msg] = rule_interface.call_uuGroupUserAddByOtherCreator(groupname, username, args.creator_user, args.creator_zone) + else: + [status, msg] = rule_interface.call_uuGroupUserAdd(groupname, username) if status == '0': currentrole = "member" @@ -333,6 +337,9 @@ def entry(): if args.delete and not args.allow_update: _exit_with_error("Using the --delete option without the --allow-update option is not supported.") + if (args.creator_user and not args.creator_zone) or (not args.creator_user and args.creator_zone): + _exit_with_error("Using the --creator-user option without the --creator-zone option is not supported.") + if args.offline_check: sys.exit(0) @@ -379,6 +386,10 @@ def _get_args(): help='Show information as extracted from CSV file') parser.add_argument('--no-validate-domains', '-n', action='store_true', help='Do not validate email address domains') + parser.add_argument('--creator-user', type=str, + help='User who creates user') + parser.add_argument('--creator-zone', type=str, + help='Zone of the user who creates user') return parser.parse_args()