Skip to content

Commit

Permalink
build: replace project.private field with project.visibility enum (#1132
Browse files Browse the repository at this point in the history
)

* build: remove project_allowed_users table from db

* build: remove odk_central_src field from project table

* refactor: tidy/reorder project db model fields

* build: remove project.task_creation_mode field + enum

* build: replace project.private field with project.visibility enum

* fix: fix visibility migration column add syntax

* fix: apply migration to projects table

* build: fix check for projectvisibility type in migration

* ci: update workflows 1.4.5 for mkdocs --dirty
  • Loading branch information
spwoodcock authored Jan 23, 2024
1 parent 17ae34d commit 0925773
Show file tree
Hide file tree
Showing 15 changed files with 96 additions and 94 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/build_and_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ on:

jobs:
pytest:
uses: hotosm/gh-workflows/.github/workflows/test_compose.yml@1.4.4
uses: hotosm/gh-workflows/.github/workflows/test_compose.yml@1.4.5
with:
image_name: ghcr.io/${{ github.repository }}/backend
build_context: src/backend
Expand All @@ -29,20 +29,20 @@ jobs:
secrets: inherit

frontend-tests:
uses: hotosm/gh-workflows/.github/workflows/test_pnpm.yml@1.4.4
uses: hotosm/gh-workflows/.github/workflows/test_pnpm.yml@1.4.5
with:
working_dir: src/frontend

backend-build:
uses: hotosm/gh-workflows/.github/workflows/image_build.yml@1.4.4
uses: hotosm/gh-workflows/.github/workflows/image_build.yml@1.4.5
needs: [pytest]
with:
context: src/backend
build_target: prod
image_name: ghcr.io/${{ github.repository }}/backend

frontend-build:
uses: hotosm/gh-workflows/.github/workflows/image_build.yml@1.4.4
uses: hotosm/gh-workflows/.github/workflows/image_build.yml@1.4.5
needs: [frontend-tests]
with:
context: src/frontend
Expand Down Expand Up @@ -147,7 +147,7 @@ jobs:
needs:
- smoke-test-backend
- smoke-test-frontend
uses: hotosm/gh-workflows/.github/workflows/remote_deploy.yml@1.4.4
uses: hotosm/gh-workflows/.github/workflows/remote_deploy.yml@1.4.5
with:
environment: ${{ github.ref_name }}
docker_compose_file: "docker-compose.${{ github.ref_name }}.yml"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build_ci_img.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ on:

jobs:
backend-ci-build:
uses: hotosm/gh-workflows/.github/workflows/image_build.yml@1.4.4
uses: hotosm/gh-workflows/.github/workflows/image_build.yml@1.4.5
with:
context: src/backend
build_target: ci
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build_odk_imgs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:

jobs:
build-odkcentral:
uses: hotosm/gh-workflows/.github/workflows/image_build.yml@1.4.4
uses: hotosm/gh-workflows/.github/workflows/image_build.yml@1.4.5
with:
context: odkcentral/api
image_tags: |
Expand All @@ -26,7 +26,7 @@ jobs:
# multi_arch: true

build-odkcentral-ui:
uses: hotosm/gh-workflows/.github/workflows/image_build.yml@1.4.4
uses: hotosm/gh-workflows/.github/workflows/image_build.yml@1.4.5
with:
context: odkcentral/ui
image_tags: |
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/build_proxy_imgs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:

jobs:
build-cert-init-main:
uses: hotosm/gh-workflows/.github/workflows/image_build.yml@1.4.4
uses: hotosm/gh-workflows/.github/workflows/image_build.yml@1.4.5
with:
context: nginx
build_target: certs-init-main
Expand All @@ -21,7 +21,7 @@ jobs:
multi_arch: true

build-cert-init-dev:
uses: hotosm/gh-workflows/.github/workflows/image_build.yml@1.4.4
uses: hotosm/gh-workflows/.github/workflows/image_build.yml@1.4.5
with:
context: nginx
build_target: certs-init-development
Expand All @@ -33,7 +33,7 @@ jobs:
multi_arch: true

build-proxy-main:
uses: hotosm/gh-workflows/.github/workflows/image_build.yml@1.4.4
uses: hotosm/gh-workflows/.github/workflows/image_build.yml@1.4.5
with:
context: nginx
build_target: main
Expand All @@ -44,7 +44,7 @@ jobs:
multi_arch: true

build-proxy-dev:
uses: hotosm/gh-workflows/.github/workflows/image_build.yml@1.4.4
uses: hotosm/gh-workflows/.github/workflows/image_build.yml@1.4.5
with:
context: nginx
build_target: development
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ on:

jobs:
build_doxygen:
uses: hotosm/gh-workflows/.github/workflows/doxygen_build.yml@1.4.4
uses: hotosm/gh-workflows/.github/workflows/doxygen_build.yml@1.4.5
with:
output_path: docs/apidocs

build_openapi_json:
uses: hotosm/gh-workflows/.github/workflows/openapi_build.yml@1.4.4
uses: hotosm/gh-workflows/.github/workflows/openapi_build.yml@1.4.5
with:
image: ghcr.io/${{ github.repository }}/backend:ci-${{ github.ref_name }}
example_env_file_path: ".env.example"
output_path: docs/openapi.json

