Exemplo n.º 1
0
    def post(self):
        user = get_current_user()
        if user is None:
            return error('Not logged in.', http_code=401)
        args = self.post_parser.parse_args()

        slug = str(args.slug or args.name.replace(' ', '-').lower())

        if not user_has_project_permission(user, slug):
            return error(
                'User does not have permission to create a project with slug {}.'
                .format(slug),
                http_code=403)

        match = Project.query.filter(Project.slug == slug, ).first()
        if match:
            return error('Project with slug {} already exists.'.format(slug),
                         http_code=400)

        repository = Repository.get(args.repository)
        if repository is None:
            return error('Repository with url {} does not exist.'.format(
                args.repository),
                         http_code=400)

        project = Project(
            name=args.name,
            slug=slug,
            repository=repository,
        )
        db.session.add(project)
        db.session.commit()

        return self.respond(project)
Exemplo n.º 2
0
    def post(self):
        user = get_current_user()
        if user is None:
            return error('Not logged in.', http_code=401)
        args = self.post_parser.parse_args()

        slug = str(args.slug or args.name.replace(' ', '-').lower())

        if not user_has_project_permission(user, slug):
            return error('User does not have permission to create a project with slug {}.'.format(slug), http_code=403)

        match = Project.query.filter(
            Project.slug == slug,
        ).first()
        if match:
            return error('Project with slug {} already exists.'.format(slug), http_code=400)

        repository = Repository.get(args.repository)
        if repository is None:
            return error('Repository with url {} does not exist.'.format(args.repository), http_code=400)

        project = Project(
            name=args.name,
            slug=slug,
            repository=repository,
        )
        db.session.add(project)
        db.session.commit()

        return self.respond(project)
Exemplo n.º 3
0
    def post(self, project_id):
        project = Project.get(project_id)
        if project is None:
            return '', 404

        args = self.post_parser.parse_args()

        if args.name:
            project.name = args.name

        if args.slug:
            match = Project.query.filter(
                Project.slug == args.slug,
                Project.id != project.id,
            ).first()
            if match:
                return '{"error": "Project with slug %r already exists"}' % (
                    args.slug, ), 400

            project.slug = args.slug

        if args.repository:
            repository = Repository.get(args.repository)
            if repository is None:
                return '{"error": "Repository with url %r does not exist"}' % (
                    args.repository, ), 400
            project.repository = repository

        if args.status == 'inactive':
            project.status = ProjectStatus.inactive
        elif args.status == 'active':
            project.status = ProjectStatus.active

        db.session.add(project)

        data = self.serialize(project)
        data['repository'] = self.serialize(project.repository)

        return self.respond(data, serialize=False)
Exemplo n.º 4
0
    def post(self, project_id):
        project = Project.get(project_id)
        if project is None:
            return '', 404

        args = self.post_parser.parse_args()

        if args.name:
            project.name = args.name

        if args.slug:
            match = Project.query.filter(
                Project.slug == args.slug,
                Project.id != project.id,
            ).first()
            if match:
                return '{"error": "Project with slug %r already exists"}' % (args.slug,), 400

            project.slug = args.slug

        if args.repository:
            repository = Repository.get(args.repository)
            if repository is None:
                return '{"error": "Repository with url %r does not exist"}' % (args.repository,), 400
            project.repository = repository

        if args.status == 'inactive':
            project.status = ProjectStatus.inactive
        elif args.status == 'active':
            project.status = ProjectStatus.active

        db.session.add(project)

        data = self.serialize(project)
        data['repository'] = self.serialize(project.repository)

        return self.respond(data, serialize=False)
Exemplo n.º 5
0
    def post(self):
        args = self.post_parser.parse_args()

        slug = str(args.slug or args.name.replace(' ', '-').lower())

        match = Project.query.filter(
            Project.slug == slug,
        ).first()
        if match:
            return '{"error": "Project with slug %r already exists"}' % (slug,), 400

        repository = Repository.get(args.repository)
        if repository is None:
            return '{"error": "Repository with url %r does not exist"}' % (args.repository,), 400

        project = Project(
            name=args.name,
            slug=slug,
            repository=repository,
        )
        db.session.add(project)
        db.session.commit()

        return self.respond(project)