Пример #1
0
    def authenticate(username, password, domain=None):
        try:
            #: TODO: Add support to domain
            userNode = CaliopeUser.index.get(username=username)
            if userNode.password == password:
                session_uuid = str(uuid4()).decode('utf-8')

                g.connection_thread_pool_id[
                    g.connection_thread_id] = session_uuid
                current_app.storekv.put(prefix_session_manager + session_uuid,
                                        username)
                PubSub().subscribe_uuid(userNode.uuid)
                PubSub().register_uuid_and_thread_id(userNode.uuid)
                PubSub().publish_command(userNode.uuid,
                                         userNode.uuid,
                                         'message', {
                                             'msg': 'Bienvenido',
                                             'type': 'success'
                                         },
                                         loopback=True)

                return {
                    'login':
                    True,
                    'session_uuid': {
                        'value': session_uuid
                    },
                    'user_uuid': {
                        'value': userNode.uuid
                    },
                    'user': {
                        'value': username
                    },
                    "first_name": {
                        'value': userNode.first_name
                    },
                    "last_name": {
                        'value': userNode.last_name
                    },
                    "image":
                    get_thumbnail(
                        os.path.join(current_app.config['STATIC_PATH'],
                                     userNode.avatar))
                }
            else:
                return {'login': False}
        except DoesNotExist:
            return {'login': False}
        except Exception as e:
            raise JSONRPCInternalError(e)
Пример #2
0
 def authenticate_with_uuid(session_uuid, domain=None):
     if session_uuid is not None:
         if current_app.storekv.__contains__(prefix_session_manager +
                                             session_uuid):
             try:
                 username = current_app.storekv.get(prefix_session_manager +
                                                    session_uuid)
                 g.connection_thread_pool_id[
                     g.connection_thread_id] = session_uuid
                 userNode = CaliopeUser.index.get(username=username)
                 PubSub().subscribe_uuid(userNode.uuid)
                 PubSub().register_uuid_and_thread_id(userNode.uuid)
                 PubSub().publish_command(userNode.uuid,
                                          userNode.uuid,
                                          'message', {
                                              'msg': 'Bienvenido',
                                              'type': 'success'
                                          },
                                          loopback=True)
                 return {
                     'login':
                     True,
                     'session_uuid': {
                         'value': session_uuid
                     },
                     'user_uuid': {
                         'value': userNode.uuid
                     },
                     'user': {
                         'value': username
                     },
                     "first_name": {
                         'value': userNode.first_name
                     },
                     "last_name": {
                         'value': userNode.last_name
                     },
                     "image":
                     get_thumbnail(
                         os.path.join(current_app.config['STATIC_PATH'],
                                      userNode.avatar))
                 }
             except Exception as e:
                 raise JSONRPCInternalError(e)
                 #: if not returned is not a  valid session
     return {'login': False}
Пример #3
0
    def commit(cls, uuid, loopback_notification=False):
        hkey_name = uuid
        hkey_name_rels = uuid + "_rels"
        #Create form if is associated to a form
        if cls.r.hexists(hkey_name, "formtask") and not cls.r.hexists(
                hkey_name_rels, "target"):
            from cid.core.forms.services import FormManager

            form_name = cls.r.hget(hkey_name, "formtask")
            form = FormManager.create_form_from_id(form_name, {})
            cls.update_relationship(uuid, "target", form["uuid"])

        #notify the other users of the change
        holders_to_add = []
        holders_to_remove = []
        if cls.r.hexists(hkey_name_rels, "holders"):
            holders_to_add = [
                h for h, v in json.loads(
                    cls.r.hget(hkey_name_rels, "holders"),
                    object_hook=DatetimeDecoder.json_date_parser).items()
                if "__changed__" in v
            ]
            holders_to_remove = [
                h for h, v in json.loads(
                    cls.r.hget(hkey_name_rels, "holders"),
                    object_hook=DatetimeDecoder.json_date_parser).items()
                if "__delete__" in v
            ]
        rv = super(TaskServices, cls).commit(uuid)
        for holder in holders_to_add:
            PubSub().publish_command("",
                                     holder,
                                     "createTask",
                                     VersionedNode.pull(uuid).serialize(),
                                     loopback=loopback_notification)
            PubSub().subscribe_uuid_with_user_uuid(holder, uuid)

        for holder in holders_to_remove:
            PubSub().publish_command("",
                                     holder,
                                     "removeTask",
                                     VersionedNode.pull(uuid).serialize(),
                                     loopback=loopback_notification)
        return rv
Пример #4
0
 def get_data(cls, uuid, entity_class=None):
     try:
         PubSub().subscribe_uuid(uuid)
         if entity_class is None:
             entity_class = VersionedNode.pull(uuid, only_class=True)
         vnode = entity_class.pull(uuid)
         if vnode is None:
             #get a vnode with the class and uuid
             vnode = cls._get_vnode_with_data(uuid, entity_class)
             #: Append related uuids to the list.
         for rel_name, rel_repr in vnode._serialize_relationships() \
             .items():
             for target_uuid in rel_repr.keys():
                 direction = getattr(vnode, rel_name).direction
                 cls._set_related(uuid, target_uuid, direction=direction)
         return cls._get_data_with_draft(vnode)
     except AssertionError:
         return RuntimeError("The give uuid {0} is not a valid object of "
                             "class {1}".format(uuid, cls.__name__))
Пример #5
0
    def commit(cls, uuid, loopback_notification=False):
        rv = dict()
        related = cls._get_related(uuid)

        if related > 0:
            for target_uuid in related.keys():
                #Avoid related locks if theres is a back-relationship:
                if cls._is_related(target_uuid, uuid):
                    continue
                    #: This is to save nodes when no data added but there are
                # in a relationships, we're saving "blank" connected nodes.
                if VersionedNode.pull(target_uuid) is None:
                    cls.update_field(target_uuid, "uuid", target_uuid)
                rv.update(cls.commit(target_uuid, loopback_notification))
        rv.update(super(FormManager, cls).commit(uuid, loopback_notification))

        PubSub().publish_command("", uuid, 'message',
                                 {'msg': 'Formulario actualizado.', 'type': 'success'}, loopback=True)
        return rv
Пример #6
0
 def _publish_update_field(cls,
                           uuid,
                           field_name,
                           value,
                           subfield_id=None,
                           pos=None,
                           delete=False,
                           metadata=None,
                           loopback_notification=False):
     rv = {
         'uuid': uuid,
         'field': field_name,
         'value': value,
         'subfield_id': subfield_id,
         'pos': pos,
         'delete': delete,
         'metadata': metadata
     }
     PubSub().publish_command('from_unused',
                              uuid,
                              'updateField',
                              rv,
                              loopback=loopback_notification)
Пример #7
0
 def unsubscribe_uuid(cls, uuid):
     PubSub().unsubscribe_uuid(uuid)
Пример #8
0
 def subscribe_uuid(cls, uuid):
     PubSub().subscribe_uuid(uuid)