Пример #1
0
 def post(self):
     '''Create a new scheduled job'''
     if 'crontab' in request.json and 'interval' in request.json:
         api.abort(400, 'Cannot define both interval and crontab schedule')
     if 'crontab' in request.json:
         form = api.validate(CrontabTaskForm)
     else:
         form = api.validate(IntervalTaskForm)
     return form.save(), 201
Пример #2
0
 def put(self, id):
     '''Update a single scheduled job'''
     task = self.get_or_404(id)
     if 'crontab' in request.json:
         task.interval = None
         task.crontab = PeriodicTask.Crontab()
         form = api.validate(CrontabTaskForm, task)
     else:
         task.crontab = None
         task.interval = PeriodicTask.Interval()
         form = api.validate(IntervalTaskForm, task)
     return form.save()
Пример #3
0
 def post(self, dataset):
     '''Create a new resource for a given dataset'''
     form = api.validate(ResourceForm)
     resource = Resource()
     form.populate_obj(resource)
     dataset.add_resource(resource)
     return resource, 201
Пример #4
0
 def put(self, org):
     """Update a organization given its identifier"""
     if org.deleted:
         api.abort(410, "Organization has been deleted")
     EditOrganizationPermission(org).test()
     form = api.validate(OrganizationForm, org)
     return form.save()
Пример #5
0
 def put(self, reuse):
     '''Update a given reuse'''
     if reuse.deleted:
         api.abort(410, 'This reuse has been deleted')
     ReuseEditPermission(reuse).test()
     form = api.validate(ReuseForm, reuse)
     return form.save()
Пример #6
0
 def post(self, ident):
     '''Validate or reject an harvest source'''
     form = api.validate(HarvestSourceValidationForm)
     if form.state.data == VALIDATION_ACCEPTED:
         return actions.validate_source(ident, form.comment.data)
     else:
         return actions.reject_source(ident, form.comment.data)
Пример #7
0
 def put(self, dataset):
     '''Update a dataset given its identifier'''
     if dataset.deleted:
         api.abort(410, 'Dataset has been deleted')
     DatasetEditPermission(dataset).test()
     form = api.validate(DatasetForm, dataset)
     return form.save()
Пример #8
0
 def post(self):
     '''Create a new harvests source'''
     form = api.validate(HarvestSourceForm)
     if form.organization.data:
         EditOrganizationPermission(form.organization.data).test()
     source = actions.create_source(**form.data)
     return source, 201
Пример #9
0
 def put(self, dataset, rid):
     '''Update a given resource on a given dataset'''
     resource = self.get_resource_or_404(dataset, rid)
     form = api.validate(ResourceForm, resource)
     form.populate_obj(resource)
     resource.modified = datetime.now()
     dataset.save()
     return resource
Пример #10
0
 def put(self, reuse):
     '''Update a given reuse'''
     request_deleted = request.json.get('deleted', True) 
     if reuse.deleted and request_deleted is not None: 
         api.abort(410, 'This reuse has been deleted')
     ReuseEditPermission(reuse).test()
     form = api.validate(ReuseForm, reuse)
     return form.save()
Пример #11
0
 def put(self, dataset):
     '''Update a dataset given its identifier'''
     request_deleted = request.json.get('deleted', True)
     if dataset.deleted and request_deleted is not None:
         api.abort(410, 'Dataset has been deleted')
     DatasetEditPermission(dataset).test()
     dataset.last_modified = datetime.now()
     form = api.validate(DatasetForm, dataset)
     return form.save()
Пример #12
0
 def put(self, community):
     '''Update a given community resource'''
     form = api.validate(CommunityResourceForm, community)
     form.populate_obj(community)
     if not community.organization:
         community.owner = current_user._get_current_object()
     community.modified = datetime.now()
     community.save()
     return community
Пример #13
0
    def put(self, org, user):
        '''Update member status into a given organization.'''
        EditOrganizationPermission(org).test()
        member = org.member(user)
        form = api.validate(MemberForm, member)
        form.populate_obj(member)
        org.save()

        return member
Пример #14
0
 def post(self, dataset):
     '''Create a new resource for a given dataset'''
     ResourceEditPermission(dataset).test()
     form = api.validate(ResourceForm)
     resource = Resource()
     form.populate_obj(resource)
     dataset.add_resource(resource)
     dataset.last_modified = datetime.now()
     dataset.save()
     return resource, 201
Пример #15
0
 def post(self, org):
     """Create a new badge for a given organization"""
     Form = badge_form(Organization)
     form = api.validate(Form)
     badge = Badge(created=datetime.now(), created_by=current_user.id)
     form.populate_obj(badge)
     for existing_badge in org.badges:
         if existing_badge.kind == badge.kind:
             return existing_badge
     org.add_badge(badge)
     return badge, 201
