示例#1
0
文件: account.py 项目: jplock/flomosa
    def post(self):
        logging.debug('Begin RegisterHandler.post() method')

        template_vars = {
            'messages': []
        }

        email_address = self.request.get('email_address')
        password = self.request.get('password')
        confirm_password = self.request.get('confirm_password')
        first_name = self.request.get('first_name')
        last_name = self.request.get('last_name')
        company = self.request.get('company')

        if not email_address:
            template_vars['messages'].append('Please provide an email address')
        if not password:
            template_vars['messages'].append('Please provide a password')
        elif not confirm_password:
            template_vars['messages'].append('Please confirm your password')
        elif password != confirm_password:
            template_vars['messages'].append('Passwords do not match')

        query = models.Client.all()
        query.filter('email_address =', email_address)
        if query.get():
            template_vars['messages'].append('Email address already exists')

        if template_vars['messages']:
            for key, value in self.request.params.items():
                template_vars[key] = value

            self.response.out.write(self.show_form(template_vars))
        else:
            client_key = utils.generate_key()
            client = models.Client(key_name=client_key,
                email_address=email_address,
                password=self.encrypt_string(password))
            client.first_name = first_name
            client.last_name = last_name
            client.company = company
            client.oauth_secret = utils.generate_key()

            try:
                client.put()
            except Exception, ex:
                logging.error(ex)
                template_vars['messages'] = [ex]
                self.response.out.write(self.show_form(template_vars))

            if client.is_saved():
                self.set_secure_cookie(settings.COOKIE_NAME, client_key)
                next_url = self.request.get('next')
                if next_url:
                    return self.redirect(next_url)
                return self.redirect('/')
示例#2
0
文件: models.py 项目: jplock/flomosa
    def from_dict(cls, client, data, team_key=None):
        """Return a new Team instance from a dict object."""

        if not (client and isinstance(client, Client)):
            raise exceptions.MissingException('No client found')

        if not (data and isinstance(data, dict)):
            raise exceptions.MissingException('No data found')

        kind = data.get('kind', None)
        name = data.get('name', None)

        if not name:
            raise exceptions.MissingException('Missing "name" parameter.')
        if not kind:
            raise exceptions.MissingException('Missing "kind" parameter.')
        if kind != cls.__name__:
            raise exceptions.MissingException(
                'Expected "kind=%s", found "kind=%s".' % (cls.__name__, kind))

        if team_key is None:
            team_key = data.get('key', None)
        if not team_key:
            team_key = utils.generate_key()

        team = cls.get_or_insert(team_key, client=client, name=name)
        if team.client != client:
            raise exceptions.UnauthorizedException(
                'Client "%s" is not authorized to access Team "%s".' % (client,
                                                                        team))

        team.description = data.get('description', None)
        team.members = data.get('members', [])
        return team
示例#3
0
文件: request.py 项目: jplock/flomosa
    def post(self, request_key=None):
        logging.debug("Begin RequestHandler.post() method")

        data = self.request.params

        process_key = data.get("process", None)
        if not process_key:
            raise exceptions.MissingException('Missing "process" parameter.')

        process = models.Process.get(process_key)

        if not process.is_valid():
            raise exceptions.ValidationException('Process "%s" is not valid.' % process_key)

        requestor = data.get("requestor", None)
        if not requestor:
            raise exceptions.MissingException('Missing "requestor" parameter.')

        if request_key:
            request = models.Request.get(request_key)
            if request:
                raise exceptions.InternalException('Request "%s" already exists.' % request_key)
        else:
            request_key = utils.generate_key()
            request = models.Request(key_name=request_key, process=process, client=process.client, requestor=requestor)

        callback_url = data.get("callback_url", None)
        response_url = data.get("response_url", None)

        reserved_keys = ["callback_url", "response_url"]

        for key, value in data.items():
            if not hasattr(request, key) and key not in reserved_keys:
                setattr(request, key, value)
        request.put()

        if callback_url:
            # Queue task to submit the callback response
            queue = taskqueue.Queue("request-callback")
            task = taskqueue.Task(params={"request_key": request.id, "callback_url": callback_url})
            queue.add(task)

        if response_url:
            logging.info('Permanently redirecting client to "%s".', response_url)
            self.redirect(response_url, permanent=True)
        else:
            logging.info('Returning Request "%s" as JSON to client.', request.id)
            build_json(self, {"key": request.id}, 201)

        logging.debug("Finished RequestHandler.post() method")
