Exemple #1
0
 def on_put(self, req, resp, projId):
     targetProject = req.session.query(Project).filter(
         Project.id == int(projId)).first()
     form = get_params(req.stream, flat=False)
     if targetProject and form.get('number') and form.get('lead'):
         lead = req.session.query(User).filter(
             User.id == int(form.get('lead').get('id'))).first()
         repository = targetProject.repositories[0]
         seqCollection = req.session.query(Collection).filter_by(repository=repository)\
             .filter_by(name='Sequences').first()
         lenOfSeqs = len(targetProject.sequences)
         if lead and seqCollection:
             number = int(form.get('number'))
             if number > 0:  # now its ok to add sequences
                 for newSeq in xrange(number):
                     num = lenOfSeqs + 1
                     new = Sequence(number=num)
                     targetProject.sequences.append(new)
                     newC = Collection(name=new.code,
                                       path=new.code,
                                       repository=repository,
                                       parent=seqCollection,
                                       template='sequences')
                     new.collection = newC
                     lenOfSeqs += 1
                 ##
                 count = 1
                 for seq in targetProject.sequences:
                     seq.number = count
                     count += 1
                 resp.status = falcon.HTTP_202
                 resp.body = {'message': 'OK'}
         else:
             resp.body = {'message': 'ERROR'}
Exemple #2
0
    def on_post(self, req, resp, **kw):
        args = req.path.split('/')
        table = args[3].title()
        #u = getUserInfoFromSession(req)
        # if not isAuthorizedTo(u.get('id'), 'update_%s'%table):
        #    raise falcon.HTTPUnauthorized('Not Authorized', 'Permission Denied')
        if len(args) < 5:
            resp.status = falcon.HTTP_400
            return
        id = args[4]
        # lets get the table data
        query = 'req.session.query({t}).filter({t}.id=={id})'.format(
            t=table, id=int(id))
        result = eval(query).first()
        ##
        query_params = get_params(req.stream, flat=False)
        updated_values = []
        for key in query_params:
            if key in ['created_on', 'modified_on', 'id', 'uuid']:
                continue
            key = str(key)
            value = query_params[key]
            if isinstance(value,
                          (int, str, unicode, float)) and hasattr(result, key):
                try:
                    setattr(result, key, value)
                    updated_values.append(key)
                except (AttributeError, TypeError):
                    continue

        # if result.update(query_params):
        resp.body = {'message': 'updated', 'info': updated_values}
Exemple #3
0
 def on_put(self, req, resp, **kw):
     u = getUserInfoFromSession(req, resp)
     targetUser = User.query.filter_by(id=u.get('id')).first()
     data = get_params(req.stream, flat=False)
     if data and data.get('body'):
         targetUser.reports.append(data.get('body'))
         resp.status = falcon.HTTP_202
         resp.body = {'message': 'OK'}
Exemple #4
0
    def on_post(self, req, resp, userId):
        target = req.session.query(User).filter_by(id=int(userId)).first()
        data = get_params(req.stream, False)
        if data.get('expertise'):
            target.exps = []
            target.expertise = [i.get('name') for i in data.get('expertise')]

            resp.status = falcon.HTTP_202
            resp.body = {'message': 'OK'}
Exemple #5
0
 def on_post(self, req, resp, key):
     options = get_params(req.stream, False)
     folder = options.get('folder')
     message = options.get('message')
     user = getUserInfoFromSession(req, resp)
     mdb = getUserMessageBox(user.get('uuid'))
     mdb.delete(key)
     obj = mdb.new(key, message)
     obj.store()
     resp.body = {'message': 'updated'}