Пример #16
0
 def post(self, reuse):
     '''Create a new badge for a given reuse'''
     form = api.validate(BadgeForm)
     badge = ReuseBadge(created=datetime.now(),
                        created_by=current_user.id)
     form.populate_obj(badge)
     for existing_badge in reuse.badges:
         if existing_badge.kind == badge.kind:
             return existing_badge
     reuse.add_badge(badge)
     return badge, 201
Пример #17
0
 def post(self, dataset):
     '''Create a new badge for a given dataset'''
     Form = badge_form(Dataset)
     form = api.validate(Form)
     badge = Badge(created=datetime.now(),
                   created_by=current_user.id)
     form.populate_obj(badge)
     for existing_badge in dataset.badges:
         if existing_badge.kind == badge.kind:
             return existing_badge
     dataset.add_badge(badge)
     return badge, 201
Пример #18
0
    def put(self, org):
        '''
        Update a organization given its identifier

        :raises PermissionDenied:
        '''
        request_deleted = request.json.get('deleted', True)
        if org.deleted and request_deleted is not None:
            api.abort(410, 'Organization has been deleted')
        EditOrganizationPermission(org).test()
        form = api.validate(OrganizationForm, org)
        return form.save()
Пример #19
0
    def post(self, org, user):
        '''Add a member into a given organization.'''
        EditOrganizationPermission(org).test()
        if org.is_member(user):
            return org.member(user), 409
        member = Member(user=user)
        form = api.validate(MemberForm, member)
        form.populate_obj(member)
        org.members.append(member)
        org.save()

        return member, 201
Пример #20
0
    def post(self, org, id):
        '''Refuse user membership to a given organization.'''
        membership_request = self.get_or_404(org, id)
        form = api.validate(MembershipRefuseForm)

        membership_request.status = 'refused'
        membership_request.handled_by = current_user._get_current_object()
        membership_request.handled_on = datetime.now()
        membership_request.refusal_comment = form.comment.data

        org.save()

        return {}, 200
Пример #21
0
    def post(self):
        '''Create a new Discussion'''
        form = api.validate(DiscussionCreateForm)

        message = Message(
            content=form.comment.data,
            posted_by=current_user.id)
        discussion = Discussion(user=current_user.id, discussion=[message])
        form.populate_obj(discussion)
        discussion.save()
        on_new_discussion.send(discussion)

        return discussion, 201
Пример #22
0
 def post(self):
     '''Create a new community resource'''
     form = api.validate(CommunityResourceForm)
     resource = CommunityResource()
     form.populate_obj(resource)
     if not resource.dataset:
         api.abort(400, errors={
             'dataset': 'A dataset identifier is required'
         })
     if not resource.organization:
         resource.owner = current_user._get_current_object()
     resource.modified = datetime.now()
     resource.save()
     return resource, 201
Пример #23
0
    def post(self, id):
        '''Create a new Issue for an object given its ID'''
        form = api.validate(IssueCreateForm)

        message = Message(content=form.comment.data, posted_by=current_user.id)
        issue = self.model.objects.create(
            subject=id,
            type=form.type.data,
            user=current_user.id,
            discussion=[message]
        )
        on_new_issue.send(issue)

        return marshal(issue, issue_fields), 201
Пример #24
0
    def post(self):
        '''Create a new Issue'''
        form = api.validate(IssueCreateForm)

        message = Message(
            content=form.comment.data,
            posted_by=current_user.id
        )
        issue = Issue(user=current_user.id, discussion=[message])
        form.populate_obj(issue)
        issue.save()
        on_new_issue.send(issue)

        return issue, 201
Пример #25
0
    def post(self, org, id):
        """Refuse user membership to a given organization."""
        EditOrganizationPermission(org).test()
        membership_request = self.get_or_404(org, id)
        form = api.validate(MembershipRefuseForm)
        membership_request.status = "refused"
        membership_request.handled_by = current_user._get_current_object()
        membership_request.handled_on = datetime.now()
        membership_request.refusal_comment = form.comment.data

        org.save()

        notify_membership_response.delay(org, membership_request)

        return {}, 200
Пример #26
0
    def post(self, org):
        '''Apply for membership to a given organization.'''
        membership_request = org.pending_request(current_user._get_current_object())
        code = 200 if membership_request else 201

        form = api.validate(MembershipRequestForm, membership_request)

        if not membership_request:
            membership_request = MembershipRequest()
            org.requests.append(membership_request)

        form.populate_obj(membership_request)
        org.save()

        return membership_request, code
