示例#1
0
文件: receipt.py 项目: lyoung83/chat
 def new(cls, user_id: str, message_id: str):
     if not isinstance(user_id, str):
         raise ValueError('user_id is not str')
     if not isinstance(message_id, str):
         raise ValueError('message_id is not str')
     return cls(RecordID(cls.record_type,
                         Receipt.consistent_id(user_id, message_id)),
                user_id,
                None,
                data={
                    'user': Reference(RecordID('user', user_id)),
                    'message': Reference(RecordID('message', message_id))
                })
示例#2
0
文件: receipt.py 项目: rickmak/chat
 def __init__(self, user_id: str, message_id: str):
     if not isinstance(user_id, str):
         raise ValueError('user_id is not str')
     if not isinstance(message_id, str):
         raise ValueError('message_id is not str')
     self.record = Record(
         RecordID('receipt', Receipt.consistent_id(user_id, message_id)),
         user_id,
         None,
         data={
             'user_id': Reference(RecordID('user', user_id)),
             'message_id': Reference(RecordID('message', message_id))
         }
     )
示例#3
0
 def new(cls, conversation, user_id):
     record = cls(None, user_id, conversation.get_user_conversation_acl())
     record['user'] = Reference(RecordID('user', user_id))
     record['conversation'] = Reference(conversation.id)
     record['unread_count'] = 0
     record['is_admin'] = False
     return record
示例#4
0
def hello():
    """
    This lamda returns some skydb types to the caller. This demonstrates
    the lambda can return skydb types.

    ```
    curl -X "POST" "http://localhost:3000" \
         -H 'Content-Type: application/json; charset=utf-8' \
         -d $'{
      "api_key": "secret",
      "action": "hello"
    }'
    ```
    """
    return [
        1,
        2,
        True,
        "hello",
        Location(1, 2),
        Record(
            id=RecordID("note", "99D92DBA-74D5-477F-B35E-F735E21B2DD5"),
            owner_id="OWNER_ID",
            acl=None,
            data={
                "content": "Hello World!",
            }
        ),
        {
            'location': Location(1, 2)
        }
    ]
示例#5
0
 def test_reference(self):
     value = {
         "$type": "ref",
         "$id": "note/c1d0e8d4-648c-4c88-86c6-22feb1a6e734"
     }
     assert deserialize_value(value) == \
         Reference(RecordID("note", "c1d0e8d4-648c-4c88-86c6-22feb1a6e734"))
示例#6
0
 def new(cls, conversation_id, user_id):
     return Conversation(RecordID(cls.record_type, conversation_id),
                         user_id,
                         [RoleAccessControlEntry(
                          cls.get_admin_role(conversation_id),
                          ACCESS_CONTROL_ENTRY_LEVEL_WRITE),
                          RoleAccessControlEntry(
                          cls.get_participant_role(conversation_id),
                          ACCESS_CONTROL_ENTRY_LEVEL_READ)])
示例#7
0
 def __init__(self, message):
     super().__init__(RecordID(self.record_type, str(uuid.uuid4())),
                      current_user_id(), message.acl)
     for key in [
             'attachment', 'body', 'metadata', 'conversation',
             'message_status', 'edited_by', 'edited_at'
     ]:
         if key in message:
             self[key] = message.get(key, None)
     self['parent'] = Reference(message.id)
示例#8
0
    def test_forgot_password_email(email,
                                   text_template=None,
                                   html_template=None,
                                   subject=None,
                                   sender=None,
                                   reply_to=None,
                                   sender_name=None,
                                   reply_to_name=None):
        access_key_type = current_context().get('access_key_type')
        if not access_key_type or access_key_type != 'master':
            raise SkygearException('master key is required',
                                   skyerror.AccessKeyNotAccepted)

        url_prefix = settings.url_prefix
        if url_prefix.endswith('/'):
            url_prefix = url_prefix[:-1]

        dummy_user = namedtuple('User',
                                ['id', 'email'])('dummy-id',
                                                 '*****@*****.**')

        dummy_record_id = RecordID('user', 'dummy-id')
        dummy_record = Record(dummy_record_id, dummy_record_id.key, None)

        template_params = {
            'appname': settings.app_name,
            'code': 'dummy-reset-code',
            'url_prefix': url_prefix,
            'link': '{}/example-reset-password-link'.format(url_prefix),
            'user_record': dummy_record,
            'user': dummy_user,
            'email': dummy_user.email,
            'user_id': dummy_user.id
        }

        email_sender = (sender_name, sender) if sender \
            else (settings.sender_name, settings.sender)
        email_subject = subject if subject else settings.subject
        email_reply_to = (reply_to_name, reply_to) if reply_to \
            else (settings.reply_to_name, settings.reply_to)

        try:
            mail_sender.send(email_sender,
                             email,
                             email_subject,
                             reply_to=email_reply_to,
                             text_template_string=text_template,
                             html_template_string=html_template,
                             template_params=template_params)
        except Exception as ex:
            logger.exception('An error occurred sending test reset password'
                             ' email to user.')
            raise SkygearException(str(ex), skyerror.UnexpectedError)

        return {'status': 'OK'}
示例#9
0
 def test_record(self):
     value = Record(id=RecordID("note",
                                "99D92DBA-74D5-477F-B35E-F735E21B2DD5"),
                    owner_id="OWNER_ID",
                    acl=None,
                    data={
                        "content": "Hello World!",
                    })
     assert serialize_value(value) == \
         {
             "$type": "record",
             "$record": {
                 "_access": None,
                 "_id": "note/99D92DBA-74D5-477F-B35E-F735E21B2DD5",
                 "_ownerID": "OWNER_ID",
                 "content": "Hello World!",
             }
         }
示例#10
0
 def test_normal(self):
     r = Record(
         id=RecordID('note', '99D92DBA-74D5-477F-B35E-F735E21B2DD5'),
         owner_id='OWNER_ID',
         acl=None,
         data={
               "content": "Hello World!",
               "noteOrder": 1,
               "money": UnknownValue("money"),
               })
     rdata = serialize_record(r)
     assert rdata == {
         "_access": None,
         "_id": "note/99D92DBA-74D5-477F-B35E-F735E21B2DD5",
         "_ownerID": "OWNER_ID",
         "content": "Hello World!",
         "noteOrder": 1,
         "money": {'$type': 'unknown', '$underlying_type': 'money'},
     }
示例#11
0
 def id(self):
     return RecordID(self.record_type, self.get_hash())