publish_docs:
uses: hotosm/gh-workflows/.github/workflows/mkdocs_build.yml@1.4.4
uses: hotosm/gh-workflows/.github/workflows/mkdocs_build.yml@1.4.5
needs:
- build_doxygen
- build_openapi_json
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr_test_backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ on:

jobs:
pytest:
uses: hotosm/gh-workflows/.github/workflows/test_compose.yml@1.4.4
uses: hotosm/gh-workflows/.github/workflows/test_compose.yml@1.4.5
with:
image_name: ghcr.io/${{ github.repository }}/backend
build_context: src/backend
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr_test_frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ on:

jobs:
frontend-tests:
uses: hotosm/gh-workflows/.github/workflows/test_pnpm.yml@1.4.4
uses: hotosm/gh-workflows/.github/workflows/test_pnpm.yml@1.4.5
with:
working_dir: src/frontend
2 changes: 1 addition & 1 deletion .github/workflows/tag_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:

jobs:
backend-build:
uses: hotosm/gh-workflows/.github/workflows/image_build.yml@1.4.4
uses: hotosm/gh-workflows/.github/workflows/image_build.yml@1.4.5
with:
context: src/backend
build_target: prod
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests/test_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export TARGET_OVERRIDE=ci
# --var-file=.env --secret-file=.env

# Instead, run backend PyTest manually
docker compose build api
TAG_OVERRIDE=ci TARGET_OVERRIDE=ci docker compose build api
act pull_request -W .github/workflows/tests/pytest.yml \
-e .github/workflows/tests/pr_payload.json \
--var-file=.env --secret-file=.env
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/wiki.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ on:

jobs:
publish-docs-to-wiki:
uses: hotosm/gh-workflows/.github/workflows/wiki.yml@1.4.4
uses: hotosm/gh-workflows/.github/workflows/wiki.yml@1.4.5
with:
homepage_path: "wiki_redirect.md"
65 changes: 25 additions & 40 deletions src/backend/app/db/db_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
ProjectPriority,
ProjectRole,
ProjectStatus,
ProjectVisibility,
TaskAction,
TaskCreationMode,
TaskSplitType,
TaskStatus,
TeamVisibility,
Expand Down Expand Up @@ -178,16 +178,6 @@ class DbTeam(Base):
organisation = relationship(DbOrganisation, backref="teams")


# Secondary table defining many-to-many join for
# private projects that only defined users can map on
project_allowed_users = Table(
"project_allowed_users",
FmtmMetadata,
Column("project_id", Integer, ForeignKey("projects.id")),
Column("user_id", BigInteger, ForeignKey("users.id")),
)


class DbProjectTeams(Base):
"""Link table between teams and projects."""

Expand Down Expand Up @@ -432,9 +422,8 @@ class DbProject(Base):
)
author = relationship(DbUser, uselist=False, backref="user")
created = Column(DateTime, default=timestamp, nullable=False)
task_creation_mode = Column(
Enum(TaskCreationMode), default=TaskCreationMode.UPLOAD, nullable=False
)

task_split_type = Column(Enum(TaskSplitType), nullable=True)
# split_strategy = Column(Integer)
# grid_meters = Column(Integer)
# task_type = Column(Integer)
Expand All @@ -454,11 +443,14 @@ class DbProject(Base):
# GEOMETRY
outline = Column(Geometry("POLYGON", srid=4326))
# geometry = Column(Geometry("POLYGON", srid=4326, from_text='ST_GeomFromWkt'))
# TODO add outline_geojson as computed @property
centroid = Column(Geometry("POINT", srid=4326))

# PROJECT STATUS
last_updated = Column(DateTime, default=timestamp)
status = Column(Enum(ProjectStatus), default=ProjectStatus.DRAFT, nullable=False)
visibility = Column(
Enum(ProjectVisibility), default=ProjectVisibility.PUBLIC, nullable=False
)
total_tasks = Column(Integer)
# tasks_mapped = Column(Integer, default=0, nullable=False)
# tasks_validated = Column(Integer, default=0, nullable=False)
Expand Down Expand Up @@ -508,9 +500,6 @@ def tasks_bad(self):
)

# XFORM DETAILS
# TODO This field was probably replaced by odk_central_url
# TODO remove in a migration
odk_central_src = Column(String, default="")
xform_title = Column(String, ForeignKey("xlsforms.title", name="fk_xform"))
xform = relationship(DbXForm)

Expand All @@ -519,10 +508,6 @@ def tasks_bad(self):
{},
)

