def handle_noargs(self, **options):

        if not (options['project_id'] and options['user_id']):
            raise CommandError("You must specify both --project and --user")

        user = User.objects.get(pk=options['user_id'])
        # Set up tracing for the requested project
        setup_tracing(options['project_id'], user)
    def handle_noargs(self, **options):

        if not (options['project_id'] and options['user_id']):
            raise CommandError("You must specify both --project and --user")

        user = User.objects.get(pk=options['user_id'])
        # Set up tracing for the requested project
        setup_tracing(options['project_id'], user);
Пример #3
0
    def setUp(self):
        """Create a project and a suer with browse/annotate permissions.
        """
        self.client = Client()
        admin = User.objects.create(username="******", password="******", is_superuser=True)
        project = Project.objects.create(title="Testproject")
        self.project_id = project.id

        # Set project up for tracing
        tracing.setup_tracing(self.project_id, admin)
        self.authenticate()
Пример #4
0
    def handle(self, *args, **options):
        user = None
        user_id = pk=options['user_id']
        if user_id is not None:
            user = User.objects.get(pk=user_id)

        if not user:
            from catmaid.apps import get_system_user
            user = get_system_user()
            logger.info("Using system user account {} (ID: {})".format(user, user.id))

        # Set up tracing for the requested project
        setup_tracing(options['project_id'], user)
    def handle(self, *args, **options):
        set_log_level(logger, options.get('verbosity', 1))
        user = None
        user_id = pk = options['user_id']
        if user_id is not None:
            user = User.objects.get(pk=user_id)

        if not user:
            from catmaid.apps import get_system_user
            user = get_system_user()
            logger.info(f"Using system user account {user} (ID: {user.id})")

        # Set up tracing for the requested project
        setup_tracing(options['project_id'], user)
Пример #6
0
def fork(request:HttpRequest, project_id) -> JsonResponse:
    """Attempt to create a new project based on the passed in project ID.
    ---
    parameters:
    - name: name
      description: Name of new project
      required: true
      type: string
    """
    name = request.POST.get('name')
    if not name:
        raise ValueError('Need new project name')

    current_p = get_object_or_404(Project, pk=project_id)
    new_p = get_object_or_404(Project, pk=project_id)

    new_p.id = None
    new_p.title = name
    new_p.save()

    # Copy all project-stack links
    ps_links = ProjectStack.objects.filter(project=current_p)
    for ps in ps_links:
        ps.id = None
        ps.project = new_p
        ps.save()

    # Assign read/write/import permissions for new fork
    assign_perm('can_browse', request.user, new_p)
    assign_perm('can_annotate', request.user, new_p)
    assign_perm('can_import', request.user, new_p)

    # Creat basic classes and relations
    validate_project_setup(new_p.id, request.user.id, fix=True)

    # If the source project is a tracing project, make the clone as well one.
    # A local import is used here to avoid a high potential for circular imports.
    from catmaid.control.tracing import check_tracing_setup, setup_tracing
    if check_tracing_setup(project_id):
        setup_tracing(new_p.id)

    return JsonResponse({
        'new_project_id': new_p.id,
        'n_copied_stack_links': len(ps_links),
    })
Пример #7
0
    def setUp(self):
        """Create a project and a suer with browse/annotate permissions on
        it. Both are referenced when creating
        """
        cache.clear()

        self.client = Client()
        self.user = User.objects.create(username="******")
        self.user.set_password("test")
        self.user.save()
        self.admin = User.objects.create(username="******", is_superuser=True)
        self.admin.set_password("admin")
        self.admin.save()
        self.project = Project.objects.create(title="Testproject")
        assign_perm('can_browse', self.user, self.project)
        assign_perm('can_annotate', self.user, self.project)

        # Set project up for tracing
        tracing.setup_tracing(self.project.id, self.admin)
        self.authenticate()
Пример #8
0
def fork(request:HttpRequest, project_id) -> JsonResponse:
    """Attempt to create a new project based on the passed in project ID.
    ---
    parameters:
    - name: name
      description: Name of new project
      required: true
      type: string
    - name: copy_volumes
      description: Whether volumes will be copied to the new project
      required: false
      type: boolean
      defaultValue: false
    """
    name = request.POST.get('name')
    if not name:
        raise ValueError('Need new project name')

    copy_volumes = get_request_bool(request.POST, 'copy_volumes', False)

    current_p = get_object_or_404(Project, pk=project_id)
    new_p = get_object_or_404(Project, pk=project_id)

    new_p.id = None
    new_p.title = name
    new_p.save()

    # Copy all project-stack links
    ps_links = ProjectStack.objects.filter(project=current_p)
    for ps in ps_links:
        ps.id = None
        ps.project = new_p
        ps.save()

    # Assign read/write/import permissions for new fork
    assign_perm('can_browse', request.user, new_p)
    assign_perm('can_annotate', request.user, new_p)
    assign_perm('can_import', request.user, new_p)
    assign_perm('can_fork', request.user, new_p)
    assign_perm('can_administer', request.user, new_p)
    assign_perm('delete_project', request.user, new_p)

    # Creat basic classes and relations
    validate_project_setup(new_p.id, request.user.id, fix=True)

    # If the source project is a tracing project, make the clone as well one.
    # A local import is used here to avoid a high potential for circular imports.
    from catmaid.control.tracing import check_tracing_setup, setup_tracing
    if check_tracing_setup(project_id):
        setup_tracing(new_p.id)

    if copy_volumes:
        cursor = connection.cursor()
        cursor.execute("""
            INSERT INTO catmaid_volume (user_id, project_id, creation_time,
                    edition_time, editor_id, name, comment, geometry, area,
                    volume, watertight, meta_computed)
            SELECT user_id, %(new_project_id)s, creation_time, edition_time,
                    editor_id, name, comment, geometry, area, volume, watertight,
                    meta_computed
            FROM catmaid_volume
            WHERE project_id = %(project_id)s;
        """, {
            'project_id': project_id,
            'new_project_id': new_p.id
        })

    return JsonResponse({
        'new_project_id': new_p.id,
        'n_copied_stack_links': len(ps_links),
    })
 def handle(self, *args, **options):
     user = User.objects.get(pk=options['user_id'])
     # Set up tracing for the requested project
     setup_tracing(options['project_id'], user)
 def handle(self, *args, **options):
     user = User.objects.get(pk=options['user_id'])
     # Set up tracing for the requested project
     setup_tracing(options['project_id'], user)
