directus icon indicating copy to clipboard operation
directus copied to clipboard

Prevent editing system collection fields

Open br41nslug opened this issue 9 months ago • 6 comments

image

Scope

What's changed:

Potential Risks / Drawbacks / Review Notes / Questions

  • ~Is this a breaking change? we're blocking edits on system fields however while you could do the edit it was not working as expected before.~

Fixes #24816, Closes NOW-963

br41nslug avatar Mar 11 '25 18:03 br41nslug

🦋 Changeset detected

Latest commit: cddc1591ece5e414a275ceed8dd788bb11000319

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 19 packages
Name Type
@directus/api Major
@directus/system-data Patch
directus Patch
@directus/utils Patch
@directus/composables Patch
@directus/env Patch
@directus/extensions-sdk Patch
@directus/extensions Patch
@directus/memory Patch
@directus/pressure Patch
@directus/storage-driver-azure Patch
@directus/storage-driver-cloudinary Patch
@directus/storage-driver-gcs Patch
@directus/storage-driver-s3 Patch
@directus/storage-driver-supabase Patch
@directus/themes Patch
@directus/validation Patch
create-directus-extension Patch
@directus/extensions-registry Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

changeset-bot[bot] avatar Mar 11 '25 18:03 changeset-bot[bot]

Setting back to draft to see if we can prevent duplicate system records from being created in the directus_fields table

br41nslug avatar Mar 13 '25 16:03 br41nslug

We should also add blackbox tests to cover this to ensure no regressions

ComfortablyCoding avatar Mar 17 '25 20:03 ComfortablyCoding

Tests

  • [x] Expect to be able to create non system field
  • [x] Expect to be able to update schema of non system field
  • [x] Expect to be able to delete non system field
  • [x] Expect to be denied/receive error if attempt to delete system field
  • [x] Expect to be denied/receive error if attempt to update any data aside from schemas is_indexed field of a system
    • [x] send meta
    • [x] send schema with field that is NOT is_indexed
  • [x] Expect to able to update is_indexed for system field
  • [x] Expect setting is_indexed to true for system field indexes the field
  • [x] Expect the above REST calls to result in the same behaviour for batch equivalents
  • [x] Expect snapshots to work as previous
  • [x] Expect is_indexed to show up for system fields if changed
    • [x] FAIL, see https://github.com/directus/directus/pull/24820#pullrequestreview-2753691675
    • [x] Left testing this to https://github.com/directus/directus/pull/25127
  • [x] Expect the above REST calls to result in the same behaviour for GQL
    • [x] FAIL, updateFields fails with valid schema change on system field (FIXED 9ce9818)
 mutation update_fields_item {
 update_fields_item(
   collection: "directus_comments"
   field: "collection"
   data: {schema: {is_indexed: true}}
 ){
   collection
 }
}
  • [x] FAIL, updateFields fails with invalid schema change on system fields throws INTERNAL SERVER ERROR due to unrecognized error (FIXED b6cfadb)
mutation update_fields_item {
  update_fields_item(
    collection: "directus_comments"
    field: "collection"
    data: {schema: {is_unique: true}}
  ){
    collection
  }
}
{
  "data": {
    "update_fields_item": null
  },
  "errors": [
    {
      "message": "Unexpected error value: [{ name: \"DirectusError\", extensions: [Object], code: \"INVALID_PAYLOAD\", status: 400 }]",
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR"
      },
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "update_fields_item"
      ]
    }
  ]
}

ComfortablyCoding avatar Mar 26 '25 20:03 ComfortablyCoding

Moved back to draft so we can merge all related PRs at the same time

ComfortablyCoding avatar Jun 13 '25 14:06 ComfortablyCoding

Updated the error formatting in graphql to now output this instead: image

br41nslug avatar Jun 16 '25 18:06 br41nslug

Codecov Report

:x: Patch coverage is 42.55319% with 27 lines in your changes missing coverage. Please review. :white_check_mark: Project coverage is 57.60%. Comparing base (d58faf6) to head (a2089b1). :warning: Report is 1 commits behind head on main.

:x: Your patch status has failed because the patch coverage (42.55%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #24820      +/-   ##
==========================================
- Coverage   57.61%   57.60%   -0.01%     
==========================================
  Files        2047     2039       -8     
  Lines      129140   129142       +2     
  Branches     7034     7019      -15     
==========================================
- Hits        74407    74397      -10     
- Misses      54733    54745      +12     
Flag Coverage Δ
api 38.98% <42.55%> (+<0.01%) :arrow_up:
app 70.37% <ø> (ø)
composables 82.80% <ø> (ø)
create-directus-extension 94.44% <ø> (ø)
create-directus-project 98.43% <ø> (ø)
env 99.66% <ø> (ø)
errors 97.47% <ø> (ø)
extensions 35.63% <ø> (ø)
extensions-registry 95.27% <ø> (ø)
extensions-sdk 14.38% <ø> (ø)
format-title 100.00% <ø> (ø)
memory 95.75% <ø> (ø)
pressure 77.63% <ø> (ø)
random ?
release-notes-generator 81.14% <ø> (ø)
schema-builder 80.56% <ø> (ø)
sdk 8.33% <ø> (ø)
storage 92.00% <ø> (ø)
storage-driver-azure 76.76% <ø> (ø)
storage-driver-cloudinary 81.14% <ø> (ø)
storage-driver-gcs 69.72% <ø> (ø)
storage-driver-local 69.76% <ø> (ø)
storage-driver-s3 46.73% <ø> (ø)
storage-driver-supabase 68.20% <ø> (ø)
update-check 55.67% <ø> (ø)
utils 87.16% <ø> (ø)
validation 44.50% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov[bot] avatar Jul 23 '25 13:07 codecov[bot]