@click.command('<STR_LIT:user>', short_help='<STR_LIT>')<EOL>@click.option('<STR_LIT>', '<STR_LIT>',<EOL>help="<STR_LIT>",<EOL>required=True<EOL>)<EOL>@click.option('<STR_LIT>', '<STR_LIT>',<EOL>type=click.Choice(['<STR_LIT>', '<STR_LIT>']),<EOL>help="<STR_LIT>",<EOL>)<EOL>@click.option('<STR_LIT>',<EOL>is_flag=True,<EOL>help="<STR_LIT>",<EOL>)<EOL>@click.option('<STR_LIT>', '<STR_LIT>',<EOL>multiple=True,<EOL>help="<STR_LIT>",<EOL>)<EOL>@click.option('<STR_LIT>',<EOL>multiple=True,<EOL>help="<STR_LIT>",<EOL>)<EOL>@click.pass_context<EOL>def user(context, user_id, update_role, add_institute, remove_admin, remove_institute):
adapter = context.obj['<STR_LIT>']<EOL>user_obj = adapter.user(user_id)<EOL>if not user_obj:<EOL><INDENT>LOG.warning("<STR_LIT>", user_id)<EOL>context.abort()<EOL><DEDENT>existing_roles = set(user_obj.get('<STR_LIT>',[]))<EOL>if update_role:<EOL><INDENT>if not update_role in user_obj['<STR_LIT>']:<EOL><INDENT>existing_roles = set(user_obj['<STR_LIT>'])<EOL>existing_roles.add(update_role)<EOL>LOG.info("<STR_LIT>", update_role)<EOL><DEDENT>else:<EOL><INDENT>LOG.warning("<STR_LIT>", update_role)<EOL><DEDENT><DEDENT>if remove_admin:<EOL><INDENT>try:<EOL><INDENT>existing_roles.remove('<STR_LIT>')<EOL>LOG.info("<STR_LIT>", user_id)<EOL><DEDENT>except KeyError as err:<EOL><INDENT>LOG.info("<STR_LIT>", user_id)<EOL><DEDENT><DEDENT>user_obj['<STR_LIT>'] = list(existing_roles)<EOL>existing_institutes = set(user_obj.get('<STR_LIT>',[]))<EOL>for institute_id in add_institute:<EOL><INDENT>institute_obj = adapter.institute(institute_id)<EOL>if not institute_obj:<EOL><INDENT>LOG.warning("<STR_LIT>", institute_id)<EOL><DEDENT>else:<EOL><INDENT>existing_institutes.add(institute_id)<EOL>LOG.info("<STR_LIT>", institute_id)<EOL><DEDENT><DEDENT>for institute_id in remove_institute:<EOL><INDENT>try:<EOL><INDENT>existing_institutes.remove(institute_id)<EOL>LOG.info("<STR_LIT>", institute_id)<EOL><DEDENT>except KeyError as err:<EOL><INDENT>LOG.info("<STR_LIT>", institute_id)<EOL><DEDENT><DEDENT>user_obj['<STR_LIT>'] = list(existing_institutes)<EOL>updated_user = adapter.update_user(user_obj)<EOL>
Update a user in the database