Пример #27
0
 def post(self, id):
     '''Add comment and optionnaly close an issue given its ID'''
     issue = Issue.objects.get_or_404(id=id)
     form = api.validate(IssueCommentForm)
     issue.discussion.append(Message(
         content=form.comment.data,
         posted_by=current_user.id
     ))
     close = form.close.data
     if close:
         issue.closed_by = current_user._get_current_object()
         issue.closed = datetime.now()
     issue.save()
     if close:
         on_issue_closed.send(issue)
     return marshal(issue, issue_fields), 200
Пример #28
0
def add(obj):
    '''
    Handle a badge add API.

    - Expecting badge_fieds as payload
    - Return the badge as payload
    - Return 200 if the badge is already
    - Return 201 if the badge is added
    '''
    Form = badge_form(obj.__class__)
    form = api.validate(Form)
    kind = form.kind.data
    badge = obj.get_badge(kind)
    if badge:
        return badge
    else:
        return obj.add_badge(kind), 201
Пример #29
0
 def post(self, id):
     '''Add comment and optionnaly close an issue given its ID'''
     issue = Issue.objects.get_or_404(id=id)
     form = api.validate(IssueCommentForm)
     message = Message(
         content=form.comment.data,
         posted_by=current_user.id
     )
     issue.discussion.append(message)
     close = form.close.data
     if close:
         CloseIssuePermission(issue).test()
         issue.closed_by = current_user._get_current_object()
         issue.closed = datetime.now()
     issue.save()
     if close:
         on_issue_closed.send(issue, message=message)
     else:
         on_new_issue_comment.send(issue, message=message)
     return issue
Пример #30
0
 def post(self, id):
     '''Add comment and optionally close a discussion given its ID'''
     discussion = Discussion.objects.get_or_404(id=id)
     form = api.validate(DiscussionCommentForm)
     message = Message(
         content=form.comment.data,
         posted_by=current_user.id
     )
     discussion.discussion.append(message)
     close = form.close.data
     if close:
         CloseDiscussionPermission(discussion).test()
         discussion.closed_by = current_user._get_current_object()
         discussion.closed = datetime.now()
     discussion.save()
     if close:
         on_discussion_closed.send(discussion, message=message)
     else:
         on_new_discussion_comment.send(discussion, message=message)
     return discussion
Пример #31
0
 def put(self):
     api.validate(FakeForm)
     return {'success': True}
Пример #32
0
 def put(self, topic):
     '''Update a given topic'''
     form = api.validate(TopicForm, topic)
     return form.save()
Пример #33
0
 def put(self, ident):
     '''Create a new harvests source'''
     source = actions.get_source(ident)
     form = api.validate(HarvestSourceForm, source)
     source = actions.update_source(ident, form.data)
     return source
Пример #34
0
 def post(self):
     '''Create a new organization'''
     form = api.validate(OrganizationForm)
     organization = form.save()
     return organization, 201
Пример #35
0
 def post(self):
     '''Create a new object'''
     form = api.validate(ReuseForm)
     return form.save(), 201
Пример #36
0
 def post(self):
     '''Preview an harvesting from a source created with the given payload'''
     form = api.validate(HarvestSourceForm)
     if form.organization.data:
         EditOrganizationPermission(form.organization.data).test()
     return actions.preview_from_config(**form.data)
Пример #37
0
 def post(self):
     '''Create a topic'''
     form = api.validate(TopicForm)
     return form.save(), 201
Пример #38
0
 def put(self, reuse):
     '''Update a given reuse'''
     ReuseEditPermission(reuse).test()
     form = api.validate(ReuseForm, reuse)
     return form.save()
Пример #39
0
 def post(self):
     '''Create a new object'''
     form = api.validate(UserProfileAdminForm)
     user = form.save()
     return user, 201
Пример #40
0
 def put(self, **kwargs):
     '''Update my profile'''
     user = current_user._get_current_object()
     form = api.validate(UserProfileForm, user)
     return form.save()
Пример #41
0
 def put(self, user):
     '''Update a user given its identifier'''
     form = api.validate(UserProfileAdminForm, user)
     return form.save()
Пример #42
0
 def post(self):
     '''Create a new dataset'''
     form = api.validate(DatasetForm)
     dataset = form.save()
     return dataset, 201
Пример #43
0
 def post(self):
     '''Create a post'''
     form = api.validate(PostForm)
     return form.save(), 201
Пример #44
0
 def put(self, post):
     '''Update a given post'''
     form = api.validate(PostForm, post)
     return form.save()
Пример #45
0
 def post(self):
     class FakeForm(Form):
         pass
     api.validate(FakeForm)
     return {'success': True}