## ---------------------------------------------- ##
# FOR REFERENCE: OTHER ATTRIBUTES IN TASKING MANAGER
# PROJECT ACCESS
private = Column(Boolean, default=False) # Only allowed users can validate
mapper_level = Column(
Enum(MappingLevel),
default=MappingLevel.INTERMEDIATE,
Expand All @@ -537,31 +522,13 @@ def tasks_bad(self):
validation_permission = Column(
Enum(ValidationPermission), default=ValidationPermission.LEVEL
) # Means only users with validator role can validate
allowed_users = relationship(DbUser, secondary=project_allowed_users)
organisation_id = Column(
Integer,
ForeignKey("organisations.id", name="fk_organisations"),
index=True,
)
organisation = relationship(DbOrganisation, backref="projects")
# PROJECT DETAILS
due_date = Column(DateTime)
changeset_comment = Column(String)
osmcha_filter_id = Column(
String
) # Optional custom filter id for filtering on OSMCha
imagery = Column(String)
osm_preset = Column(String)
odk_preset = Column(String)
josm_preset = Column(String)
id_presets = Column(ARRAY(String))
extra_id_params = Column(String)
license_id = Column(Integer, ForeignKey("licenses.id", name="fk_licenses"))
# GEOMETRY
centroid = Column(Geometry("POINT", srid=4326))
# country = Column(ARRAY(String), default=[])
# FEEDBACK
project_chat = relationship(DbProjectChat, lazy="dynamic", cascade="all")

## Odk central server
odk_central_url = Column(String)
Expand All @@ -582,6 +549,24 @@ def tasks_bad(self):

hashtags = Column(ARRAY(String)) # Project hashtag

## ---------------------------------------------- ##
# FOR REFERENCE: OTHER ATTRIBUTES IN TASKING MANAGER
imagery = Column(String)
osm_preset = Column(String)
odk_preset = Column(String)
josm_preset = Column(String)
id_presets = Column(ARRAY(String))
extra_id_params = Column(String)
license_id = Column(Integer, ForeignKey("licenses.id", name="fk_licenses"))
# GEOMETRY
# country = Column(ARRAY(String), default=[])
# FEEDBACK
project_chat = relationship(DbProjectChat, lazy="dynamic", cascade="all")
osmcha_filter_id = Column(
String
) # Optional custom filter id for filtering on OSMCha
due_date = Column(DateTime)


# TODO: Add index on project geometry, tried to add in __table args__
# Index("idx_geometry", DbProject.geometry, postgresql_using="gist")
Expand Down
19 changes: 9 additions & 10 deletions src/backend/app/models/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,8 @@ class UserRole(IntEnum, Enum):
class ProjectRole(IntEnum, Enum):
"""Available roles assigned to a user for a specific project.
Invitation is required for a MAPPER to join a project.
All roles must be assigned by someone higher in the hierarchy:
- MAPPER = default for all (invitation required)
- MAPPER = default for all
- VALIDATOR = can validate the mappers output
- FIELD_MANAGER = can invite mappers and organise people
- ASSOCIATE_PROJECT_MANAGER = helps the project manager, cannot delete project
Expand Down Expand Up @@ -145,14 +144,6 @@ class ValidationPermission(IntEnum, Enum):
TEAMS_LEVEL = 3


class TaskCreationMode(IntEnum, Enum):
"""Enum to describe task creation mode."""

GRID = 0
ROADS = 1
UPLOAD = 2


class TaskStatus(IntEnum, Enum):
"""Enum describing available Task Statuses."""

Expand Down Expand Up @@ -287,3 +278,11 @@ class TaskSplitType(IntEnum, Enum):
DIVIDE_ON_SQUARE = 0
CHOOSE_AREA_AS_TASK = 1
TASK_SPLITTING_ALGORITHM = 2


class ProjectVisibility(IntEnum, Enum):
"""Enum describing task splitting type."""

PUBLIC = 0
PRIVATE = 1
INVITE_ONLY = 2
23 changes: 23 additions & 0 deletions src/backend/migrations/004-organisation-odk-creds.sql
Original file line number Diff line number Diff line change
@@ -1,14 +1,37 @@
-- ## Migration to:
-- * Add odk central credentials (str) to organisations table.
-- * Add the approved (bool) field to organisations table.
-- * Add the visibility type for project visibility level.
-- * Add the visibility field to projects table.

-- Start a transaction
BEGIN;

-- Add fields to organisations table
ALTER TABLE IF EXISTS public.organisations
ADD COLUMN IF NOT EXISTS approved BOOLEAN DEFAULT false,
ADD COLUMN IF NOT EXISTS odk_central_url VARCHAR,
ADD COLUMN IF NOT EXISTS odk_central_user VARCHAR,
ADD COLUMN IF NOT EXISTS odk_central_password VARCHAR;

-- Create visibility enum if it doesn't exist
DO $$
BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'projectvisibility') THEN
CREATE TYPE public.projectvisibility AS ENUM (
'PUBLIC',
'PRIVATE',
'INVITE_ONLY'
);
END IF;
END $$;
ALTER TYPE public.projectvisibility OWNER TO fmtm;

-- Add field to projects table
ALTER TABLE IF EXISTS public.projects
DROP COLUMN IF EXISTS private,
ADD COLUMN IF NOT EXISTS visibility public.projectvisibility
NOT NULL DEFAULT 'PUBLIC';

-- Commit the transaction
COMMIT;
Loading

0 comments on commit 0925773

Please sign in to comment.