Example #1
0
def create_group(group_id, users, **kwargs):
    # Check if group already exists
    if get_group(group_id) is not None:
        # group_id is already used or request failed
        return False

    # create group and add members
    group = Group(group_id)
    if group.members is None:
        group.members = []
    for user in users:
        group.members.append(user["username"])
        print(user["username"])
        created = create_user(user['username'],
                              user['password'],
                              remote_ip=user['pptpIP'],
                              group_id=group_id)
        if not created:
            print('Unable to create user ', user['username'])
            return False

    # from rocketchat_API.rocketchat import RocketChat
    # groupName = "group" + str(group_id)
    # chat_ip_port = "http://0.0.0.0:3000"
    # rocket = RocketChat('Admin', 'chat.service', server_url=chat_ip_port, proxies=None)
    # data = rocket.groups_create(groupName, members=group.members).json()
    # status = data["success"]
    # print("group status: ", status)

    # put data in the correct format
    doc = {'group_id': group_id, 'members': group.members, **kwargs}
    if 'note' not in kwargs:
        doc['note'] = ""
    if 'alias' not in kwargs:
        doc['alias'] = ""
    doc_data = {
        'collection_name': 'groups',
        'document_id': group_id,
        'document': doc
    }
    # store in the database
    r = requests.post(database_url, json=doc_data)
    if r.status_code != requests.codes.ok:
        return False
    return True
Example #2
0
def get_group(group_id):
    # put data in the correct format
    doc_data = {'collection_name': 'groups', 'document_id': group_id}
    # retrieve info from database
    r = requests.get(database_url, json=doc_data)
    if r.status_code == requests.codes.ok:
        group_js = r.json()
        return Group(**group_js)
    return None
Example #3
0
 def test_change_id(self):
     self.assertFalse(
         AccountManager.update_group(start_id, Group(**updated_group)))
Example #4
0
 def test_update_nonexistent(self):
     self.assertFalse(
         AccountManager.update_group(102, Group(**updated_group)))
Example #5
0
 def make_group(self, data):
     return Group(**data)