labpack/databases/couchbase.py
def save_user(self, uid, user_password, user_email='', user_channels=None, user_roles=None, user_views=None, disable_account=False):

        '''
            a method to add or update an authorized user to the bucket
            
        :param uid: string with id to assign to user
        :param user_password: string with password to assign to user
        :param user_email: [optional] string with email of user for future lookup
        :param user_channels: [optional] list of strings with channels to subscribe to user
        :param user_roles: [optional] list of strings with roles to assign to user
        :param user_views: [optional] list of query criteria to create as views for user
        :param disable_account: boolean to disable access to records by user
        :return: integer with status code of user account creation
        '''

    # https://developer.couchbase.com/documentation/mobile/1.5/references/sync-gateway/admin-rest-api/index.html#/user/put__db___user__name_
    # https://developer.couchbase.com/documentation/mobile/1.5/guides/sync-gateway/authorizing-users/index.html
    
        title = '%s.save_user' % self.__class__.__name__
        
    # validate inputs
        input_fields = {
            'uid': uid,
            'user_password': user_password,
            'user_email': user_email,
            'user_channels': user_channels,
            'user_roles': user_roles
        }
        for key, value in input_fields.items():
            if value:
                object_title = '%s(%s=%s)' % (title, key, str(value))
                self.fields.validate(value, '.%s' % key, object_title)
    
    # construct url
        url = self.bucket_url + '/_user/%s' % uid

    # create default settings
        json_data = {
            'admin_channels': [ uid ],
            'admin_roles': [ uid ],
            'name': uid,
            'password': user_password,
            'disabled': disable_account
        }
    
    # add optional additional channels and roles
        if user_email:
            json_data['email'] = user_email
        if user_channels:
            json_data['admin_channels'].extend(user_channels)
        if user_roles:
            json_data['admin_roles'].extend(user_roles)

    # send request
        response = requests.put(url, json=json_data)

    # create indices
        if response.status_code in (200, 201) and not self.public:
            self.create_view(uid=uid)
            if user_views:
                for criteria in user_views:
                    self.create_view(query_criteria=criteria, uid=uid)

    # report outcome
        self.printer('User "%s" updated in bucket "%s"' % (uid, self.bucket_name))
        
        return response.status_code

            a method to add or update an authorized user to the bucket
            
        :param uid: string with id to assign to user
        :param user_password: string with password to assign to user
        :param user_email: [optional] string with email of user for future lookup
        :param user_channels: [optional] list of strings with channels to subscribe to user
        :param user_roles: [optional] list of strings with roles to assign to user
        :param user_views: [optional] list of query criteria to create as views for user
        :param disable_account: boolean to disable access to records by user
        :return: integer with status code of user account creation
        
a method to add or update an authorized user to the bucket
a method to add or update an authorized user to the bucket
def save_user(self, uid, user_password, user_email='', user_channels=None, user_roles=None, user_views=None, disable_account=False):
        title = '%s.save_user' % self.__class__.__name__
        input_fields = {
            'uid': uid,
            'user_password': user_password,
            'user_email': user_email,
            'user_channels': user_channels,
            'user_roles': user_roles
        }
        for key, value in input_fields.items():
            if value:
                object_title = '%s(%s=%s)' % (title, key, str(value))
                self.fields.validate(value, '.%s' % key, object_title)
        url = self.bucket_url + '/_user/%s' % uid
        json_data = {
            'admin_channels': [ uid ],
            'admin_roles': [ uid ],
            'name': uid,
            'password': user_password,
            'disabled': disable_account
        }
        if user_email:
            json_data['email'] = user_email
        if user_channels:
            json_data['admin_channels'].extend(user_channels)
        if user_roles:
            json_data['admin_roles'].extend(user_roles)
        response = requests.put(url, json=json_data)
        if response.status_code in (200, 201) and not self.public:
            self.create_view(uid=uid)
            if user_views:
                for criteria in user_views:
                    self.create_view(query_criteria=criteria, uid=uid)
        self.printer('User "%s" updated in bucket "%s"' % (uid, self.bucket_name))
        return response.status_code
def save_user ( self , uid , user_password , user_email = '' , user_channels = None , user_roles = None , user_views = None , disable_account = False ) : title = '%s.save_user' % self . __class__ . __name__ input_fields = { 'uid' : uid , 'user_password' : user_password , 'user_email' : user_email , 'user_channels' : user_channels , 'user_roles' : user_roles } for key , value in input_fields . items ( ) : if value : object_title = '%s(%s=%s)' % ( title , key , str ( value ) ) self . fields . validate ( value , '.%s' % key , object_title ) url = self . bucket_url + '/_user/%s' % uid json_data = { 'admin_channels' : [ uid ] , 'admin_roles' : [ uid ] , 'name' : uid , 'password' : user_password , 'disabled' : disable_account } if user_email : json_data [ 'email' ] = user_email if user_channels : json_data [ 'admin_channels' ] . extend ( user_channels ) if user_roles : json_data [ 'admin_roles' ] . extend ( user_roles ) response = requests . put ( url , json = json_data ) if response . status_code in ( 200 , 201 ) and not self . public : self . create_view ( uid = uid ) if user_views : for criteria in user_views : self . create_view ( query_criteria = criteria , uid = uid ) self . printer ( 'User "%s" updated in bucket "%s"' % ( uid , self . bucket_name ) ) return response . status_code
a method to add or update an authorized user to the bucket
a method to add or update an authorized user to the bucket
'''
            a method to add or update an authorized user to the bucket
            
        :param uid: string with id to assign to user
        :param user_password: string with password to assign to user
        :param user_email: [optional] string with email of user for future lookup
        :param user_channels: [optional] list of strings with channels to subscribe to user
        :param user_roles: [optional] list of strings with roles to assign to user
        :param user_views: [optional] list of query criteria to create as views for user
        :param disable_account: boolean to disable access to records by user
        :return: integer with status code of user account creation
        ''' # https://developer.couchbase.com/documentation/mobile/1.5/references/sync-gateway/admin-rest-api/index.html#/user/put__db___user__name_ # https://developer.couchbase.com/documentation/mobile/1.5/guides/sync-gateway/authorizing-users/index.html # validate inputs # construct url # create default settings # add optional additional channels and roles # send request # create indices # report outcome
integer with status code of user account creation
integer with status code of user account creation
self
uid
string with id to assign to user
string with id to assign to user
user_password
string with password to assign to user
string with password to assign to user
user_email
[optional] string with email of user for future lookup
[ optional ] string with email of user for future lookup
user_channels
[optional] list of strings with channels to subscribe to user
[ optional ] list of strings with channels to subscribe to user
user_roles
[optional] list of strings with roles to assign to user
[ optional ] list of strings with roles to assign to user
user_views
[optional] list of query criteria to create as views for user
[ optional ] list of query criteria to create as views for user
disable_account
boolean to disable access to records by user
boolean to disable access to records by user