Exemple #6
0
    def on_put(self, req, resp):
        user = getUserInfoFromSession(req, resp)
        projectData = get_params(req.stream, flat=False)
        start, end, name, lead_id, description = None, None, None, None, None
        if projectData.get('start'):
            start = str(projectData.get('start'))
        if projectData.get('end'):
            end = str(projectData.get('end'))
        if projectData.get('name'):
            name = str(projectData.get('name'))
        if projectData.get('description'):
            description = str(projectData.get('description'))
        if projectData.get('lead_id'):
            lead_id = int(projectData.get('lead_id'))

        if start and end and name and lead_id:
            leader = User.query.filter_by(id=lead_id).first()
            creater = User.query.filter_by(id=user.get('id')).first()
            new = Project(start=start,
                          name=name,
                          end=end,
                          lead=leader,
                          creater=creater)
            if description:
                new.description = description
            repoName = name
            newRepoFolder = os.path.join(home, '.fearlessrepo', repoName)
            if not os.path.isdir(newRepoFolder):
                os.makedirs(newRepoFolder)
            new_repository = Repository.query.filter(
                Repository.name == repoName).first()
            if not new_repository:
                new_repository = Repository(name=repoName, path=newRepoFolder)
                #

            chars_section = Collection(name='Characters', path='chars')

            props_section = Collection(name='Props', path='props')
            sets_section = Collection(name='Sets', path='sets')
            sequences_section = Collection(name='Sequences', path='sequences')
            editorial_section = Collection(name='Editorial', path='editorial')
            resources_section = Collection(name='Resources', path='resources')

            new_repository.collections.append(chars_section)
            new_repository.collections.append(props_section)
            new_repository.collections.append(sets_section)
            new_repository.collections.append(sequences_section)
            new_repository.collections.append(editorial_section)
            new_repository.collections.append(resources_section)

            new.repositories.append(new_repository)
            req.session.add(new)
            resp.status = falcon.HTTP_201
            req.session.flush()
            resp.body = {'message': 'OK'}
Exemple #7
0
    def on_post(self, req, resp, taskId):
        user = getUserInfoFromSession(req, resp)
        uid = int(user.get('id'))

        reviewData = get_params(req.stream, flat=False)
        rew = reviewData.get('review')
        if rew:
            r = Review(content=rew, reviewer_id=uid, task_id=taskId)
            req.session.add(r)
            resp.status = falcon.HTTP_201
        else:
            resp.status = falcon.HTTP_204
Exemple #8
0
    def on_post(self, req, resp, taskId):
        user = getUserInfoFromSession(req, resp)
        resources, depends, responsibles, effort, alternative_resources = list(
        ), list(), list(), 0, list()
        taskData = get_params(req.stream, flat=False)
        if taskData.get('resources'):
            resources = [int(i.get('id')) for i in taskData.get('resources')]
        if taskData.get('updatedResponsibles'):
            responsibles = taskData.get('updatedResponsibles')
        if taskData.get('depends'):
            depends = [int(i.get('id')) for i in taskData.get('depends')]
        if taskData.get('updatedAlternativeResources'):
            alternative_resources = taskData.get('updatedAlternativeResources')
        if taskData.get('updatedWatchers'):
            watchers = taskData.get('updatedWatchers')

        complete = int(taskData.get('complete'))
        effort = int(taskData.get('effort'))
        start = str(taskData.get('start'))
        end = str(taskData.get('end'))
        title = taskData.get('title')
        priority = taskData.get('priority')
        _id = int(taskData.get('id'))
        priority = int(taskData.get('priority'))
        target = Task.query.filter(Task.id == _id).first()
        if target:
            target.title = title
            target.start = start
            target.priority = priority
            target.end = end
            target.effort = effort
            if effort:
                target.complete = complete
            if resources:
                target.resources = []
            for i in resources:
                resource = User.query.filter(User.id == i).first()
                if not resource in target.project.users:
                    target.project.users.append(resource)
                if resource:
                    target.resources.append(resource)
            if depends:
                target.depends = []
            for i in depends:
                depend = Task.query.filter(Task.id == i).first()
                if depend:
                    target.depends.append(depend)

            resp.body = {'message': 'Task Updated'}
        else:
            resp.status = falcon.HTTP_404
            resp.body = {'message': 'Task Not Found'}
