Example #1
0
 def post(self, request, format=None):
     username = request.user.username
     repo_name = request.POST.get("name", None)
     repo_desc= request.POST.get("desc", 'new repo')
     passwd = request.POST.get("passwd")
     if not repo_name:
         return api_error(status.HTTP_400_BAD_REQUEST, \
                 'Library name is required.')
     
     # create a repo
     try:
         repo_id = seafserv_threaded_rpc.create_repo(repo_name, repo_desc,
                                                     username, passwd)
     except:
         return api_error(status.HTTP_520_OPERATION_FAILED, \
                 'Failed to create library.')
     if not repo_id:
         return api_error(status.HTTP_520_OPERATION_FAILED, \
                 'Failed to create library.')
     else:
         resp = Response('success', status=status.HTTP_201_CREATED)
         resp['Location'] = reverse('api2-repo', args=[repo_id])
         return resp
Example #2
0
    def post(self, request, format=None):
        username = request.user.username
        repo_name = request.POST.get("name", None)
        repo_desc = request.POST.get("desc", 'new repo')
        passwd = request.POST.get("passwd")
        if not repo_name:
            return api_error(status.HTTP_400_BAD_REQUEST, \
                    'Library name is required.')

        # create a repo
        try:
            repo_id = seafserv_threaded_rpc.create_repo(
                repo_name, repo_desc, username, passwd)
        except:
            return api_error(status.HTTP_520_OPERATION_FAILED, \
                    'Failed to create library.')
        if not repo_id:
            return api_error(status.HTTP_520_OPERATION_FAILED, \
                    'Failed to create library.')
        else:
            resp = Response('success', status=status.HTTP_201_CREATED)
            resp['Location'] = reverse('api2-repo', args=[repo_id])
            return resp
Example #3
0
            except SearpcError, e:
                status = -1
                
            # if share failed, remove the newly created repo
            if status != 0:
                seafserv_threaded_rpc.remove_repo(repo_id)
                return json_error(_(u'Failed to create: internal error.'))
            else:
                result = {'success': True}
                return HttpResponse(json.dumps(result),
                                    content_type=content_type)
        else:
            # create group repo in user context
            try:
                repo_id = seafserv_threaded_rpc.create_repo(repo_name,
                                                            repo_desc,
                                                            user, passwd)
            except:
                repo_id = None
            if not repo_id:
                return json_error(_(u'Failed to create'))

            try:
                status = seafserv_threaded_rpc.group_share_repo(repo_id,
                                                                group_id,
                                                                user,
                                                                permission)
            except SearpcError, e:
                status = -1
                
            # if share failed, remove the newly created repo