Commit graph

12 commits

Author SHA1 Message Date
Miguel de la Cruz
48f2fd0873
Merge the Integrated Boards MVP feature branch (#35796)
* Add CreatedBy and UpdatedBy to the properties fields and values (#34485)

* Add CreatedBy and UpdatedBy to the properties fields and values

* Fix types

---------

Co-authored-by: Miguel de la Cruz <miguel@ctrlz.es>

* Adds ObjectType to the property fields table (#34908)

Co-authored-by: Miguel de la Cruz <miguel@ctrlz.es>

* Update ObjectType migration setting an empty value and marking the column as not null (#34915)

Co-authored-by: Miguel de la Cruz <miguel@ctrlz.es>

* Adds uniqueness mechanisms to the property fields (#35058)

* Adds uniqueness mechanisms to the property fields

After adding ObjectType, this commit ensures that both the PSAv1 and
PSAv2 schemas are supported, and enforces property uniqueness through
both database indexes and a logical check when creating new property
fields.

* Adds uniqueness check to property updates

Updates are covered on this commit and we refactor as well the SQL
code to use the squirrel builder and work better with the conditional
addition of the `existingID` piece of the query.

* Add translations to error messages

* Fixing retrylayer mocks

* Remove retrylayer duplication

* Address review comments

* Fix comment to avoid linter issues

* Address PR comments

* Update server/channels/db/migrations/postgres/000157_add_object_type_to_property_fields.down.sql

Co-authored-by: Alejandro García Montoro <alejandro.garciamontoro@gmail.com>

* Update server/channels/db/migrations/postgres/000157_add_object_type_to_property_fields.up.sql

Co-authored-by: Alejandro García Montoro <alejandro.garciamontoro@gmail.com>

* Update server/channels/db/migrations/postgres/000157_add_object_type_to_property_fields.up.sql

Co-authored-by: Alejandro García Montoro <alejandro.garciamontoro@gmail.com>

* Update field validation to check only for valid target types

* Update migrations to avoid concurrent index creation within a transaction

* Update migrations to make all index ops concurrent

* Update tests to use valid PSAv2 property fields

* Adds a helper for valid PSAv2 TargetTypes

---------

Co-authored-by: Miguel de la Cruz <miguel@ctrlz.es>
Co-authored-by: Alejandro García Montoro <alejandro.garciamontoro@gmail.com>

* Fix property tests (#35388)

Co-authored-by: Miguel de la Cruz <miguel@ctrlz.es>

* Adds Integrated Boards feature flag (#35378)

Co-authored-by: Miguel de la Cruz <miguel@ctrlz.es>

* Adds Integrated Boards MVP API changes (#34822)

This PR includes the necessary changes for channels and posts
endpoints and adds a set of generic endpoints to retrieve and manage
property fields and values following the new Property System approach.

Co-authored-by: Miguel de la Cruz <miguel@ctrlz.es>
Co-authored-by: Mattermost Build <build@mattermost.com>

* Property System Architecture permissions for v2 (#35113)

* Adds uniqueness mechanisms to the property fields

After adding ObjectType, this commit ensures that both the PSAv1 and
PSAv2 schemas are supported, and enforces property uniqueness through
both database indexes and a logical check when creating new property
fields.

* Adds uniqueness check to property updates

Updates are covered on this commit and we refactor as well the SQL
code to use the squirrel builder and work better with the conditional
addition of the `existingID` piece of the query.

* Add translations to error messages

* Add the permissions to the migrations, model and update the store calls

* Adds the property field and property group app layer

* Adds authorization helpers for property fields and values

* Make sure that users cannot lock themselves out of property fields

* Migrate permissions from a JSON column to three normalized columns

* Remove the audit comment

* Use target level constants in authorization

* Log authorization membership failures

* Rename admin to sysadmin

* Fix i18n sorting

---------

Co-authored-by: Miguel de la Cruz <miguel@ctrlz.es>

* Add Views store and app layer (#35361)

* Add Views store and app layer for Integrated Boards

Implements the View entity (model, SQL store, service, app) as described
in the Integrated Boards tech spec. Views are channel-scoped board
configurations with typed props (board, kanban subviews) and soft-delete.

- public/model: View, ViewBoardProps, Subview, ViewPatch types with
  PreSave/PreUpdate/IsValid/Patch/Clone/Auditable
- Migration 158: Views table with jsonb Props column and indexes
- SqlViewStore: CRUD with nil-safe Props marshaling (AppendBinaryFlag)
- ViewService: CreateView seeds default kanban subview and links the
  boards property field; caches boardPropertyFieldID at startup
- App layer: CreateView/GetView/GetViewsForChannel/UpdateView/DeleteView
  with channel-membership permission checks and WebSocket events
  (view_created, view_updated, view_deleted)
- doSetupBoardsPropertyField: registers the Boards property group and
  board field in NewServer() before ViewService construction
- GetFieldByName now returns store.ErrNotFound instead of raw sql.ErrNoRows

* Move permission checks out of App layer for views

- Remove HasPermissionToChannel calls from all App view methods
- Drop userID params from GetView, GetViewsForChannel, UpdateView, DeleteView
- Fix doSetupBoardsPropertyField to include required TargetType for PSAv2 field

* Make View service generic and enforce board validation in model

- Remove board-specific auto-setup from service and server startup
- Enforce that board views require Props, at least one subview, and at least one linked property in IsValid()
- Move default subview seeding out of app layer; callers must provide valid props
- Call PreSave on subviews during PreUpdate to assign IDs to new subviews
- Update all tests to reflect the new validation requirements

* Restore migrations files to match base branch

* Distinguish ErrNotFound from other errors in view store Get

* Use CONCURRENTLY and nontransactional for index operations in views migration

* Split views index creation into separate nontransactional migrations

* Update migrations.list

* Update i18n translations for views

* Fix makeView helper to include required Props for board view validation

* Rename ctx parameter from c to rctx in OAuthProvider mock

* Remove views service layer, call store directly from app

* Return 500 for unexpected DB errors in GetView, 404 only for not-found

* Harden View model: deep-copy Props, validate linked property IDs

- Add ViewBoardProps.Clone() to deep-copy LinkedProperties and Subviews
- Use it in View.Clone() and View.Patch() to prevent shared-slice aliasing
- Iterate over LinkedProperties in View.IsValid() and reject invalid IDs
  with a dedicated i18n key
- Register ViewStore in storetest AssertExpectations so mock expectations
  are enforced
- Add tests covering all new behaviours

* Restore autotranslation worker_stopped i18n translation

* Fix view store test IDs and improve error handling in app layer

- Use model.NewId() for linked property IDs in testUpdateView to fix
  validation failure (IsValid rejects non-UUID strings)
- Fix import grouping in app/view.go (stdlib imports in one block)
- Return 404 instead of 500 when Update/Delete store calls return
  ErrNotFound (e.g. concurrent deletion TOCTOU race)

* Add View store mock to retrylayer test genStore helper

The View store was added to the store interface but the genStore()
helper in retrylayer_test.go was not updated, causing TestRetry to panic.
Also removes the duplicate Recap mock registration.

* Refactor view deletion and websocket event handling; update SQL store methods to use query builder

* revert property field store

* Remove useless migrations

* Add cursor-based pagination to View store GetForChannel

- Add ViewQueryCursor and ViewQueryOpts types with validation
- Return (views, cursor, error) for caller-driven pagination
- PerPage clamping: <=0 defaults to 20, >200 clamps to 200
- Support IncludeDeleted filter
- Add comprehensive store tests for pagination, cursor edge cases,
  PerPage clamping, and invalid input rejection
- Add app layer test for empty channelID → 400
- Update interface, retrylayer, timerlayer, and mock signatures

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Refactor test loops in ViewStore tests for improved readability

* change pagination to limit/offset

* Add upper-bound limits on View Subviews and LinkedProperties

Defense-in-depth validation: cap Subviews at 50 and LinkedProperties
at 500 to prevent abuse below the 300KB payload limit.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>

* MM-67388, MM-66528, MM-67750: Add View REST API endpoints, websocket events, and sort order (#35442)

* Add Views store and app layer for Integrated Boards

Implements the View entity (model, SQL store, service, app) as described
in the Integrated Boards tech spec. Views are channel-scoped board
configurations with typed props (board, kanban subviews) and soft-delete.

- public/model: View, ViewBoardProps, Subview, ViewPatch types with
  PreSave/PreUpdate/IsValid/Patch/Clone/Auditable
- Migration 158: Views table with jsonb Props column and indexes
- SqlViewStore: CRUD with nil-safe Props marshaling (AppendBinaryFlag)
- ViewService: CreateView seeds default kanban subview and links the
  boards property field; caches boardPropertyFieldID at startup
- App layer: CreateView/GetView/GetViewsForChannel/UpdateView/DeleteView
  with channel-membership permission checks and WebSocket events
  (view_created, view_updated, view_deleted)
- doSetupBoardsPropertyField: registers the Boards property group and
  board field in NewServer() before ViewService construction
- GetFieldByName now returns store.ErrNotFound instead of raw sql.ErrNoRows

* Move permission checks out of App layer for views

- Remove HasPermissionToChannel calls from all App view methods
- Drop userID params from GetView, GetViewsForChannel, UpdateView, DeleteView
- Fix doSetupBoardsPropertyField to include required TargetType for PSAv2 field

* Make View service generic and enforce board validation in model

- Remove board-specific auto-setup from service and server startup
- Enforce that board views require Props, at least one subview, and at least one linked property in IsValid()
- Move default subview seeding out of app layer; callers must provide valid props
- Call PreSave on subviews during PreUpdate to assign IDs to new subviews
- Update all tests to reflect the new validation requirements

* Restore migrations files to match base branch

* Distinguish ErrNotFound from other errors in view store Get

* Use CONCURRENTLY and nontransactional for index operations in views migration

* Split views index creation into separate nontransactional migrations

* Update migrations.list

* Update i18n translations for views

* Fix makeView helper to include required Props for board view validation

* Rename ctx parameter from c to rctx in OAuthProvider mock

* Remove views service layer, call store directly from app

* Return 500 for unexpected DB errors in GetView, 404 only for not-found

* Harden View model: deep-copy Props, validate linked property IDs

- Add ViewBoardProps.Clone() to deep-copy LinkedProperties and Subviews
- Use it in View.Clone() and View.Patch() to prevent shared-slice aliasing
- Iterate over LinkedProperties in View.IsValid() and reject invalid IDs
  with a dedicated i18n key
- Register ViewStore in storetest AssertExpectations so mock expectations
  are enforced
- Add tests covering all new behaviours

* Restore autotranslation worker_stopped i18n translation

* Fix view store test IDs and improve error handling in app layer

- Use model.NewId() for linked property IDs in testUpdateView to fix
  validation failure (IsValid rejects non-UUID strings)
- Fix import grouping in app/view.go (stdlib imports in one block)
- Return 404 instead of 500 when Update/Delete store calls return
  ErrNotFound (e.g. concurrent deletion TOCTOU race)

* Add View store mock to retrylayer test genStore helper

The View store was added to the store interface but the genStore()
helper in retrylayer_test.go was not updated, causing TestRetry to panic.
Also removes the duplicate Recap mock registration.

* Refactor view deletion and websocket event handling; update SQL store methods to use query builder

* revert property field store

* Add View API endpoints with OpenAPI spec, client methods, and i18n

Implement REST API for channel views (board-type) behind the
IntegratedBoards feature flag. Adds CRUD endpoints under
/api/v4/channels/{channel_id}/views with permission checks
matching the channel bookmark pattern.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Remove useless migrations

* Add cursor-based pagination to View store GetForChannel

- Add ViewQueryCursor and ViewQueryOpts types with validation
- Return (views, cursor, error) for caller-driven pagination
- PerPage clamping: <=0 defaults to 20, >200 clamps to 200
- Support IncludeDeleted filter
- Add comprehensive store tests for pagination, cursor edge cases,
  PerPage clamping, and invalid input rejection
- Add app layer test for empty channelID → 400
- Update interface, retrylayer, timerlayer, and mock signatures

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Add cursor-based pagination to View API for channel views

* Enhance cursor handling in getViewsForChannel and update tests for pagination

* Refactor test loops in ViewStore tests for improved readability

* Refactor loop in TestGetViewsForChannel for improved readability

* change pagination to limit/offset

* switch to limit/offset pagination

* Add upper-bound limits on View Subviews and LinkedProperties

Defense-in-depth validation: cap Subviews at 50 and LinkedProperties
at 500 to prevent abuse below the 300KB payload limit.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Add view sort order API endpoint

Add POST /api/v4/channels/{channel_id}/views/{view_id}/sort_order
endpoint following the channel bookmarks reorder pattern. Includes
store, app, and API layers with full test coverage at each layer.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Add connectionId to view WebSocket events and sort_order API spec

Thread connectionId from request header through all view handlers
(create, update, delete, sort_order) to WebSocket events, matching
the channel bookmarks pattern. Add sort_order endpoint to OpenAPI
spec. Update minimum server version to 11.6.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Remove duplicate View/ViewPatch definitions from definitions.yaml

The merge from integrated-boards-mvp introduced duplicate View and
ViewPatch schema definitions that were already defined earlier in
the file with more detail (including ViewBoardProps ref and enums).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Update minimum server version to 11.6 in views API spec

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Add missing translations for view sort order error messages

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Merge integrated-boards-mvp into ibmvp_api-views; remove spec files

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Fix flaky TestViewStore timestamp test on CI

Add sleep before UpdateSortOrder to ensure timestamps differ,
preventing same-millisecond comparisons on fast CI machines.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* remove duplicate views.yaml imclude

* Use c.boolString() for include_deleted query param in GetViewsForChannel

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Fix views.yaml sort order schema: use integer type and require body

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Refactor view sort order tests to use named IDs instead of array indices

Extract idA/idB/idC from views slice and add BEFORE/AFTER comments
to make stateful subtest ordering easier to follow.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Return 404 instead of 403 for view operations on deleted channels

Deleted channels should appear non-existent to callers rather than
revealing their existence via a 403. Detailed error text explains
the context for debugging.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* add missing channel deleteat checks

* Use c.Params.Page instead of manual page query param parsing in getViewsForChannel

c.Params already validates and defaults page/per_page, so the manual
parsing was redundant.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Add support for total count in views retrieval

* Add tests for handling deleted views in GetViewsForChannel and GetView

* Short-circuit negative newIndex in UpdateSortOrder before opening transaction

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Add per-channel limit on views to bound UpdateSortOrder cost

Without a cap, unbounded view creation makes sort-order updates
increasingly expensive (CASE WHEN per view, row locks). Adds
MaxViewsPerChannel=50 constant and enforces it in the app layer
before saving. Includes API and app layer tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Remove include_deleted support from views API

Soft-deleted views are structural metadata with low risk, but no other
similar endpoint (e.g. channel bookmarks) exposes deleted records without
an admin gate. Rather than adding an admin-only permission check for
consistency, remove the feature entirely since there is no current use case.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Update view permissions to require `create_post` instead of channel management permissions

* Remove obsolete view management error messages for direct and group messages

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>

* feat(migrations): add user tracking and object type to property fields

- Introduced user tracking columns (CreatedBy, UpdatedBy) to PropertyFields and PropertyValues.
- Added ObjectType column to PropertyFields with associated unique indexes for legacy and typed properties.
- Created new migration scripts for adding and dropping these features, including necessary indexes for data integrity.
- Established views for managing property fields with new attributes.

This update enhances the schema to support better tracking and categorization of property fields.

* Add Property System Architecture v2 API endpoints (#35583)

* Adds uniqueness mechanisms to the property fields

After adding ObjectType, this commit ensures that both the PSAv1 and
PSAv2 schemas are supported, and enforces property uniqueness through
both database indexes and a logical check when creating new property
fields.

* Adds uniqueness check to property updates

Updates are covered on this commit and we refactor as well the SQL
code to use the squirrel builder and work better with the conditional
addition of the `existingID` piece of the query.

* Add translations to error messages

* Add the permissions to the migrations, model and update the store calls

* Adds the property field and property group app layer

* Adds authorization helpers for property fields and values

* Make sure that users cannot lock themselves out of property fields

* Migrate permissions from a JSON column to three normalized columns

* Remove the audit comment

* Use target level constants in authorization

* Log authorization membership failures

* Rename admin to sysadmin

* Adds the Property System Architecture v2 API endpoints

* Adds permission checks to the create field endpoint

* Add target access checks to value endpoints

* Add default branches for object_type and target_type and extra guards for cursor client4 methods

* Fix vet API mismatch

* Fix error checks

* Fix linter

* Add merge semantics for property patch logic and API endpoint

* Fix i18n

* Fix duplicated patch elements and early return on bad cursor

* Update docs to use enums

* Fix i18n sorting

* Update app layer to return model.AppError

* Adds a limit to the number of property values that can be patched in the same request

* Require target_type filter when searching property fields

* Add objectType validation as part of field.IsValid()

* Fix linter

* Fix test with bad objecttpye

* Fix test grouping

---------

Co-authored-by: Miguel de la Cruz <miguel@ctrlz.es>

* MM-67968: Flatten view model — remove icon, subviews, typed board props (#35726)

* feat(views): flatten view model by removing icon, subview, and board props

Simplifies the View data model as part of MM-67968: removes Icon, Subview,
and ViewBoardProps types; renames ViewTypeBoard to ViewTypeKanban; replaces
typed Props with StringInterface (map[string]any); adds migration 000167
to drop the Icon column from the Views table.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>

* feat(api): update views OpenAPI spec to reflect flattened model

Removes ViewBoardProps, Subview, and icon from the View and ViewPatch
schemas. Changes type enum from board to kanban. Replaces typed props
with a free-form StringInterface object. Aligns with MM-67968.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>

* refactor(views): simplify store by dropping dbView and marshalViewProps

StringInterface already implements driver.Valuer and sql.Scanner, so the
manual JSON marshal/unmarshal and the dbView intermediate struct were
redundant. model.View now scans directly from the database. Also removes
the dead ViewMaxLinkedProperties constant and wraps the Commit() error in
UpdateSortOrder.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>

* fix(api): allow arbitrary JSON in view props OpenAPI schema

The props field was restricted to string values via
additionalProperties: { type: string }, conflicting with the Go model's
StringInterface (map[string]any). Changed to additionalProperties: true
in View, ViewPatch, and inline POST schemas.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>

* Adds basic implementation of the generic redux store for PSAv2 (#35512)

* Adds basic implementation of the generic redux store for PSAv2

* Add created_by and updated_by to the test fixtures

* Make target_id, target_type and object_type mandatory

* Wrap getPropertyFieldsByIds and getPropertyValuesForTargetByFieldIds with createSelector

* Address PR comments

---------

Co-authored-by: Miguel de la Cruz <miguel@ctrlz.es>

* Adds websocket messages for the PSAv2 API events (#35696)

* Adds uniqueness mechanisms to the property fields

After adding ObjectType, this commit ensures that both the PSAv1 and
PSAv2 schemas are supported, and enforces property uniqueness through
both database indexes and a logical check when creating new property
fields.

* Adds uniqueness check to property updates

Updates are covered on this commit and we refactor as well the SQL
code to use the squirrel builder and work better with the conditional
addition of the `existingID` piece of the query.

* Add translations to error messages

* Add the permissions to the migrations, model and update the store calls

* Adds the property field and property group app layer

* Adds authorization helpers for property fields and values

* Make sure that users cannot lock themselves out of property fields

* Migrate permissions from a JSON column to three normalized columns

* Remove the audit comment

* Use target level constants in authorization

* Log authorization membership failures

* Rename admin to sysadmin

* Adds the Property System Architecture v2 API endpoints

* Adds permission checks to the create field endpoint

* Add target access checks to value endpoints

* Add default branches for object_type and target_type and extra guards for cursor client4 methods

* Fix vet API mismatch

* Fix error checks

* Fix linter

* Add merge semantics for property patch logic and API endpoint

* Fix i18n

* Fix duplicated patch elements and early return on bad cursor

* Update docs to use enums

* Fix i18n sorting

* Update app layer to return model.AppError

* Adds a limit to the number of property values that can be patched in the same request

* Adds websocket messages for the PSAv2 API events

* Add IsPSAv2 helper to the property field for clarity

* Add guard against nil returns on field deletion

* Add docs to the websocket endpoints

---------

Co-authored-by: Miguel de la Cruz <miguel@ctrlz.es>

* migrations: consolidate views migrations and reorder after master

- Merged 000165 (create Views) with 000167 (drop Icon) since Icon was never needed
- Renumbered branch migrations 159-166 → 160-167 so master's 000159 (deduplicate_policy_names) runs first
- Regenerated migrations.list

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Add API endpoint to retrieve posts for a specific view (#35604)

Automatic Merge

* Apply fixes after merge

* Return a more specific error from getting multiple fields

* Prevent getting broadcast params on field deletion if not needed

* Remove duplicated migration code

* Update property conflict code to always use master

* Adds nil guard when iterating on property fields

* Check that permission level is valid before getting rejected by the database

* Validate correctness on TargetID for PSAv2 fields

* Avoid PSAv1 using permissions or protected

* Fix test data after validation change

* Fix flaky search test

* Adds more posts for filter use cases to properly test exclusions

---------

Co-authored-by: Miguel de la Cruz <miguel@ctrlz.es>
Co-authored-by: Alejandro García Montoro <alejandro.garciamontoro@gmail.com>
Co-authored-by: Julien Tant <julien@craftyx.fr>
Co-authored-by: Mattermost Build <build@mattermost.com>
Co-authored-by: Julien Tant <785518+JulienTant@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-27 10:36:35 +01:00
David Krauser
1cfe3d92b6
[MM-66836] Integrate PropertyAccessService into API and app layers (#34818)
Updates all Custom Profile Attribute endpoints and app layer methods to pass caller user IDs through to the PropertyAccessService. This connects the access control service introduced in #34812 to the REST API, Plugin API, and internal app operations.

Also updates the OpenAPI spec to document the new field attributes (protected, source_plugin_id, access_mode) and adds notes about protected field restrictions.
2026-02-06 18:06:51 -05:00
Miguel de la Cruz
ef16fcfad2
Adds default values to the attrs of CPA fields and refactors the app layer (#34408)
* Adds default values to the attrs of CPA fields and refactors the app layer

* Fix mmctl tests

* Fix types and linter

* Fix model test

---------

Co-authored-by: Miguel de la Cruz <miguel@ctrlz.es>
Co-authored-by: Mattermost Build <build@mattermost.com>
2025-11-13 12:00:54 +01:00
Miguel de la Cruz
ac3d087d2d
Adds admin managed property fields (#33662)
* Adds admin managed property fields

* Fix linter

* Adds extra tests

* Update server/public/model/custom_profile_attributes.go

Co-authored-by: Caleb Roseland <caleb@calebroseland.com>

* Fix linter

---------

Co-authored-by: Miguel de la Cruz <miguel@ctrlz.es>
Co-authored-by: Caleb Roseland <caleb@calebroseland.com>
2025-08-22 12:33:20 +00:00
Miguel de la Cruz
2decc2ccdb
Prevent synced CPA values to be updated from the API (#30687)
* Prevents the API from updating synced CPA values

The patch functions for CPA values now accept a parameter that checks
if they should allow for synced values to be updated, and prevent
those updates if necessary

* Fix linter

* Fix parameter after merge

---------

Co-authored-by: Miguel de la Cruz <miguel@ctrlz.es>
Co-authored-by: Scott Bishel <scott.bishel@mattermost.com>
Co-authored-by: Mattermost Build <build@mattermost.com>
2025-04-30 18:43:05 +02:00
Miguel de la Cruz
3df7bfca88
Improves validation and sanitization for CPA fields and values (#30694)
This change automatically removes options and sync attributes when
sanitizing fields that don't support them. As per values, it returns
an error when the value for a text type field is longer than the 64
characters limit we're currently applying.

The PR fixes a bug on the create CPA field endpoint that was causing
the attrs of the CPAField not to be decoded correctly.

Co-authored-by: Miguel de la Cruz <miguel@ctrlz.es>
2025-04-16 16:04:30 +02:00
Saturn Abril
49d3a1f472
MM-62558 Add E2E tests for custom profile settings (#30722)
* add e2e tests for custom profile settings

* fix failed tests

* reorg folder and file convention, and add more details of the tests

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
2025-04-16 10:32:27 +08:00
Miguel de la Cruz
0c8e30da4d
Move the sanitization and validation of CPA values to the model (#30653)
* Move the sanitization and validation of CPA values to the model

* Fix CI

* Use proper IDs instead of strings

---------

Co-authored-by: Miguel de la Cruz <miguel@ctrlz.es>
Co-authored-by: Mattermost Build <build@mattermost.com>
2025-04-10 11:31:40 +02:00
Caleb Roseland
035b9ad402
MM-62696, MM-62697: CPA Ext. Types & Visibility in System Console (#30511)
* Squashed commit of the following:

commit 42ef1ff8c3
Merge: 4940da4326 c049748b88
Author: Mattermost Build <build@mattermost.com>
Date:   Fri Mar 14 21:15:22 2025 +0200

    Merge branch 'master' into MM-62695

commit 4940da4326
Author: Julien Tant <julien@craftyx.fr>
Date:   Fri Mar 14 12:14:45 2025 -0700

    manage error the same way property field and value do

commit cd9ec59026
Author: Julien Tant <julien@craftyx.fr>
Date:   Fri Mar 14 12:05:02 2025 -0700

    sanitize and validate

commit 2672e90b06
Author: Julien Tant <julien@craftyx.fr>
Date:   Fri Mar 14 12:02:20 2025 -0700

    use Len test method

commit d101950d65
Author: Julien Tant <julien@craftyx.fr>
Date:   Fri Mar 14 11:59:12 2025 -0700

    rearrange consts

commit ed1b8f66fb
Author: Julien Tant <julien@craftyx.fr>
Date:   Fri Mar 14 11:58:56 2025 -0700

    rename CPASortOrder method

commit d3bc303fa3
Author: Julien Tant <julien@craftyx.fr>
Date:   Fri Mar 14 11:54:24 2025 -0700

    rename CustomProfileAttributes in method to CPA

commit b2323d44a6
Author: Julien Tant <julien@craftyx.fr>
Date:   Fri Mar 14 11:54:02 2025 -0700

    Add SAML and LDAP attr

commit d411ae9da5
Author: Julien Tant <julien@craftyx.fr>
Date:   Wed Mar 12 11:58:21 2025 -0700

    i18n

commit 27bc74c714
Author: Julien Tant <julien@craftyx.fr>
Date:   Wed Mar 12 11:11:23 2025 -0700

    fix TestDeleteCPAField test

commit 0d77071225
Author: Julien Tant <julien@craftyx.fr>
Date:   Wed Mar 12 10:28:49 2025 -0700

    err->appErr

commit fe87a68caa
Author: Julien Tant <julien@craftyx.fr>
Date:   Wed Mar 12 10:22:13 2025 -0700

    i18n

commit 3b3ddf978f
Author: Julien Tant <julien@craftyx.fr>
Date:   Wed Mar 12 10:21:12 2025 -0700

    tests

commit 2f898bd53b
Author: Julien Tant <julien@craftyx.fr>
Date:   Tue Mar 11 15:09:12 2025 -0700

    add validation and tests

commit a8c20841af
Author: Julien Tant <julien@craftyx.fr>
Date:   Tue Mar 11 13:45:53 2025 -0700

    code style

commit 5bb3868b2c
Merge: a4180d5d8f 7c25de2cff
Author: Mattermost Build <build@mattermost.com>
Date:   Tue Mar 11 22:24:06 2025 +0200

    Merge branch 'master' into MM-62695

commit a4180d5d8f
Author: Julien Tant <julien@craftyx.fr>
Date:   Tue Feb 25 11:53:54 2025 -0700

    use CPAField

commit 988177024c
Author: Julien Tant (aider) <julien@craftyx.fr>
Date:   Tue Feb 25 10:52:47 2025 -0700

    refactor: Move validateCustomProfileAttributesField to Validate method on CPAField struct

commit 783e64472c
Author: Julien Tant <julien@craftyx.fr>
Date:   Tue Feb 25 10:52:45 2025 -0700

    refactor: Improve custom profile attributes field handling and validation

commit aee06af59c
Author: Julien Tant (aider) <julien@craftyx.fr>
Date:   Tue Feb 25 10:50:29 2025 -0700

    test: Add test case for CPA field with empty attributes

commit 7ab4455f9f
Author: Julien Tant <julien@craftyx.fr>
Date:   Tue Feb 25 10:50:28 2025 -0700

    refactor: Cleanup whitespace and remove empty Attrs in custom profile attributes test

commit dbdb47d758
Author: Julien Tant (aider) <julien@craftyx.fr>
Date:   Tue Feb 25 10:48:08 2025 -0700

    test: Add test case for property field with empty attributes

commit 43872e0693
Author: Julien Tant (aider) <julien@craftyx.fr>
Date:   Tue Feb 25 10:44:39 2025 -0700

    test: Add tests for NewCPAFieldFromPropertyField and CPAFieldToPropertyField

commit 335f6b5c89
Merge: 01f632db46 e8ef26196c
Author: Julien Tant <julien@craftyx.fr>
Date:   Tue Feb 25 10:05:43 2025 -0700

    Merge branch 'master' into MM-62695

commit 01f632db46
Author: Julien Tant <julien@craftyx.fr>
Date:   Thu Feb 13 19:16:33 2025 -0700

    removed unused i18n

commit 0214d7eb94
Merge: db0e371ca2 68c11e9ecb
Author: Julien Tant <julien@craftyx.fr>
Date:   Thu Feb 13 19:15:08 2025 -0700

    Merge remote-tracking branch 'origin/master' into MM-62695

commit db0e371ca2
Author: Julien Tant <julien@craftyx.fr>
Date:   Thu Feb 13 19:05:58 2025 -0700

    generic options

commit 3cd62774a1
Merge: d95e5d9838 41e0f97176
Author: Julien Tant <julien@craftyx.fr>
Date:   Thu Feb 13 10:48:47 2025 -0700

    Merge remote-tracking branch 'origin/master' into MM-62695

commit d95e5d9838
Author: Julien Tant <julien@craftyx.fr>
Date:   Wed Feb 12 17:07:28 2025 -0700

    style

commit 2256076ed1
Author: Julien Tant (aider) <julien@craftyx.fr>
Date:   Wed Feb 12 17:06:22 2025 -0700

    refactor: Make color field optional in custom profile attributes

commit 7382b8ecb3
Author: Julien Tant <julien@craftyx.fr>
Date:   Wed Feb 12 16:40:10 2025 -0700

    fix api test

commit a54c2d653f
Author: Julien Tant <julien@craftyx.fr>
Date:   Wed Feb 12 16:02:27 2025 -0700

    lint

commit 9d2e3f78f6
Author: Julien Tant <julien@craftyx.fr>
Date:   Wed Feb 12 15:50:31 2025 -0700

    use custom types rather than string

commit 4624df52cb
Author: Julien Tant (aider) <julien@craftyx.fr>
Date:   Wed Feb 12 15:40:52 2025 -0700

    refactor: Use consistent "ValidateCPAField" in error messages for custom profile attributes

commit 42716170b7
Author: Julien Tant <julien@craftyx.fr>
Date:   Wed Feb 12 15:36:04 2025 -0700

    fix casing in custom profilte attributes test

commit bcca3d87c4
Author: Julien Tant (aider) <julien@craftyx.fr>
Date:   Wed Feb 12 15:33:26 2025 -0700

    refactor: Modify CustomProfileAttributesSelectOption to use lowercase JSON keys

commit 861e12c1fc
Author: Julien Tant <julien@craftyx.fr>
Date:   Wed Feb 12 15:29:23 2025 -0700

    i18n

commit a44f6f40eb
Author: Julien Tant <julien@craftyx.fr>
Date:   Wed Feb 12 15:21:08 2025 -0700

    improve test

commit b2f002016f
Author: Julien Tant (aider) <julien@craftyx.fr>
Date:   Wed Feb 12 15:10:00 2025 -0700

    test: Add test case for preserving option IDs when patching select field

commit aac155ef23
Author: Julien Tant <julien@craftyx.fr>
Date:   Wed Feb 12 15:04:18 2025 -0700

    don't do validation in constructor

commit a88c092768
Author: Julien Tant (aider) <julien@craftyx.fr>
Date:   Wed Feb 12 15:00:10 2025 -0700

    feat: Enhance ID validation and trimming in custom profile attributes

commit b6fb5f274a
Author: Julien Tant (aider) <julien@craftyx.fr>
Date:   Wed Feb 12 14:57:24 2025 -0700

    test: Add test cases for preserving IDs in custom profile attributes

commit bbb7f3e261
Author: Julien Tant (aider) <julien@craftyx.fr>
Date:   Wed Feb 12 14:56:15 2025 -0700

    refactor: Update CustomProfileAttributesSelectOption constructor to prioritize ID parameter

commit dbd1728a14
Author: Julien Tant <julien@craftyx.fr>
Date:   Wed Feb 12 14:50:14 2025 -0700

    feat: Add validation for custom profile attributes fields

commit e87689571b
Author: Julien Tant (aider) <julien@craftyx.fr>
Date:   Wed Feb 12 14:44:15 2025 -0700

    test: Add comprehensive test for NewCustomProfileAttributesSelectOptionFromMap

commit a2292d44ff
Author: Julien Tant (aider) <julien@craftyx.fr>
Date:   Wed Feb 12 14:43:14 2025 -0700

    feat: Add support for lowercase and title case keys in custom profile attributes map

commit 47ca184876
Author: Julien Tant <julien@craftyx.fr>
Date:   Wed Feb 12 14:43:12 2025 -0700

    fix: Update custom profile attributes map keys to use capitalized names

commit e8de7dfc6d
Author: Julien Tant (aider) <julien@craftyx.fr>
Date:   Wed Feb 12 14:01:31 2025 -0700

    feat: Add comprehensive test cases for custom profile attributes field validation

commit e798a53170
Author: Julien Tant <julien@craftyx.fr>
Date:   Wed Feb 12 13:56:25 2025 -0700

    add default visibility

commit e54ea2ba2f
Author: Julien Tant <julien@craftyx.fr>
Date:   Wed Feb 12 13:22:04 2025 -0700

    fix tests

commit db1839a6e9
Author: Julien Tant (aider) <julien@craftyx.fr>
Date:   Wed Feb 12 13:18:51 2025 -0700

    feat: Add index number to validation error messages in custom profile attributes

commit 35e29a0dfd
Author: Julien Tant <julien@craftyx.fr>
Date:   Wed Feb 12 13:18:49 2025 -0700

    refactor: Add validation and creation methods for custom profile attributes

commit eac47527d2
Author: Julien Tant (aider) <julien@craftyx.fr>
Date:   Wed Feb 12 12:49:00 2025 -0700

    feat: Add validation to prevent empty custom profile attribute options

commit 1baece68f9
Author: Julien Tant <julien@craftyx.fr>
Date:   Wed Feb 12 12:48:36 2025 -0700

    refactor: Rename NewCustomProfileAttributeSelectOption to NewCustomProfileAttributesSelectOption

commit 43710b018a
Author: Julien Tant (aider) <julien@craftyx.fr>
Date:   Wed Feb 12 12:46:43 2025 -0700

    refactor: Replace map[string]bool with map[string]struct{} for key existence check

commit 3263b04478
Author: Julien Tant (aider) <julien@craftyx.fr>
Date:   Wed Feb 12 12:46:06 2025 -0700

    feat: Add IsValid method to validate CustomProfileAttributesSelectOptions

commit 4531710f56
Author: Julien Tant <julien@craftyx.fr>
Date:   Wed Feb 12 12:46:04 2025 -0700

    refactor: Fix typo in custom profile attributes select option function name

commit c1c821275c
Author: Julien Tant <julien@craftyx.fr>
Date:   Wed Feb 12 12:42:50 2025 -0700

    gofmt

commit 328c898a3f
Author: Julien Tant (aider) <julien@craftyx.fr>
Date:   Wed Feb 12 12:41:14 2025 -0700

    refactor: Trim spaces from name and color in custom profile attribute select option constructor

commit b924431499
Author: Julien Tant <julien@craftyx.fr>
Date:   Wed Feb 12 12:41:12 2025 -0700

    feat: Add custom profile attributes model with validation and constants

commit 463ad161c5
Author: Julien Tant (aider) <julien@craftyx.fr>
Date:   Wed Feb 12 12:40:19 2025 -0700

    test: Add unit tests for custom profile attributes select options

* sort_order int temp

* name, type menu, dot menu

* values add/remove

* disabled when deleted

* - max length
- full height
- validate options
- clear attrs.options when not select/multiselect

* Revert "sort_order int temp"

This reverts commit ed675983c2.

* Revert "Squashed commit of the following:"

This reverts commit faf8b01169.

* field values test

* test type menu

* test table

* fix dot menu item id

* test delete modal

* test dot menu

* fix system_properties test

* fix user_properties_utils tests

* fix attr sort_order type

* i18n

* fix lint

* fix test types

* lint scss

* disable email type

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
2025-04-02 13:46:28 -05:00
Julien Tant
cb89e5646e
[MM-62695] Extend property types for CPA (#30201)
* test: Add unit tests for custom profile attributes select options

* feat: Add custom profile attributes model with validation and constants

* refactor: Trim spaces from name and color in custom profile attribute select option constructor

* gofmt

* refactor: Fix typo in custom profile attributes select option function name

* feat: Add IsValid method to validate CustomProfileAttributesSelectOptions

* refactor: Replace map[string]bool with map[string]struct{} for key existence check

* refactor: Rename NewCustomProfileAttributeSelectOption to NewCustomProfileAttributesSelectOption

* feat: Add validation to prevent empty custom profile attribute options

* refactor: Add validation and creation methods for custom profile attributes

* feat: Add index number to validation error messages in custom profile attributes

* fix tests

* add default visibility

* feat: Add comprehensive test cases for custom profile attributes field validation

* fix: Update custom profile attributes map keys to use capitalized names

* feat: Add support for lowercase and title case keys in custom profile attributes map

* test: Add comprehensive test for NewCustomProfileAttributesSelectOptionFromMap

* feat: Add validation for custom profile attributes fields

* refactor: Update CustomProfileAttributesSelectOption constructor to prioritize ID parameter

* test: Add test cases for preserving IDs in custom profile attributes

* feat: Enhance ID validation and trimming in custom profile attributes

* don't do validation in constructor

* test: Add test case for preserving option IDs when patching select field

* improve test

* i18n

* refactor: Modify CustomProfileAttributesSelectOption to use lowercase JSON keys

* fix casing in custom profilte attributes test

* refactor: Use consistent "ValidateCPAField" in error messages for custom profile attributes

* use custom types rather than string

* lint

* fix api test

* refactor: Make color field optional in custom profile attributes

* style

* generic options

* removed unused i18n

* test: Add tests for NewCPAFieldFromPropertyField and CPAFieldToPropertyField

* test: Add test case for property field with empty attributes

* refactor: Cleanup whitespace and remove empty Attrs in custom profile attributes test

* test: Add test case for CPA field with empty attributes

* refactor: Improve custom profile attributes field handling and validation

* refactor: Move validateCustomProfileAttributesField to Validate method on CPAField struct

* use CPAField

* code style

* add validation and tests

* tests

* i18n

* err->appErr

* fix TestDeleteCPAField test

* i18n

* Add SAML and LDAP attr

* rename CustomProfileAttributes in method to CPA

* rename CPASortOrder method

* rearrange consts

* use Len test method

* sanitize and validate

* manage error the same way property field and value do

* fix: Update test error ID for custom profile attributes validation

* test: Update error ID expectations in custom profile attributes tests

* refactor: Convert CPAAttrs.SortOrder from string to int

* json uses float64

* feat: Add length validation for custom profile attribute option name and color

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
2025-03-20 18:47:40 +00:00
Caleb Roseland
2182b1eaf9
MM-62548: CPA Reordering - drag and drop (#30097) 2025-02-13 17:09:35 -06:00
Miguel de la Cruz
ca34c6a03f
Custom profile attributes field endpoints (#29662)
* Adds the main Property System Architecture components

This change adds the necessary migrations for the Property Groups,
Fields and Values tables to be created, the store layer and a Property
Service that can be used from the app layer.

* Adds Custom Profile Attributes endpoints and app layer

* implement get and patch cpa values

* run i18n-extract

* Update property field type to use user instead of person

* Update PropertyFields to allow for unique nondeleted fields and remove redundant indexes

* Update PropertyValues to allow for unique nondeleted fields and remove redundant indexes

* Use StringMap instead of the map[string]any on property fields

* Add i18n strings

* Revert "Use StringMap instead of the map[string]any on property fields"

This reverts commit e2735ab0f8.

* Cast JSON binary data to string and add todo note for StringMap use

* Add mocks to the retrylayer tests

* Cast JSON binary data to string in property value store

* Check for binary parameter instead of casting to string for JSON data

* Fix bad merge

* Check property field type is one of the allowed ones

* Avoid reusing err variable to be explicit about the returned value

* Merge Property System Migrations into one file

* Adds NOT NULL to timestamps at the DB level

* Update stores to use tableSelectQuery instead of a slice var

* Update PropertyField model translations to be more explicit and avoid repetition

* Update PropertyValue model translations to be more explicit and avoid repetition

* Use ExecBuilder instead of ToSql&Exec

* Update property field errors to add context

* Ensure PerPage is greater than zero

* Update store errors to give more context

* Use ExecBuilder in the property stores where possible

* Add an on conflict suffix to the group register to avoid race conditions

* Remove user profile API documentation changes

* Update patchCPAValues endpoint and docs to return the updated information

* Merge two similar error conditions

* Use a route function for ListCPAValues

* Remove badly used translation string

* Remove unused get in register group method

* Adds input sanitization and validation to the CPA API endpoints

* Takes login outside of one test case to make it clear it affects multiple t.Runs

* Fix wrap error and return code when property field has been deleted

* Fix receiver name

* Adds comment to move the CPA group ID to the db cache

* Set the PerPage of CPA fields to the fields limit

* Update server/channels/app/custom_profile_attributes_test.go

Co-authored-by: Alejandro García Montoro <alejandro.garciamontoro@gmail.com>

* Standardize group ID access

* Avoid polluting the state between tests

* Use specific errors for the retrieval of CPA group

---------

Co-authored-by: Scott Bishel <scott.bishel@mattermost.com>
Co-authored-by: Mattermost Build <build@mattermost.com>
Co-authored-by: Alejandro García Montoro <alejandro.garciamontoro@gmail.com>
2025-01-13 18:12:38 +01:00