示例#4
0
    def post(self):
        logging.debug("Begin execution-creation task handler")

        num_tries = self.request.headers["X-AppEngine-TaskRetryCount"]
        logging.info("Task has been executed %s times", num_tries)

        step_key = self.request.get("step_key")
        if not step_key:
            raise exceptions.MissingException('Missing "step_key" parameter.')

        request_key = self.request.get("request_key")
        if not request_key:
            raise exceptions.MissingException('Missing "request_key" parameter.')

        member = self.request.get("member")
        if not member:
            raise exceptions.MissingException('Missing "member" parameter.')

        step = models.Step.get(step_key)
        request = models.Request.get(request_key)

        team = None
        team_key = self.request.get("team_key")
        if team_key:
            try:
                team = models.Team.get(team_key)
            except Exception:
                team = None

        execution_key = utils.generate_key()
        execution = models.Execution(
            key_name=execution_key,
            parent=request,
            request=request,
            step=step,
            process=step.process,
            member=member,
            team=team,
        )

        execution.put()

        task = taskqueue.Task(params={"key": execution_key})
        queue = taskqueue.Queue("execution-process")
        queue.add(task)

        logging.debug("Finished execution-creation task handler")
示例#5
0
文件: models.py 项目: jplock/flomosa
    def add_step(self, name, description=None, team_key=None,
                 members=None, is_start=None, step_key=None):
        """Add a step to this process."""

        if is_start is None:
            if self.has_steps:
                is_start = False
            else:
                is_start = True
        if team_key is None and not members:
            raise exceptions.MissingException(
                'Steps require at least one member or a team.')
        if not members:
            members = []

        team = None
        if team_key:
            team = Team.get(team_key, self.client)
            if not team:
                raise exceptions.NotFoundException(
                    'Team "%s" does not exist.' % team_key)

        step = None
        if step_key:
            step = Step.get_by_key_name(step_key, parent=self)
        else:
            step_key = utils.generate_key()

        if not step:
            step = Step(key_name=step_key, parent=self, process=self,
                        name=name)

        if team:
            step.team = team
        step.is_start = bool(is_start)
        step.name = name
        step.members = members
        step.description = description
        step.put()
        self.has_steps = True
        return step
示例#6
0
文件: models.py 项目: jplock/flomosa
    def add_action(self, name, incoming, outgoing=None, action_key=None):
        """Add an action to this process."""

        if not incoming:
            raise exceptions.MissingException(
                'Actions require at least one incoming Step')
        if not outgoing:
            outgoing = []

        action = None
        if action_key:
            action = Action.get_by_key_name(action_key, parent=self)
        else:
            action_key = utils.generate_key()

        if not action:
            action = Action(key_name=action_key, parent=self, process=self,
                            name=name)
        action.name = name

        for step in incoming:
            if not isinstance(step, Step):
                step = Step.get(step, parent=self)
                if not step:
                    raise exceptions.NotFoundException(
                        'Incoming Step "%s" does not exist.' % step)
            action.add_incoming_step(step)
        for step in outgoing:
            if not isinstance(step, Step):
                step = Step.get(step, parent=self)
                if not step:
                    raise exceptions.NotFoundException(
                        'Outgoing Step "%s" does not exist.' % step)
            action.add_outgoing_step(step)

        action.put()
        return action
示例#7
0
文件: models.py 项目: jplock/flomosa
    def from_dict(cls, client, data, process_key=None):
        """Return a new Process instance from a dict object."""

        if not (client and isinstance(client, Client)):
            raise exceptions.MissingException('No client found')

        if not (data and isinstance(data, dict)):
            raise exceptions.MissingException('No data found')

        kind = data.get('kind', None)
        name = data.get('name', None)

        if not name:
            raise exceptions.MissingException('Missing "name" parameter.')
        if not kind:
            raise exceptions.MissingException('Missing "kind" parameter.')
        if kind != cls.__name__:
            raise exceptions.MissingException(
                'Expected "kind=%s", found "kind=%s".' % (cls.__name__, kind))

        if process_key is None:
            process_key = data.get('key', None)
        if not process_key:
            process_key = utils.generate_key()

        process = cls.get_or_insert(process_key, client=client, name=name)
        if process.client != client:
            raise exceptions.UnauthorizedException(
                'Client "%s" is not authorized to access Process "%s".' % (
                    client, process))

        process.description = data.get('description', None)
        collect_stats = data.get('collect_stats', False)
        if collect_stats is not None:
            process.collect_stats = bool(collect_stats)
        return process