Exemple #9
0
    def on_put(self, req, resp, projId):
        user = getUserInfoFromSession(req, resp)
        taskData = get_params(req.stream, flat=False)
        resources, depends, manager, effort = list(), list(), 0, 0
        title = taskData.get('title')
        if taskData.get('effort'):
            effort = int(taskData.get('effort'))
        start = taskData.get('start')
        end = taskData.get('end')
        priority = taskData.get('priority')
        project = Project.query.filter_by(id=int(projId)).scalar()
        if Project.query.join(Task).filter_by(title=title).all():
            resp.status = falcon.HTTP_203
            resp.body = {'message': 'task already available'}
            return
        if not start:
            start = project.start
        else:
            start = str(start)

        newTask = Task(title=title,
                       effort=effort,
                       project_id=project.id,
                       start=start)

        newTask.priority = priority
        if end:
            newTask.end = str(end)

        if taskData.get('resources'):
            resources = [int(i.get('id')) for i in taskData.get('resources')]
        if taskData.get('depends'):
            depends = [int(i.get('id')) for i in taskData.get('depends')]
        if taskData.get('manager'):
            manager = int(taskData.get('manager').get('id'))
        for i in resources:
            resource = User.query.filter(User.id == i).first()
            if resource:
                newTask.resources.append(resource)
        if manager:
            manager = User.query.filter(User.id == manager).first()
            if manager:
                newTask.responsibles.append(manager)
        for i in depends:
            depend = Task.query.filter(Task.id == i).first()
            if depend:
                newTask.depends.append(depend)
        #depend = session.query(Task).filter(Task.id==depends).first()
        # newTask.depends.append(depend)
        req.session.add(newTask)
        resp.body = {'message': 'OK'}
Exemple #10
0
    def on_post(self, req, resp, userId):
        target = req.session.query(User).filter_by(id=int(userId)).first()
        data = get_params(req.stream, False)
        added = []
        if data.get('groups'):
            target.grps = []
            target.groups = [i.get('name') for i in data.get('groups')]
            if 'guests' in target.groups and 'users' not in target.groups:
                target.groups.append('users')

            if target.id == 1 and not 'admin' in target.groups:
                target.groups.append('admin')

            resp.status = falcon.HTTP_202
            resp.body = {'message': 'OK'}
Exemple #11
0
 def on_put(self, req, resp, **kw):
     args = req.path.split('/')
     table = args[3].title()
     u = getUserInfoFromSession(req, resp)
     # if not isAuthorizedTo(u.get('id'), 'create_%s'%table):
     #    raise falcon.HTTPUnauthorized('Not Authorized', 'Permission Denied')
     query_params = get_params(req.stream, flat=False)
     insert_cmd = '{t}(**query_params)'.format(t=table)
     new = eval(insert_cmd)
     # for i in query_params:
     #    setattr(new, i, query_params.get(i))
     resp.status = falcon.HTTP_201
     req.session.add(new)
     data = repr(new)
     resp.body = data
Exemple #12
0
 def on_post(self, req, resp, key):
     options = get_params(req.stream, False)
     from_folder = options.get('from_folder') or req.get_param(
         'from_folder')
     to_folder = options.get('to_folder') or req.get_param('to_folder')
     if not from_folder in [
             'inbox', 'sent', 'draft', 'star', 'archive', 'spam', 'trash'
     ]:
         resp.body = falcon.HTTP_400
         return
     if not to_folder in [
             'inbox', 'sent', 'draft', 'star', 'archive', 'spam', 'trash'
     ]:
         resp.body = falcon.HTTP_400
         return
     if to_folder == from_folder:
         resp.body = falcon.HTTP_201
         return
     user = getUserInfoFromSession(req, resp)
     mdb = getUserMessageBox(user.get('uuid'))
     message = mdb.get(key)
     data = message.data
     # lets move
     #        if data:
     #            target_mdb = getUserMessageBox(user.get('uuid'),  to_folder)
     #            tobj = target_mdb.new(key, data)
     #            tobj.store()
     #            mdb.delete(key)
     #            resp.body = falcon.HTTP_201
     #            resp.body = {'message':'MOVED'}
     #        else:
     #            resp.status = falcon.HTTP_404
     #            resp.body = {'message':'Not Found'}
     if data:
         data['folder'] = to_folder
         mdb.delete(key)
         obj = mdb.new(key, data)
         obj.store()
         resp.body = falcon.HTTP_201
         resp.body = {'message': 'MOVED'}
     else:
         mdb.delete(key)
         resp.status = falcon.HTTP_404
         resp.body = {'message': 'Not Found'}