Пример #11
0
def fork(request: HttpRequest, project_id) -> JsonResponse:
    """Attempt to create a new project based on the passed in project ID.
    ---
    parameters:
    - name: name
      description: Name of new project
      required: true
      type: string
    - name: description
      description: Description of new project
      required: false
      type: string
    - name: copy_volumes
      description: Whether volumes will be copied to the new project
      required: false
      type: boolean
      defaultValue: false
    - name: project_token
      description: Whether or not a new project token should be generated
      required: false
      type: boolean
      defaultValue: false
    - name: add_to_favorites
      description: Whether or not the new project is marked as a favorite
      required: false
      type: boolean
      defaultValue: true
    """
    name = request.POST.get('name')
    if not name:
        raise ValueError('Need new project name')

    description = request.POST.get('description')
    copy_volumes = get_request_bool(request.POST, 'copy_volumes', False)
    create_project_token = get_request_bool(request.POST, 'project_token',
                                            False)

    project_token_approval_needed = get_request_bool(
        request.POST, 'project_token_approval_needed', False)
    project_token_default_perms = get_request_list(
        request.POST, 'project_token_default_permissions', [])
    add_to_favorites = get_request_bool(request.POST, 'add_to_favorites', True)

    current_p = get_object_or_404(Project, pk=project_id)
    new_p = get_object_or_404(Project, pk=project_id)

    new_p.id = None
    new_p.title = name
    new_p.comment = description
    new_p.save()

    # Copy all project-stack links
    ps_links = ProjectStack.objects.filter(project=current_p)
    for ps in ps_links:
        ps.id = None
        ps.project = new_p
        ps.save()

    # Assign read/write/import permissions for new fork
    assign_perm('can_browse', request.user, new_p)
    assign_perm('can_annotate', request.user, new_p)
    assign_perm('can_import', request.user, new_p)
    assign_perm('can_fork', request.user, new_p)
    assign_perm('can_administer', request.user, new_p)
    assign_perm('delete_project', request.user, new_p)

    # Creat basic classes and relations
    validate_project_setup(new_p.id, request.user.id, fix=True)

    # If the source project is a tracing project, make the clone as well one.
    # A local import is used here to avoid a high potential for circular imports.
    from catmaid.control.tracing import check_tracing_setup, setup_tracing
    if check_tracing_setup(project_id):
        setup_tracing(new_p.id)

    if copy_volumes:
        cursor = connection.cursor()
        cursor.execute(
            """
            INSERT INTO catmaid_volume (user_id, project_id, creation_time,
                    edition_time, editor_id, name, comment, geometry, area,
                    volume, watertight, meta_computed)
            SELECT user_id, %(new_project_id)s, creation_time, edition_time,
                    editor_id, name, comment, geometry, area, volume, watertight,
                    meta_computed
            FROM catmaid_volume
            WHERE project_id = %(project_id)s;
        """, {
                'project_id': project_id,
                'new_project_id': new_p.id
            })

    project_token_str = None
    if create_project_token:
        allowed_permissions = set(
            get_perms_for_model(Project).values_list('codename', flat=True))
        unknown_permissions = set(
            project_token_default_perms) - allowed_permissions
        if unknown_permissions:
            raise ValueError(
                f'Unknown permissions: {", ".join(unknown_permissions)}')
        project_token = ProjectToken.objects.create(
            **{
                'user_id': request.user.id,
                'project_id': new_p.id,
                'name': "",
                'needs_approval': project_token_approval_needed,
                'default_permissions': project_token_default_perms,
            })
        project_token.name = f'Project token #{project_token.id}'
        project_token.save()

        project_token_str = project_token.token

    if add_to_favorites:
        FavoriteProject.objects.create(**{
            'project_id': new_p.id,
            'user_id': request.user.id,
        })

    return JsonResponse({
        'new_project_id': new_p.id,
        'n_copied_stack_links': len(ps_links),
        'project_token': project_token_str,
    })