Пример #1
0
 def mutate(self, info, name, groups=None, role=None):
     _groups = []
     if groups is not None:
         existing_groups = [g.name for g in Group.get_query(info).all()]
         for g in groups:
             assert g in existing_groups, f'Group {g} does not exist. ' \
                                          f'Existing groups: {existing_groups}'
             _groups.append(
                 Group.get_query(info).filter(
                     models.Group.name == g).first())
     user = models.User(name=name, role=role, groups=_groups)
     db_session.add(user)
     db_session.commit()
     return CreateUser(user=user, ok=True)
Пример #2
0
def post_sms(to_num, from_num, content_type, text, images):
    sms = SMS.get(to_num)
    for group in Group.query(sms.group_id):
        type, device_id = group.dest.split(':')
        if type == 'device':
            post_sms_to_device(device_id, to_num, from_num,
                                content_type, text, images)
Пример #3
0
 def save(self, group_data: GroupData, attribute_data: AttributeData):
     group_exists = self._db_session.query(exists().where(Group.vk_id == group_data.group_id)).scalar()
     if not group_exists:
         group = Group(vk_id=group_data.group_id, name=group_data.group_name, url=group_data.group_url)
         self._db_session.add(group)
     else:
         group = self._db_session.query(Group).filter(Group.vk_id == group_data.group_id).first()
     self._db_session.add(GroupAttribute(attribute_data.attribute_name, attribute_data.attribute_val, group))
     self._db_session.commit()
Пример #4
0
    def test__should_save_group_data_when_already_exists(self):
        self.given_exists(Group(123, 'name', 'url'))

        group_data: GroupRepository.GroupData = GroupRepository.GroupData(123, 'url', 'name')
        user_count_data: GroupRepository.AttributeData = GroupRepository.AttributeData('user_count', 199)

        repo: GroupRepository = GroupRepository(self.session)
        repo.save(group_data, user_count_data)

        group_obj: Group = self.session.query(Group).filter(Group.vk_id == group_data.group_id).first()
        self._checkGroupValidity(group_data, user_count_data, group_obj)
Пример #5
0
def post_sms(to_num, from_num, content_type, text, images):
    to_names = []
    sms = SMS.get(to_num)
    group = Group.get(sms.group_id)
    person = SMSToPerson.get(from_num)

    for dest in Dest.query(sms.group_id):
        type, device_id = dest.dest.split(':')
        if type == 'device':
            to_name = post_sms_to_device(device_id, group.name, person.name,
                                         content_type, text, images)
            to_names.append(to_name)
    if len(to_names) > 10:
        return 'Sent to %d people' % len(to_names)
    return 'Sent to %s.' % ' '.join(to_names)
Пример #6
0
def add_device(num, name):
    id = str(uuid.uuid4())
    SMS(num, group_id=id).save()
    Group(id, name=name).save()
    Dest(id, 'device:' + id).save()
Пример #7
0
 def mutate(self, info, name):
     group = Group.get_query(info).filter(models.Group.name == name).first()
     db_session.delete(group)
     db_session.commit()
     return DeleteGroup(ok=True)
Пример #8
0
 def mutate(self, info, name, new_name):
     group = Group.get_query(info).filter(models.Group.name == name).first()
     group.name = new_name
     db_session.add(group)
     db_session.commit()
     return UpdateGroup(group=group, ok=True)