Skip to content

Commit

Permalink
Merge pull request #643 from opensafely-core/bll-refactor-1
Browse files Browse the repository at this point in the history
BLL refactor mark 1
  • Loading branch information
bloodearnest authored Aug 29, 2024
2 parents 0f4a42e + 3c7374f commit bd2625d
Show file tree
Hide file tree
Showing 18 changed files with 2,220 additions and 2,138 deletions.
1,038 changes: 18 additions & 1,020 deletions airlock/business_logic.py

Large diffs are not rendered by default.

51 changes: 45 additions & 6 deletions airlock/file_browser_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,61 @@
from dataclasses import dataclass, field
from datetime import UTC, datetime
from pathlib import Path
from typing import Protocol

from airlock.business_logic import (
ROOT_PATH,
AirlockContainer,
from airlock import renderers
from airlock.enums import PathType, RequestFileType, WorkspaceFileStatus
from airlock.models import (
CodeRepo,
ReleaseRequest,
RequestFileStatus,
Workspace,
)
from airlock.enums import PathType, RequestFileType, WorkspaceFileStatus
from airlock.types import FileMetadata, UrlPath
from airlock.types import ROOT_PATH, FileMetadata, UrlPath
from airlock.users import User
from airlock.utils import is_valid_file_type
from airlock.visibility import RequestFileStatus
from services.tracing import instrument


class AirlockContainer(Protocol):
"""Structural typing class for a instance of a Workspace or ReleaseRequest
Provides a uniform interface for the file browser to accessing information
about the paths and files contained within this container, whichever kind
it is.
"""

def get_id(self) -> str:
"""Get the human name for this container."""

def get_url(self, relpath: UrlPath = ROOT_PATH) -> str:
"""Get the url for the container object with path"""

def get_contents_url(
self, relpath: UrlPath, download: bool = False, plaintext: bool = False
) -> str:
"""Get the url for the contents of the container object with path"""

def request_filetype(self, relpath: UrlPath) -> RequestFileType | None:
"""What kind of file is this, e.g. output, supporting, etc."""

def get_renderer(
self, relpath: UrlPath, plaintext: bool = False
) -> renderers.Renderer:
"""Create and return the correct renderer for this path."""

def get_file_metadata(self, relpath: UrlPath) -> FileMetadata | None:
"""Get the file metadata"""

def get_workspace_file_status(self, relpath: UrlPath) -> WorkspaceFileStatus | None:
"""Get workspace state of file."""

def get_request_file_status(
self, relpath: UrlPath, user: User
) -> RequestFileStatus | None:
"""Get request status of file."""


@dataclass
class PathItem:
"""
Expand Down
2 changes: 1 addition & 1 deletion airlock/forms.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from django import forms
from django.forms.formsets import BaseFormSet, formset_factory

from airlock.business_logic import FileGroup
from airlock.enums import RequestFileType, Visibility
from airlock.models import FileGroup


class ListField(forms.Field):
Expand Down
Loading

0 comments on commit bd2625d

Please sign in to comment.