Add the email confirmation option to gitlab_users (#25134)

`confirm` is an optional parameter ìn gitlab API[1].
It indicates whether the email of the user has to be confirmed.

[1]: https://docs.gitlab.com/ce/api/users.html#user-creation
This commit is contained in:
Matthieu Simonin 2017-06-05 21:47:52 +02:00 committed by René Moser
parent e8e73e0edd
commit 8432ba80c1

View file

@ -109,6 +109,12 @@ options:
required: false
default: present
choices: ["present", "absent"]
confirm:
description:
- Require confirmation.
required: false
default: true
version_added: "2.4"
'''
EXAMPLES = '''
@ -167,7 +173,7 @@ class GitLabUser(object):
level = 50
return self._gitlab.addgroupmember(group_id, user_id, level)
def createOrUpdateUser(self, user_name, user_username, user_password, user_email, user_sshkey_name, user_sshkey_file, group_name, access_level):
def createOrUpdateUser(self, user_name, user_username, user_password, user_email, user_sshkey_name, user_sshkey_file, group_name, access_level, confirm):
group_id = ''
arguments = {"name": user_name,
"username": user_username,
@ -182,16 +188,16 @@ class GitLabUser(object):
else:
if self._module.check_mode:
self._module.exit_json(changed=True)
self.createUser(group_id, user_password, user_sshkey_name, user_sshkey_file, access_level, arguments)
self.createUser(group_id, user_password, user_sshkey_name, user_sshkey_file, access_level, confirm, arguments)
def createUser(self, group_id, user_password, user_sshkey_name, user_sshkey_file, access_level, arguments):
def createUser(self, group_id, user_password, user_sshkey_name, user_sshkey_file, access_level, confirm, arguments):
user_changed = False
# Create the user
user_username = arguments['username']
user_name = arguments['name']
user_email = arguments['email']
if self._gitlab.createuser(password=user_password, **arguments):
if self._gitlab.createuser(password=user_password, confirm=confirm, **arguments):
user_id = self.getUserId(user_username)
if self._gitlab.addsshkeyuser(user_id=user_id, title=user_sshkey_name, key=user_sshkey_file):
user_changed = True
@ -284,6 +290,7 @@ def main():
group=dict(required=False),
access_level=dict(required=False, choices=["guest", "reporter", "developer", "master", "owner"]),
state=dict(default="present", choices=["present", "absent"]),
confirm=dict(required=False, default=True, type='bool')
),
supports_check_mode=True
)
@ -305,6 +312,7 @@ def main():
group_name = module.params['group']
access_level = module.params['access_level']
state = module.params['state']
confirm = module.params['confirm']
# We need both login_user and login_password or login_token, otherwise we fail.
if login_user is not None and login_password is not None:
@ -359,7 +367,7 @@ def main():
if state == "absent":
user.deleteUser(user_username)
else:
user.createOrUpdateUser(user_name, user_username, user_password, user_email, user_sshkey_name, user_sshkey_file, group_name, access_level)
user.createOrUpdateUser(user_name, user_username, user_password, user_email, user_sshkey_name, user_sshkey_file, group_name, access_level, confirm)