Exemple #13
0
    def on_put(self, req, resp):
        userInfo = getUserInfoFromSession(req, resp)
        data = get_params(req.stream, flat=False)
        name = data.get('name')
        repository_id = data.get('repository_id')
        parent_id = data.get('parent_id')

        template = data.get('template').lower()
        if name and repository_id:
            _uid = getUUID()
            newC = Collection( name=name, uuid=_uid, path=name,
                              repository_id=repository_id, owner_id=userInfo.get('id'))
            if parent_id:
                newC.parent_id = parent_id
            if template:
                newC.template = template

            # if not os.path.isdir(newC.url):
            req.session.add(newC)
            req.session.flush()
            resp.body = {'message': 'OK', 'info': {'uuid': _uid}}
Exemple #14
0
    def on_post(self, req, resp, projId):
        user = getUserInfoFromSession(req, resp)
        data = get_params(req.stream, flat=False)
        project = Project.query.filter(Project.id == int(projId)).first()
        if project:
            project.start = data.get('start')
            project.name = data.get('name')
            project.end = data.get('end')
            project.description = data.get('description')
            if data.get('leader'):
                project.lead_id = data.get('leader').get('id')
            project.watchers = []
            if data.get('watchers'):
                for eachWatcherId in data.get('watchers'):
                    _id = int(eachWatcherId.get('id'))
                    watcher = User.query.filter(User.id == _id).first()
                    project.watchers.append(watcher)

            resp.body = {'message': 'OK'}
        else:
            resp.status = falcon.HTTP_404
Exemple #15
0
    def on_post(self, req, resp):
        user = getUserInfoFromSession(req, resp)
        message = get_params(req.stream, False)
        TO = None
        if message.get('to'):
            TO = req.session.query(User).filter_by(
                id=message.get('to').get('id')).first()
        FROM = req.session.query(User).filter_by(
            email=user.get('email')).first()
        _from = user.get('email')
        _from_fn = user.get('firstname')
        _from_ln = user.get('lastname')

        data = {
            'to_s': {
                'firstname_s': TO.firstname if TO else None,
                'lastname_s': TO.lastname if TO else None,
                'email_s': TO.email if TO else None,
                'id': TO.id if TO else None,
            },
            'from_s': {
                'firstname_s': FROM.firstname,
                'lastname_s': FROM.lastname,
                'email_s': FROM.email,
                'id': FROM.id
            },
            'read': False,
            'attachments': [],
            'body_s': message.get('body'),
            'subject_s': message.get('subject'),
            'folder': 'sent',
            'stared': False,
            'flagged': False,
            'datetime': time.time()
        }

        target_data = data.copy()
        bfolder = message.get('folder') or 'sent'
        if not bfolder in [
                'inbox', 'sent', 'draft', 'star', 'archive', 'spam', 'trash'
        ]:
            resp.body = falcon.HTTP_400
            return
        if not TO or not message.get('subject') or message.get('draft'):
            bfolder = 'draft'
            target_data = {}
            data['folder'] = 'draft'
        if FROM and message.get('body'):
            key = getUUID()
            if data:
                from_mdb = getUserMessageBox(FROM.uuid)
                obj = from_mdb.new(key, data)
                obj.store()
            if target_data:
                to_mdb = getUserMessageBox(TO.uuid)
                target_data['folder'] = 'inbox'
                tobj = to_mdb.new(key, target_data)
                tobj.store()
                mail_body = misaka.html('_____\n %s \n_____' %
                                        message.get('body'))
                mail_subject = ('New message from %s: ' %
                                FROM.firstname) + message.get('subject')
                sent = send_envelope.delay([TO.email], [], [], mail_subject,
                                           mail_body, FROM.email)
            if data:
                resp.body = {'message': data, 'key': key}
            else:
                resp.status = falcon.HTTP_201
        else:
            resp.status = falcon.HTTP_400
            resp.body = {
                'message': 'error',
                'info': 'subject, to and body needed.'
            }
Exemple #16
0
 def on_post(self, req, resp, key):
     target = req.session.query(Project).filter_by(uuid=key).first()
     data = get_params(req.stream, False)
     target.tags = data.get('tags')
     resp.status = falcon.HTTP_202