mirror of
https://github.com/penpot/penpot.git
synced 2026-05-06 16:48:48 +00:00
Merge remote-tracking branch 'origin/develop' into staging
This commit is contained in:
commit
1744d17385
15
.github/workflows/build-staging-render.yml
vendored
15
.github/workflows/build-staging-render.yml
vendored
@ -1,15 +0,0 @@
|
||||
name: _STAGING RENDER
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
schedule:
|
||||
- cron: '36 5-20 * * 1-5'
|
||||
|
||||
jobs:
|
||||
build-bundle:
|
||||
uses: ./.github/workflows/build-bundle.yml
|
||||
secrets: inherit
|
||||
with:
|
||||
gh_ref: "staging-render"
|
||||
build_wasm: "yes"
|
||||
build_storybook: "yes"
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@ -53,6 +53,7 @@
|
||||
/frontend/.storybook/preview-body.html
|
||||
/frontend/.storybook/preview-head.html
|
||||
/frontend/playwright-report/
|
||||
/frontend/playwright/ui/visual-specs/
|
||||
/frontend/text-editor/src/wasm/
|
||||
/frontend/dist/
|
||||
/frontend/npm-debug.log
|
||||
@ -84,3 +85,4 @@
|
||||
/**/node_modules
|
||||
/**/.yarn/*
|
||||
/.pnpm-store
|
||||
/.vscode
|
||||
|
||||
115
CHANGES.md
115
CHANGES.md
@ -1,5 +1,15 @@
|
||||
# CHANGELOG
|
||||
|
||||
## 2.17.0 (Unreleased)
|
||||
|
||||
### :boom: Breaking changes & Deprecations
|
||||
|
||||
### :rocket: Epics and highlights
|
||||
|
||||
### :sparkles: New features & Enhancements
|
||||
|
||||
### :bug: Bugs fixed
|
||||
|
||||
## 2.16.0 (Unreleased)
|
||||
|
||||
### :boom: Breaking changes & Deprecations
|
||||
@ -9,6 +19,54 @@
|
||||
### :sparkles: New features & Enhancements
|
||||
|
||||
- Enhance readability of applied tokens in plugins API [Taiga #13714](https://tree.taiga.io/project/penpot/issue/13714)
|
||||
- Add "Delete group" option to the assets panel context menu for components, colors and typographies (by @FairyPigDev) [Github #9141](https://github.com/penpot/penpot/issues/9141)
|
||||
- Add `Alt+click` on a layer's disclosure arrow to recursively expand the entire subtree in the Layers sidebar (by @MilosM348) [Github #9179](https://github.com/penpot/penpot/pull/9179)
|
||||
- Show alpha percentage next to library color values to distinguish colors that differ only in opacity (by @rockchris099) [Github #6328](https://github.com/penpot/penpot/issues/6328)
|
||||
- Add "Clear artboard guides" option to right-click context menu for frames (by @eureka0928) [Github #6987](https://github.com/penpot/penpot/issues/6987)
|
||||
- Add loader feedback while importing and exporting files (by @moorsecopers99) [Github #9024](https://github.com/penpot/penpot/pull/9024)
|
||||
- Allow duplicating color and typography styles (by @MkDev11) [Github #2912](https://github.com/penpot/penpot/issues/2912)
|
||||
- Add woff2 support on user uploaded fonts (by @Nivl) [Github #8248](https://github.com/penpot/penpot/pull/8248)
|
||||
- Import Tokens from linked library (by @dfelinto) [Github #8391](https://github.com/penpot/penpot/pull/8391)
|
||||
- Option to download custom fonts (by @dfelinto) [Github #8320](https://github.com/penpot/penpot/issues/8320)
|
||||
- Add copy as image to clipboard option to workspace context menu (by @dfelinto) [Github #8313](https://github.com/penpot/penpot/pull/8313)
|
||||
- Add Tab/Shift+Tab navigation to rename layers sequentially (by @bittoby) [Github #8474](https://github.com/penpot/penpot/pull/8474)
|
||||
- Copy and paste entire rows in existing table (by @bittoby) [Github #8498](https://github.com/penpot/penpot/pull/8498)
|
||||
- Rename token group [Taiga #13137](https://tree.taiga.io/project/penpot/us/13137)
|
||||
- Duplicate token group [Taiga #10653](https://tree.taiga.io/project/penpot/us/10653)
|
||||
- Copy token name from contextual menu [Taiga #13568](https://tree.taiga.io/project/penpot/issue/13568)
|
||||
- Add natural sorting on token names [Taiga #13713](https://tree.taiga.io/project/penpot/issue/13713)
|
||||
- Add drag-to-change for numeric inputs in workspace sidebar (by @RenzoMXD) [Github #8536](https://github.com/penpot/penpot/pull/8536)
|
||||
- Add CSS linter [Taiga #13790](https://tree.taiga.io/project/penpot/us/13790)
|
||||
- Save and restore selection state in undo/redo (by @eureka0928) [Github #6007](https://github.com/penpot/penpot/issues/6007)
|
||||
- Fix warnings for unsupported token $type (by @Dexterity104) [Github #8790](https://github.com/penpot/penpot/issues/8790)
|
||||
- Add per-group add button for typographies (by @eureka0928) [Github #5275](https://github.com/penpot/penpot/issues/5275)
|
||||
- Add Find & Replace for text content and layer names (by @statxc) [Github #7108](https://github.com/penpot/penpot/issues/7108)
|
||||
- Use page name for multi-export ZIP/PDF downloads (by @Dexterity104) [Github #8773](https://github.com/penpot/penpot/issues/8773)
|
||||
- Make links in comments clickable (by @eureka0928) [Github #1602](https://github.com/penpot/penpot/issues/1602)
|
||||
- Add visibility toggle for strokes (by @eureka0928) [Github #7438](https://github.com/penpot/penpot/issues/7438)
|
||||
- Sort asset library subfolders alphabetically at every nesting level (by @eureka0928) [Github #2572](https://github.com/penpot/penpot/issues/2572)
|
||||
- Add Paste to replace (Cmd+Shift+V) to replace the selected shape with clipboard contents (by @eureka0928) [Github #4240](https://github.com/penpot/penpot/issues/4240)
|
||||
- Differentiate incoming and outgoing interaction link colors (by @claytonlin1110) [Github #7794](https://github.com/penpot/penpot/issues/7794)
|
||||
- Add guide locking and fix locked elements not selectable in viewer (by @Dexterity104) [Github #8358](https://github.com/penpot/penpot/issues/8358)
|
||||
- Apply styles to selection (by @AzazelN28) [Taiga #13647](https://tree.taiga.io/project/penpot/task/13647)
|
||||
- Reorder prototyping overlay options to show Position before Relative to (by @rockchris099) [Github #2910](https://github.com/penpot/penpot/issues/2910)
|
||||
- Add customizable colors for ruler guides (by @Dexterity104) [Github #5199](https://github.com/penpot/penpot/issues/5199)
|
||||
- Persist asset search query and section filter when switching sidebar tabs (by @eureka0928) [Github #2913](https://github.com/penpot/penpot/issues/2913)
|
||||
- Add delete and duplicate buttons to typography dialog (by @eureka0928) [Github #5270](https://github.com/penpot/penpot/issues/5270)
|
||||
- Edit ruler guide position by double-clicking the guide pill (by @eureka0928) [Github #2311](https://github.com/penpot/penpot/issues/2311)
|
||||
- Add a search bar to filter colors in the color palette toolbar (by @eureka0928) [Github #7653](https://github.com/penpot/penpot/issues/7653)
|
||||
- Add a search bar to filter board size presets (by @eureka0928) [Github #4658](https://github.com/penpot/penpot/issues/4658)
|
||||
- Allow customising the OIDC login button label (by @wdeveloper16) [Github #7027](https://github.com/penpot/penpot/issues/7027)
|
||||
- Add page separators in Workspace [Taiga #13611](https://tree.taiga.io/project/penpot/us/13611?milestone=262806)
|
||||
- Preserve vector content when pasting SVG from external tools such as Inkscape (by @RenzoMXD) [Github #9182](https://github.com/penpot/penpot/pull/9182)
|
||||
- Add Shift+Numpad0/1/2 as aliases to Shift+0/1/2 for zoom shortcuts (by @RenzoMXD) [Github #9063](https://github.com/penpot/penpot/pull/9063)
|
||||
- Add pixel grid color picker in viewport settings (by @Yakehira) [Github #7750](https://github.com/penpot/penpot/issues/7750)
|
||||
- Add HEX, HSB and HSL support to the color picker with a model switcher that persists across sessions (by @edwin-rivera-dev) [Github #9133](https://github.com/penpot/penpot/issues/9133)
|
||||
- Show specific invitation-link error messages for expired, email-mismatch and invalid token cases [Github #9220](https://github.com/penpot/penpot/issues/9220)
|
||||
- Show detailed messages on file import errors to help diagnose why a file could not be imported (by @jsdevninja) [Github #9004](https://github.com/penpot/penpot/issues/9004)
|
||||
- Add read-only preview mode for saved versions — click a version name to open a dedicated preview view (by @wdeveloper16) [Github #8976](https://github.com/penpot/penpot/issues/8976)
|
||||
- Add clipboard read/write permissions to the plugin system (by @wdeveloper16) [Github #9053](https://github.com/penpot/penpot/issues/9053)
|
||||
- Add new numeric inputs for token management on the right sidebar [Taiga #12109](https://tree.taiga.io/project/penpot/us/12109?milestone=513226)
|
||||
|
||||
### :bug: Bugs fixed
|
||||
|
||||
@ -23,7 +81,56 @@
|
||||
- Fix text editor v1 focus [Taiga #13961](https://tree.taiga.io/project/penpot/issue/13961)
|
||||
- Fix color dropdown option update [Taiga #14035](https://tree.taiga.io/project/penpot/issue/14035)
|
||||
- Fix themes modal height [Taiga #14046](https://tree.taiga.io/project/penpot/issue/14046)
|
||||
|
||||
- Fix layers panel rename input showing the default type name instead of the saved layer name (by @jack-stormentswe) [Github #9231](https://github.com/penpot/penpot/pull/9231)
|
||||
- Suppress browser context menu on right-click in workspace sidebars while preserving it on text inputs (by @sujyotraut) [Github #5127](https://github.com/penpot/penpot/issues/5127)
|
||||
- Fix release notes modal appearing behind the dashboard sidebar (by @ciaokitty) [Github #8296](https://github.com/penpot/penpot/issues/8296)
|
||||
- Fix plugin API `fileVersion.restore()` promise hanging indefinitely on restore failure (by @thomascolden585-svg) [Github #9092](https://github.com/penpot/penpot/issues/9092)
|
||||
- Fix imported stroke-only SVG paths losing their rounded join when split into adjacent subpaths (by @Chrissi2812) [Github #5283](https://github.com/penpot/penpot/issues/5283)
|
||||
- Fix plugin API `library.connectLibrary()` not returning a Promise when the plugin lacks `library:write` permission (by @boskodev790) [Github #9158](https://github.com/penpot/penpot/pull/9158)
|
||||
- Fix LDAP provider schema typo (`bind-passwor` → `bind-password`) introduced during the `clojure.spec` → `malli` migration (by @boskodev790) [Github #9165](https://github.com/penpot/penpot/pull/9165)
|
||||
- Fix `login-with-ldap` silently dropping the error message when LDAP is not initialized (typo `:hide` → `:hint`) (by @boskodev790) [Github #9159](https://github.com/penpot/penpot/pull/9159)
|
||||
- Fix plugin API `applyToken()` / `applyToShapes()` / `applyToSelected()` rejecting JS-array attribute lists (by @brunopbezerra) [Github #9162](https://github.com/penpot/penpot/issues/9162)
|
||||
- Fix `PENPOT_OIDC_USER_INFO_SOURCE` flag being silently ignored in the OIDC callback (by @GeekClassy) [Github #9108](https://github.com/penpot/penpot/issues/9108)
|
||||
- Fix crash in share-link viewer when a team member's email is missing `@` or has no domain TLD (by @boskodev790) [Github #9120](https://github.com/penpot/penpot/pull/9120)
|
||||
- Fix crash when pasting a component with variants from an external shared library into a file that uses that library (by @FairyPigDev) [Github #8144](https://github.com/penpot/penpot/issues/8144)
|
||||
- Remove `corepack` from the MCP local launcher so it runs on Node.js 25+, where corepack is no longer bundled (by @TheAifam5) [Github #8877](https://github.com/penpot/penpot/issues/8877)
|
||||
- Fix Copy as SVG to produce a valid document for multi-shape selections and use `image/svg+xml` MIME type (by @RenzoMXD) [Github #9066](https://github.com/penpot/penpot/pull/9066)
|
||||
- Reset profile submenu state when the account menu closes (by @eureka0928) [Github #8947](https://github.com/penpot/penpot/issues/8947)
|
||||
- Preserve OpenType variant name table for custom fonts in the dashboard (by @rutherfordcraze) [Github #8924](https://github.com/penpot/penpot/issues/8924)
|
||||
- Add export panel to inspect styles tab [Taiga #13582](https://tree.taiga.io/project/penpot/issue/13582)
|
||||
- Fix styles between grid layout inputs [Taiga #13526](https://tree.taiga.io/project/penpot/issue/13526)
|
||||
- Fix id prop on switch component [Taiga #13534](https://tree.taiga.io/project/penpot/issue/13534)
|
||||
- Update copy on penpot update message [Taiga #12924](https://tree.taiga.io/project/penpot/issue/12924)
|
||||
- Fix scroll on library modal [Taiga #13639](https://tree.taiga.io/project/penpot/issue/13639)
|
||||
- Fix dates to avoid show them in english when browser is in auto [Taiga #13786](https://tree.taiga.io/project/penpot/issue/13786)
|
||||
- Fix focus radio button [Taiga #13841](https://tree.taiga.io/project/penpot/issue/13841)
|
||||
- Token tree should be expanded by default [Taiga #13631](https://tree.taiga.io/project/penpot/issue/13631)
|
||||
- Fix opacity incorrectly disabled for visible shapes [Taiga #13906](https://tree.taiga.io/project/penpot/issue/13906)
|
||||
- Update onboarding image [Taiga #13864](https://tree.taiga.io/project/penpot/issue/13864)
|
||||
- Fix plugin modal drag interactions over iframe and close-button behavior (by @marekhrabe) [Github #8871](https://github.com/penpot/penpot/pull/8871)
|
||||
- Fix hot update on color-row on texts [Taiga #13923](https://tree.taiga.io/project/penpot/issue/13923)
|
||||
- Fix selected color tokens [Taiga #13930](https://tree.taiga.io/project/penpot/issue/13930)
|
||||
- Fix dashboard Recent/Deleted titles overlapped by scrolling content (by @rockchris099) [Github #8577](https://github.com/penpot/penpot/issues/8577)
|
||||
- Display resolved values of inactive tokens [Taiga #13628](https://tree.taiga.io/project/penpot/issue/13628)
|
||||
- Fix hyphens stripped from export filenames (by @jamesrayammons) [Github #8901](https://github.com/penpot/penpot/issues/8901)
|
||||
- Fix app crash when selecting shapes with one hidden [Taiga #13959](https://tree.taiga.io/project/penpot/issue/13959)
|
||||
- Fix opacity mixed value [Taiga #13960](https://tree.taiga.io/project/penpot/issue/13960)
|
||||
- Fix gap input throwing an error [Github #8984](https://github.com/penpot/penpot/pull/8984)
|
||||
- Fix non-functional clear icon in change email modal inputs (by @Dexterity104) [Github #8977](https://github.com/penpot/penpot/issues/8977)
|
||||
- Disable save button after saving account profile settings (by @Dexterity104) [Github #8979](https://github.com/penpot/penpot/issues/8979)
|
||||
- Fix copy to be more specific [Taiga #13990](https://tree.taiga.io/project/penpot/issue/13990)
|
||||
- Allow deleting the profile avatar after uploading (by @moorsecopers99) [Github #9067](https://github.com/penpot/penpot/issues/9067)
|
||||
- Fix incorrect rendering when exporting text as SVG, PNG and JPG (by @edwin-rivera-dev) [Github #8516](https://github.com/penpot/penpot/issues/8516)
|
||||
- Fix Settings and Notifications "Update Settings" button enabled state when form has no changes (by @moorsecopers99) [Github #9090](https://github.com/penpot/penpot/issues/9090)
|
||||
- Fix "Help & Learning" submenu vertical alignment in account menu (by @juan-flores077) [Github #9137](https://github.com/penpot/penpot/issues/9137)
|
||||
- Fix plugin `addInteraction` silently rejecting `open-overlay` actions with `manualPositionLocation` (by @axelseis) [Github #8409](https://github.com/penpot/penpot/issues/8409)
|
||||
- Fix typography style creation with tokenized line-height (by @juan-flores077) [Github #8479](https://github.com/penpot/penpot/issues/8479)
|
||||
- Fix colorpicker layout so the eyedropper button is visible again [Taiga #14057](https://tree.taiga.io/project/penpot/issue/14057)
|
||||
- Fix restore-deleted-team-files failing due to a typo in the reduce accumulator (by @Dexterity104) [Github #9241](https://github.com/penpot/penpot/issues/9241)
|
||||
- Fix internal error on layer prev/next sibling selection (by @jsdevninja) [Github #9003](https://github.com/penpot/penpot/issues/9003)
|
||||
- Fix tooltip appearing two times when nested elements [Github #9031](https://github.com/penpot/penpot/issues/9031)
|
||||
- Fix broken update library notification link in the UI [Github #9070](https://github.com/penpot/penpot/issues/9070)
|
||||
- Fix plugin API `ShapeBase.component()` returning the outermost component instead of the immediate component in case of nested component instances [Github #9183](https://github.com/penpot/penpot/issues/9183)
|
||||
|
||||
## 2.15.0 (Unreleased)
|
||||
|
||||
@ -39,7 +146,6 @@
|
||||
- Fix incorrect handling of version restore operation [Github #9041](https://github.com/penpot/penpot/pull/9041)
|
||||
- Fix Plugin API token methods rejecting JS array of strings [Github #9162](https://github.com/penpot/penpot/issues/9162)
|
||||
|
||||
|
||||
## 2.14.4
|
||||
|
||||
### :bug: Bugs fixed
|
||||
@ -48,7 +154,6 @@
|
||||
- Fix email blacklisting [Github #9122](https://github.com/penpot/penpot/pull/9122)
|
||||
- Fix removeChild errors from unmount race conditions [Github #8927](https://github.com/penpot/penpot/pull/8927)
|
||||
|
||||
|
||||
## 2.14.3
|
||||
|
||||
### :sparkles: New features & Enhancements
|
||||
@ -79,7 +184,6 @@
|
||||
- Fix typo `:podition` in swap-shapes grid cell
|
||||
- Fix multiple selection on shapes with token applied to stroke color
|
||||
|
||||
|
||||
## 2.14.2
|
||||
|
||||
### :sparkles: New features & Enhancements
|
||||
@ -102,7 +206,6 @@
|
||||
- Guard delete undo against missing sibling order [Github #8858](https://github.com/penpot/penpot/pull/8858)
|
||||
- Fix ICounted error on numeric-input token dropdown keyboard nav [Github #8803](https://github.com/penpot/penpot/pull/8803)
|
||||
|
||||
|
||||
## 2.14.1
|
||||
|
||||
### :sparkles: New features & Enhancements
|
||||
@ -126,7 +229,6 @@
|
||||
- Ensure path content is always PathData when saving
|
||||
- Fix error when get-parent-with-data encounters non-Element nodes
|
||||
|
||||
|
||||
## 2.14.0
|
||||
|
||||
### :boom: Breaking changes & Deprecations
|
||||
@ -196,6 +298,7 @@
|
||||
## 2.13.0
|
||||
|
||||
### :heart: Community contributions (Thank you!)
|
||||
|
||||
- Add 'page' special shapeId to MCP export_shape tool for full-page snapshots [Github #8689](https://github.com/penpot/penpot/issues/8689)
|
||||
|
||||
- Fix mask issues with component swap (by @dfelinto) [Github #7675](https://github.com/penpot/penpot/issues/7675)
|
||||
|
||||
@ -63,12 +63,11 @@ Advisories](https://github.com/penpot/penpot/security/advisories)
|
||||
1. **Read the DCO** — see [Developer's Certificate of Origin](#developers-certificate-of-origin-dco)
|
||||
below. All code patches must include a `Signed-off-by` line.
|
||||
2. **Discuss before building** — open a [GitHub
|
||||
Issue](https://github.com/penpot/penpot/issues) or start a [GitHub
|
||||
Discussion](https://github.com/penpot/penpot/discussions) before starting
|
||||
work on a new feature or significant change. For planned features on the
|
||||
roadmap, reference the corresponding Taiga story. No PR will be accepted
|
||||
without prior discussion, whether it is a new feature, a planned one, or a
|
||||
quick win.
|
||||
Issue](https://github.com/penpot/penpot/issues) before starting work on
|
||||
a new feature or significant change. For planned features on the roadmap,
|
||||
reference the corresponding Taiga story. Do not expect your contribution
|
||||
to be accepted if you submit it without prior discussion — this applies
|
||||
to new features, planned features, and quick wins alike.
|
||||
3. **Bug fixes** — you may submit a PR directly, but we still recommend
|
||||
filing an issue first so we can track it independently of your fix.
|
||||
4. **Format and lint** — run the checks described in
|
||||
@ -136,7 +135,11 @@ refactor/layout-sizing
|
||||
|
||||
### Review process
|
||||
|
||||
- Maintainers review PRs when time permits. Please be patient.
|
||||
- We are a small team and maintainers juggle reviews alongside other
|
||||
tasks. Please do not expect your code to be reviewed instantly.
|
||||
- Reviews are handled in dedicated blocks of time, usually in the order
|
||||
PRs arrive. It may take a few days to get a first review, especially
|
||||
when urgent tasks come up.
|
||||
- Address review feedback by **pushing new commits** — do not
|
||||
force-push during review, as it breaks comment threads.
|
||||
- PRs require at least **one approval** before merge.
|
||||
|
||||
138
README.md
138
README.md
@ -1,53 +1,56 @@
|
||||
<img width="100%" src="https://github.com/user-attachments/assets/da17b160-f289-436f-b140-972083a08602" />
|
||||
|
||||
[uri_license]: https://www.mozilla.org/en-US/MPL/2.0
|
||||
[uri_license_image]: https://img.shields.io/badge/MPL-2.0-blue.svg
|
||||
|
||||
<picture>
|
||||
<source media="(prefers-color-scheme: dark)" srcset="https://penpot.app/images/readme/github-dark-mode.png">
|
||||
<source media="(prefers-color-scheme: light)" srcset="https://penpot.app/images/readme/github-light-mode.png">
|
||||
<img alt="penpot header image" src="https://penpot.app/images/readme/github-light-mode.png">
|
||||
</picture>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://www.mozilla.org/en-US/MPL/2.0" rel="nofollow"><img alt="License: MPL-2.0" src="https://img.shields.io/badge/MPL-2.0-blue.svg" style="max-width:100%;"></a>
|
||||
<a href="https://community.penpot.app" rel="nofollow"><img alt="Penpot Community" src="https://img.shields.io/discourse/posts?server=https%3A%2F%2Fcommunity.penpot.app" style="max-width:100%;"></a>
|
||||
<a href="https://tree.taiga.io/project/penpot/" title="Managed with Taiga.io" rel="nofollow"><img alt="Managed with Taiga.io" src="https://img.shields.io/badge/managed%20with-TAIGA.io-709f14.svg" style="max-width:100%;"></a>
|
||||
<a href="https://gitpod.io/#https://github.com/penpot/penpot" rel="nofollow"><img alt="Gitpod ready-to-code" src="https://img.shields.io/badge/Gitpod-ready--to--code-blue?logo=gitpod" style="max-width:100%;"></a>
|
||||
<a href="https://www.digitalpublicgoods.net/r/penpot" rel="nofollow">
|
||||
<img alt="Verified DPG" src="https://img.shields.io/badge/Verified-DPG-blue.svg">
|
||||
</a>
|
||||
<a href="https://community.penpot.app" rel="nofollow">
|
||||
<img alt="Penpot Community" src="https://img.shields.io/discourse/posts?server=https%3A%2F%2Fcommunity.penpot.app">
|
||||
</a>
|
||||
<a href="https://tree.taiga.io/project/penpot/" rel="nofollow">
|
||||
<img alt="Managed with Taiga.io" src="https://img.shields.io/badge/managed%20with-TAIGA.io-709f14.svg">
|
||||
</a>
|
||||
<a href="https://gitpod.io/#https://github.com/penpot/penpot" rel="nofollow">
|
||||
<img alt="Gitpod ready-to-code" src="https://img.shields.io/badge/Gitpod-ready--to--code-blue?logo=gitpod">
|
||||
</a>
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://penpot.app/"><b>Website</b></a> •
|
||||
<a href="https://help.penpot.app/user-guide/"><b>User Guide</b></a> •
|
||||
<a href="https://penpot.app/learning-center"><b>Learning Center</b></a> •
|
||||
<a href="https://community.penpot.app/"><b>Community</b></a>
|
||||
<a href="https://penpot.app/"><b>Website</b></a> •
|
||||
<a href="https://help.penpot.app/user-guide/"><b>User Guide</b></a> •
|
||||
<a href="https://penpot.app/learning-center"><b>Learning Center</b></a> •
|
||||
<a href="https://community.penpot.app/"><b>Community</b></a>
|
||||
</p>
|
||||
<p align="center">
|
||||
<a href="https://www.youtube.com/@Penpot"><b>Youtube</b></a> •
|
||||
<a href="https://peertube.kaleidos.net/a/penpot_app/video-channels"><b>Peertube</b></a> •
|
||||
<a href="https://www.linkedin.com/company/penpot/"><b>Linkedin</b></a> •
|
||||
<a href="https://instagram.com/penpot.app"><b>Instagram</b></a> •
|
||||
<a href="https://fosstodon.org/@penpot/"><b>Mastodon</b></a> •
|
||||
<a href="https://bsky.app/profile/penpot.app"><b>Bluesky</b></a> •
|
||||
<a href="https://twitter.com/penpotapp"><b>X</b></a>
|
||||
|
||||
<a href="https://www.youtube.com/@Penpot"><b>Youtube</b></a> •
|
||||
<a href="https://peertube.kaleidos.net/a/penpot_app/video-channels"><b>Peertube</b></a> •
|
||||
<a href="https://www.linkedin.com/company/penpot/"><b>Linkedin</b></a> •
|
||||
<a href="https://instagram.com/penpot.app"><b>Instagram</b></a> •
|
||||
<a href="https://fosstodon.org/@penpot/"><b>Mastodon</b></a> •
|
||||
<a href="https://bsky.app/profile/penpot.app"><b>Bluesky</b></a> •
|
||||
<a href="https://twitter.com/penpotapp"><b>X</b></a>
|
||||
</p>
|
||||
|
||||
<br />
|
||||
[Penpot video](https://github.com/user-attachments/assets/7c67fd7c-04d3-4c9b-88ec-b6f5e23f8332)
|
||||
|
||||
[Penpot video](https://github.com/user-attachments/assets/7c67fd7c-04d3-4c9b-88ec-b6f5e23f8332
|
||||
)
|
||||
Penpot is the open-source design platform for teams that build digital products at scale.
|
||||
|
||||
<br />
|
||||
Penpot’s key strength lies in giving you **full ownership of your design infrastructure**. Built on open source and designed for [self-hosting](https://help.penpot.app/technical-guide/getting-started/), it puts teams in complete control of their design environment supporting strict compliance and governance requirements. Whether used in the **browser or deployed on your own servers**, Penpot **works with open standards** like SVG, CSS, HTML, and JSON.
|
||||
|
||||
Penpot is the first **open-source** design tool for design and code collaboration. Designers can create stunning designs, interactive prototypes, design systems at scale, while developers enjoy ready-to-use code and make their workflow easy and fast. And all of this with no handoff drama.
|
||||
Real-time collaboration strengthens this foundation, helping teams scale and bring design closer to the product through top-tier capabilities. Additionally, developers feel at home using Penpot, because design is expressed as code, enabling a direct translation and shipping products faster.
|
||||
|
||||
Available on browser or self-hosted, Penpot works with open standards like SVG, CSS, HTML and JSON, and it’s free!
|
||||
Best-in-class native [Design Tokens](https://penpot.dev/collaboration/design-tokens) provide a single source of truth between design and development. They ensure consistency, improve collaboration, and make it easier to manage complex design systems.
|
||||
|
||||
The latest updates take Penpot even further. It’s the first design tool to integrate native [design tokens](https://penpot.dev/collaboration/design-tokens)—a single source of truth to improve efficiency and collaboration between product design and development.
|
||||
With the [huge 2.0 release](https://penpot.app/dev-diaries), Penpot took the platform to a whole new level. This update introduces the ground-breaking [CSS Grid Layout feature](https://penpot.app/penpot-2.0), a complete UI redesign, a new Components system, and much more.
|
||||
For organizations that need extra service for its teams, [get in touch](https://cal.com/team/penpot/talk-to-us)
|
||||
The [MCP server](https://penpot.app/penpot-mcp-server) takes it further by enabling multi-directional workflows between design and code. A [powerful open API](https://help.penpot.app/mcp/#quick-start) and plugin system makes the workspace programmable, enabling automation, AI-driven workflows, and integrations with the tools and systems you already use.
|
||||
|
||||
🎇 Design, code, and Open Source meet at [Penpot Fest](https://penpot.app/penpotfest)! Be part of the 2025 edition in Madrid, Spain, on October 9-10.
|
||||
With [CSS Grid and Flex Layout](https://help.penpot.app/user-guide/designing/flexible-layouts/), teams can design responsive interfaces that behave like real code from the start.
|
||||
|
||||
Combined, these features turn Penpot into a **full-stack design platform** for building scalable design systems and fully integrated product development processes.
|
||||
|
||||
If your organization is scaling and needs extra support, we’re here to help. [Talk to us](https://penpot.app/talk-to-us)
|
||||
|
||||
## Table of contents ##
|
||||
|
||||
@ -60,101 +63,78 @@ For organizations that need extra service for its teams, [get in touch](https://
|
||||
|
||||
## Why Penpot ##
|
||||
|
||||
Penpot expresses designs as code. Designers can do their best work and see it will be beautifully implemented by developers in a two-way collaboration.
|
||||
Penpot connects design, code, and AI workflows through a code-based approach, making designs readable by developers and AI via the MCP server. This approach helps teams ship what’s actually designed and manage design systems at scale with powerful design tokens. As a self-hosted, open-source and real-time collaboration platform, Penpot offers full flexibility, security, and ownership without vendor lock-in. Learn more about [why Penpot](https://penpot.app/why-penpot) is the platform for your team.
|
||||
|
||||
### Plugin system ###
|
||||
|
||||
[Penpot plugins](https://penpot.app/penpothub/plugins) let you expand the platform's capabilities, give you the flexibility to integrate it with other apps, and design custom solutions.
|
||||
|
||||
### Designed for developers ###
|
||||
|
||||
Penpot was built to serve both designers and developers and create a fluid design-code process. You have the choice to enjoy real-time collaboration or play "solo".
|
||||
|
||||
### Inspect mode ###
|
||||
|
||||
Work with ready-to-use code and make your workflow easy and fast. The inspect tab gives instant access to SVG, CSS and HTML code.
|
||||
|
||||
### Self host your own instance ###
|
||||
Provide your team or organization with a completely owned collaborative design tool. Use Penpot's cloud service or deploy your own Penpot server.
|
||||
|
||||
### Integrations ###
|
||||
Penpot offers integration into the development toolchain, thanks to its support for webhooks and an API accessible through access tokens.
|
||||
|
||||
### Building Design Systems: design tokens, components and variants ###
|
||||
Penpot brings design systems to code-minded teams: a single source of truth with native Design Tokens, Components, and Variants for scalable, reusable, and consistent UI across projects and platforms.
|
||||
Penpot offers [integration](https://penpot.app/integrations-api) into the development toolchain, thanks to its support for webhooks and an API accessible through access tokens.
|
||||
|
||||
### Building Design Systems: design tokens, components and variants ###
|
||||
|
||||
<br />
|
||||
Penpot brings [design systems](https://penpot.app/design/design-systems) to code-minded teams: a single source of truth with native Design Tokens, Components, and Variants for scalable, reusable, and consistent UI across projects and platforms.
|
||||
|
||||
<p align="center">
|
||||
<img src="https://github.com/user-attachments/assets/cce75ad6-f783-473f-8803-da9eb8255fef">
|
||||
</p>
|
||||
|
||||
<br />
|
||||
<img width="100%" alt="Penpot Design Systems" src="https://github.com/user-attachments/assets/cce75ad6-f783-473f-8803-da9eb8255fef">
|
||||
|
||||
## Getting started ##
|
||||
|
||||
Penpot is the only design & prototype platform that is deployment agnostic. You can use it in our [SAAS](https://design.penpot.app) or deploy it anywhere.
|
||||
|
||||
Learn how to install it with Docker, Kubernetes, Elestio or other options on [our website](https://penpot.app/self-host).
|
||||
<br />
|
||||
|
||||
<p align="center">
|
||||
<img src="https://site-assets.plasmic.app/2168cf524dd543caeff32384eb9ea0a1.svg" alt="Open Source" style="width: 65%;">
|
||||
</p>
|
||||
<br />
|
||||
|
||||
## Community ##
|
||||
|
||||
We love the Open Source software community. Contributing is our passion and if it’s yours too, participate and [improve](https://community.penpot.app/c/help-us-improve-penpot/7) Penpot. All your designs, code and ideas are welcome!
|
||||
|
||||
Want to go a step further? Become a [Penpot Ambassador](https://penpot.app/ambassador-program) and help grow the Penpot community in your region while contributing to a global, open design ecosystem.
|
||||
|
||||
If you need help or have any questions; if you’d like to share your experience using Penpot or get inspired; if you’d rather meet our community of developers and designers, [join our Community](https://community.penpot.app/)!
|
||||
|
||||
You will find the following categories:
|
||||
Categories include:
|
||||
|
||||
- [Ask the Community](https://community.penpot.app/c/ask-for-help-using-penpot/6)
|
||||
- [Troubleshooting](https://community.penpot.app/c/technical/8)
|
||||
- [Help us Improve Penpot](https://community.penpot.app/c/help-us-improve-penpot/7)
|
||||
- [#MadeWithPenpot](https://community.penpot.app/c/madewithpenpot/9)
|
||||
- [Events and Announcements](https://community.penpot.app/c/announcements/5)
|
||||
- [Inside Penpot](https://community.penpot.app/c/inside-penpot/21)
|
||||
- [Penpot in your language](https://community.penpot.app/c/penpot-in-your-language/12)
|
||||
- [Design and Code Essentials](https://community.penpot.app/c/design-and-code-essentials/22)
|
||||
- [Education](https://community.penpot.app/c/education/28)
|
||||
|
||||
|
||||
<br />
|
||||
|
||||
<p align="center">
|
||||
<img src="https://github.com/penpot/penpot/assets/5446186/6ac62220-a16c-46c9-ab21-d24ae357ed03" alt="Community" style="width: 65%;">
|
||||
</p>
|
||||
<br />
|
||||
<img width="100%" alt="Pentpot Community" src="https://github.com/user-attachments/assets/4b2a4360-12b5-4994-bd45-641449f86c4e" />
|
||||
|
||||
### Code of Conduct ###
|
||||
|
||||
Anyone who contributes to Penpot, whether through code, in the community, or at an event, must adhere to the
|
||||
[code of conduct](https://help.penpot.app/contributing-guide/coc/) and foster a positive and safe environment.
|
||||
|
||||
|
||||
## Contributing ##
|
||||
### Contributing ###
|
||||
|
||||
Any contribution will make a difference to improve Penpot. How can you get involved?
|
||||
|
||||
Choose your way:
|
||||
|
||||
- Create and [share Libraries & Templates](https://penpot.app/libraries-templates.html) that will be helpful for the community
|
||||
- Invite your [team to join](https://design.penpot.app/#/auth/register)
|
||||
- Give this repo a star and follow us on Social Media: [Mastodon](https://fosstodon.org/@penpot/), [Youtube](https://www.youtube.com/c/Penpot), [Instagram](https://instagram.com/penpot.app), [Linkedin](https://www.linkedin.com/company/penpotdesign), [Peertube](https://peertube.kaleidos.net/a/penpot_app), [X](https://twitter.com/penpotapp) and [BlueSky](https://bsky.app/profile/penpot.app)
|
||||
- Create and [share Libraries & Templates](https://penpot.app/libraries-templates.html) that will be helpful for the community.
|
||||
- Invite your [team to join](https://design.penpot.app/#/auth/register).
|
||||
- Give this repo a star and follow us on Social Media: [Mastodon](https://fosstodon.org/@penpot/), [Youtube](https://www.youtube.com/c/Penpot), [Instagram](https://instagram.com/penpot.app), [Linkedin](https://www.linkedin.com/company/penpotdesign), [Peertube](https://peertube.kaleidos.net/a/penpot_app), [X](https://twitter.com/penpotapp) and [BlueSky](https://bsky.app/profile/penpot.app).
|
||||
- Participate in the [Community](https://community.penpot.app/) space by asking and answering questions; reacting to others’ articles; opening your own conversations and following along on decisions affecting the project.
|
||||
- Report bugs with our easy [guide for bugs hunting](https://help.penpot.app/contributing-guide/reporting-bugs/) or [GitHub issues](https://github.com/penpot/penpot/issues)
|
||||
- Become a [translator](https://help.penpot.app/contributing-guide/translations)
|
||||
- Give feedback: [Email us](mailto:support@penpot.app)
|
||||
- **Contribute to Penpot's code:** [Watch this video](https://www.youtube.com/watch?v=TpN0osiY-8k) by Alejandro Alonso, CIO and developer at Penpot, where he gives us a hands-on demo of how to use Penpot’s repository and make changes in both front and back end
|
||||
- Report bugs with our easy [guide for bugs hunting](https://help.penpot.app/contributing-guide/reporting-bugs/) or [GitHub issues](https://github.com/penpot/penpot/issues).
|
||||
- Become a [translator](https://help.penpot.app/contributing-guide/translations).
|
||||
- Give feedback: [Email us](mailto:support@penpot.app).
|
||||
- **Contribute to Penpot's code:** [Watch this video](https://www.youtube.com/watch?v=TpN0osiY-8k) by Alejandro Alonso, CIO and developer at Penpot, where he gives us a hands-on demo of how to use Penpot’s repository and make changes in both front and back end.
|
||||
|
||||
To find (almost) everything you need to know on how to contribute to Penpot, refer to the [contributing guide](https://help.penpot.app/contributing-guide/).
|
||||
|
||||
<br />
|
||||
|
||||
<p align="center">
|
||||
<img src="https://github.com/penpot/penpot/assets/5446186/fea18923-dc06-49be-86ad-c3496a7956e6" alt="Libraries and templates" style="width: 65%;">
|
||||
</p>
|
||||
|
||||
<br />
|
||||
<img width="100%" alt="Penpot hub" src="https://github.com/user-attachments/assets/0abc02f0-625c-45ab-ad81-4927bec7a055" />
|
||||
|
||||
## Resources ##
|
||||
|
||||
@ -170,6 +150,8 @@ You can ask and answer questions, have open-ended conversations, and follow alon
|
||||
|
||||
📚 [Dev Diaries](https://penpot.app/dev-diaries.html)
|
||||
|
||||
🧑🏫 [UI Design Course](https://penpot.app/courses/)
|
||||
|
||||
|
||||
## License ##
|
||||
|
||||
|
||||
264
backend/resources/app/email/invite-to-org/en.html
Normal file
264
backend/resources/app/email/invite-to-org/en.html
Normal file
@ -0,0 +1,264 @@
|
||||
<!doctype html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml"
|
||||
xmlns:o="urn:schemas-microsoft-com:office:office">
|
||||
|
||||
<head>
|
||||
<title>
|
||||
</title>
|
||||
<!--[if !mso]><!-- -->
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<!--<![endif]-->
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<style type="text/css">
|
||||
#outlook a {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
-webkit-text-size-adjust: 100%;
|
||||
-ms-text-size-adjust: 100%;
|
||||
}
|
||||
|
||||
table,
|
||||
td {
|
||||
border-collapse: collapse;
|
||||
mso-table-lspace: 0pt;
|
||||
mso-table-rspace: 0pt;
|
||||
}
|
||||
|
||||
img {
|
||||
border: 0;
|
||||
height: auto;
|
||||
line-height: 100%;
|
||||
outline: none;
|
||||
text-decoration: none;
|
||||
-ms-interpolation-mode: bicubic;
|
||||
}
|
||||
|
||||
p {
|
||||
display: block;
|
||||
margin: 13px 0;
|
||||
}
|
||||
</style>
|
||||
<!--[if mso]>
|
||||
<xml>
|
||||
<o:OfficeDocumentSettings>
|
||||
<o:AllowPNG/>
|
||||
<o:PixelsPerInch>96</o:PixelsPerInch>
|
||||
</o:OfficeDocumentSettings>
|
||||
</xml>
|
||||
<![endif]-->
|
||||
<!--[if lte mso 11]>
|
||||
<style type="text/css">
|
||||
.mj-outlook-group-fix { width:100% !important; }
|
||||
</style>
|
||||
<![endif]-->
|
||||
<!--[if !mso]><!-->
|
||||
<link href="https://fonts.googleapis.com/css?family=Source%20Sans%20Pro" rel="stylesheet" type="text/css">
|
||||
<style type="text/css">
|
||||
@import url(https://fonts.googleapis.com/css?family=Source%20Sans%20Pro);
|
||||
</style>
|
||||
<!--<![endif]-->
|
||||
<style type="text/css">
|
||||
@media only screen and (min-width:480px) {
|
||||
.mj-column-per-100 {
|
||||
width: 100% !important;
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.mj-column-px-425 {
|
||||
width: 425px !important;
|
||||
max-width: 425px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<style type="text/css">
|
||||
@media only screen and (max-width:480px) {
|
||||
table.mj-full-width-mobile {
|
||||
width: 100% !important;
|
||||
}
|
||||
|
||||
td.mj-full-width-mobile {
|
||||
width: auto !important;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body style="background-color:#E5E5E5;">
|
||||
<div style="background-color:#E5E5E5;">
|
||||
<!--[if mso | IE]>
|
||||
<table
|
||||
align="center" border="0" cellpadding="0" cellspacing="0" class="" style="width:600px;" width="600"
|
||||
>
|
||||
<tr>
|
||||
<td style="line-height:0px;font-size:0px;mso-line-height-rule:exactly;">
|
||||
<![endif]-->
|
||||
<div style="margin:0px auto;max-width:600px;">
|
||||
<table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="width:100%;">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td style="direction:ltr;font-size:0px;padding:0;text-align:center;">
|
||||
<!--[if mso | IE]>
|
||||
<table role="presentation" border="0" cellpadding="0" cellspacing="0">
|
||||
|
||||
<tr>
|
||||
|
||||
<td
|
||||
class="" style="vertical-align:top;width:600px;"
|
||||
>
|
||||
<![endif]-->
|
||||
<div class="mj-column-per-100 mj-outlook-group-fix"
|
||||
style="font-size:0px;text-align:left;direction:ltr;display:inline-block;vertical-align:top;width:100%;">
|
||||
<table border="0" cellpadding="0" cellspacing="0" role="presentation" style="vertical-align:top;"
|
||||
width="100%">
|
||||
<tr>
|
||||
<td align="left" style="font-size:0px;padding:16px;word-break:break-word;">
|
||||
<table border="0" cellpadding="0" cellspacing="0" role="presentation"
|
||||
style="border-collapse:collapse;border-spacing:0px;">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td style="width:97px;">
|
||||
<img height="32" src="{{ public-uri }}/images/email/uxbox-title.png"
|
||||
style="border:0;display:block;outline:none;text-decoration:none;height:32px;width:100%;font-size:13px;"
|
||||
width="97" />
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<!--[if mso | IE]>
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
<![endif]-->
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<!--[if mso | IE]>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table
|
||||
align="center" border="0" cellpadding="0" cellspacing="0" class="" style="width:600px;" width="600"
|
||||
>
|
||||
<tr>
|
||||
<td style="line-height:0px;font-size:0px;mso-line-height-rule:exactly;">
|
||||
<![endif]-->
|
||||
<div style="background:#FFFFFF;background-color:#FFFFFF;margin:0px auto;max-width:600px;">
|
||||
<table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation"
|
||||
style="background:#FFFFFF;background-color:#FFFFFF;width:100%;">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td style="direction:ltr;font-size:0px;padding:20px 0;text-align:center;">
|
||||
<!--[if mso | IE]>
|
||||
<table role="presentation" border="0" cellpadding="0" cellspacing="0">
|
||||
|
||||
<tr>
|
||||
|
||||
<td
|
||||
class="" style="vertical-align:top;width:600px;"
|
||||
>
|
||||
<![endif]-->
|
||||
<div class="mj-column-per-100 mj-outlook-group-fix"
|
||||
style="font-size:0px;text-align:left;direction:ltr;display:inline-block;vertical-align:top;width:100%;">
|
||||
<table border="0" cellpadding="0" cellspacing="0" role="presentation" style="vertical-align:top;"
|
||||
width="100%">
|
||||
<tr>
|
||||
<td align="left" style="font-size:0px;padding:10px 25px;word-break:break-word;">
|
||||
<div
|
||||
style="font-family:Source Sans Pro, sans-serif;font-size:16px;line-height:150%;text-align:left;color:#000000;">
|
||||
Hi{% if user-name %} {{ user-name|abbreviate:25 }}{% endif %},
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left" style="font-size:0px;padding:10px 25px;word-break:break-word;">
|
||||
<div
|
||||
style="font-family:Source Sans Pro, sans-serif;font-size:16px;line-height:150%;text-align:left;color:#000000;">
|
||||
<b>{{invited-by|abbreviate:25}}</b> sent you an invitation to join the organization:
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left" style="font-size:0px;padding:10px 25px;word-break:break-word;">
|
||||
<div
|
||||
style="font-family:Source Sans Pro, sans-serif;font-size:16px;line-height:150%;text-align:left;color:#000000;">
|
||||
<table role="presentation" cellpadding="0" cellspacing="0" border="0" width="20" height="20" style="display:inline-block;vertical-align:middle;">
|
||||
<tr>
|
||||
<td width="20" height="20" align="center" valign="middle"
|
||||
background="{{organization-logo}}"
|
||||
style="width:20px;height:20px;text-align:center;font-weight:bold;font-size:9px;line-height:20px;color:#ffffff;background-size:cover;background-position:center;background-repeat:no-repeat;border-radius: 50%;color:black">
|
||||
{% if organization-initials %}{{organization-initials}}{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<span style="display:inline-block; vertical-align: middle;padding-left:5px;height:20px;line-height: 20px;">
|
||||
“{{ organization-name|abbreviate:25 }}”
|
||||
</span>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" vertical-align="middle"
|
||||
style="font-size:0px;padding:10px 25px;word-break:break-word;">
|
||||
<table border="0" cellpadding="0" cellspacing="0" role="presentation"
|
||||
style="border-collapse:separate;line-height:100%;">
|
||||
<tr>
|
||||
<td align="center" bgcolor="#6911d4" role="presentation"
|
||||
style="border:none;border-radius:8px;cursor:auto;mso-padding-alt:10px 25px;background:#6911d4;"
|
||||
valign="middle">
|
||||
<a href="{{ public-uri }}/#/auth/verify-token?token={{token}}"
|
||||
style="display:inline-block;background:#6911d4;color:#FFFFFF;font-family:Source Sans Pro, sans-serif;font-size:16px;font-weight:normal;line-height:120%;margin:0;text-decoration:none;text-transform:none;padding:10px 25px;mso-padding-alt:0px;border-radius:8px;"
|
||||
target="_blank"> ACCEPT INVITE </a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left" style="font-size:0px;padding:10px 25px;word-break:break-word;">
|
||||
<div
|
||||
style="font-family:Source Sans Pro, sans-serif;font-size:16px;line-height:150%;text-align:left;color:#000000;">
|
||||
Enjoy!</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left" style="font-size:0px;padding:10px 25px;word-break:break-word;">
|
||||
<div
|
||||
style="font-family:Source Sans Pro, sans-serif;font-size:16px;line-height:150%;text-align:left;color:#000000;">
|
||||
The Penpot team.</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<!--[if mso | IE]>
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
<![endif]-->
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
{% include "app/email/includes/footer.html" %}
|
||||
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
1
backend/resources/app/email/invite-to-org/en.subj
Normal file
1
backend/resources/app/email/invite-to-org/en.subj
Normal file
@ -0,0 +1 @@
|
||||
{{invited-by|abbreviate:25}} has invited you to join the organization “{{ organization-name|abbreviate:25 }}”
|
||||
10
backend/resources/app/email/invite-to-org/en.txt
Normal file
10
backend/resources/app/email/invite-to-org/en.txt
Normal file
@ -0,0 +1,10 @@
|
||||
Hello!
|
||||
|
||||
{{invited-by|abbreviate:25}} has invited you to join the organization “{{ organization-name|abbreviate:25 }}”.
|
||||
|
||||
Accept invitation using this link:
|
||||
|
||||
{{ public-uri }}/#/auth/verify-token?token={{token}}
|
||||
|
||||
Enjoy!
|
||||
The Penpot team.
|
||||
@ -186,7 +186,8 @@
|
||||
<td align="left" style="font-size:0px;padding:10px 25px;word-break:break-word;">
|
||||
<div
|
||||
style="font-family:Source Sans Pro, sans-serif;font-size:16px;line-height:150%;text-align:left;color:#000000;">
|
||||
{{invited-by|abbreviate:25}} has invited you to join the team “{{ team|abbreviate:25 }}”.</div>
|
||||
{{invited-by|abbreviate:25}} has invited you to join the team “{{ team|abbreviate:25 }}”{% if organization %}
|
||||
part of the organization “{{ organization|abbreviate:25 }}”{% endif %}.</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
Hello!
|
||||
|
||||
{{invited-by|abbreviate:25}} has invited you to join the team “{{ team|abbreviate:25 }}”.
|
||||
{{invited-by|abbreviate:25}} has invited you to join the team "{{ team|abbreviate:25 }}"{% if organization %}, part of the organization "{{ organization|abbreviate:25 }}"{% endif %}.
|
||||
|
||||
Accept invitation using this link:
|
||||
|
||||
|
||||
@ -111,7 +111,7 @@
|
||||
[:host {:optional true} :string]
|
||||
[:port {:optional true} ::sm/int]
|
||||
[:bind-dn {:optional true} :string]
|
||||
[:bind-passwor {:optional true} :string]
|
||||
[:bind-password {:optional true} :string]
|
||||
[:query {:optional true} :string]
|
||||
[:base-dn {:optional true} :string]
|
||||
[:attrs-email {:optional true} :string]
|
||||
|
||||
@ -401,8 +401,9 @@
|
||||
|
||||
(defn- parse-attr-path
|
||||
[provider path]
|
||||
(let [[fitem & items] (str/split path "__")]
|
||||
(into [(keyword (:type provider) fitem)] (map keyword) items)))
|
||||
(let [separator (if (str/includes? path "__") "__" ".")
|
||||
[fitem & items] (str/split path separator)]
|
||||
(into [(keyword (:type provider) (str/kebab fitem))] (map keyword) items)))
|
||||
|
||||
(defn- build-redirect-uri
|
||||
[]
|
||||
@ -488,9 +489,9 @@
|
||||
(let [attr-ph (parse-attr-path provider "nickname")]
|
||||
(get-in props attr-ph))))]
|
||||
|
||||
(let [info (assoc info :provider-id (str (:id provider)))
|
||||
props (qualify-props provider info)
|
||||
email (get-email props)]
|
||||
(let [info (assoc info :provider-id (str (:id provider)))
|
||||
props (qualify-props provider info)
|
||||
email (get-email props)]
|
||||
{:backend (:type provider)
|
||||
:fullname (or (get-name props) email)
|
||||
:email email
|
||||
@ -547,16 +548,29 @@
|
||||
(def ^:private valid-info?
|
||||
(sm/validator schema:info))
|
||||
|
||||
(defn- select-user-info-source
|
||||
"Normalise the provider's configured user-info source into a keyword the
|
||||
dispatch below can match. The raw value comes from config as a string
|
||||
per the malli schema in `app.config` (`\"token\"`, `\"userinfo\"`, or
|
||||
`\"auto\"`) and from hard-coded per-provider maps as strings as well;
|
||||
any unrecognised or missing value falls back to `:auto` (prefer claims,
|
||||
use userinfo as fallback)."
|
||||
[source]
|
||||
(case source
|
||||
"token" :token
|
||||
"userinfo" :userinfo
|
||||
:auto))
|
||||
|
||||
(defn- get-info
|
||||
[cfg provider state code]
|
||||
(let [tdata (fetch-access-token cfg provider code)
|
||||
claims (get-id-token-claims provider tdata)
|
||||
|
||||
info (case (get provider :user-info-source)
|
||||
:token (dissoc claims :exp :iss :iat :aud :sub :sid)
|
||||
info (case (select-user-info-source (get provider :user-info-source))
|
||||
:token (dissoc claims :exp :iss :iat :aud :sid)
|
||||
:userinfo (fetch-user-info cfg provider tdata)
|
||||
(or (some-> claims (dissoc :exp :iss :iat :aud :sub :sid))
|
||||
(fetch-user-info cfg provider tdata)))
|
||||
:auto (or (some-> claims (dissoc :exp :iss :iat :aud :sid))
|
||||
(fetch-user-info cfg provider tdata)))
|
||||
|
||||
info (process-user-info provider tdata info)]
|
||||
|
||||
|
||||
@ -412,6 +412,21 @@
|
||||
:id ::invite-to-team
|
||||
:schema schema:invite-to-team))
|
||||
|
||||
(def ^:private schema:invite-to-org
|
||||
[:map
|
||||
[:invited-by ::sm/text]
|
||||
[:organization-name ::sm/text]
|
||||
[:organization-initials [:maybe :string]]
|
||||
[:organization-logo ::sm/uri]
|
||||
[:user-name [:maybe ::sm/text]]
|
||||
[:token ::sm/text]])
|
||||
|
||||
(def invite-to-org
|
||||
"Org member invitation email."
|
||||
(template-factory
|
||||
:id ::invite-to-org
|
||||
:schema schema:invite-to-org))
|
||||
|
||||
(def ^:private schema:join-team
|
||||
[:map
|
||||
[:invited-by ::sm/text]
|
||||
|
||||
@ -112,8 +112,9 @@
|
||||
THEN (c.deleted_at IS NULL OR c.deleted_at >= ?::timestamptz)
|
||||
END"))
|
||||
|
||||
(defn- get-snapshot
|
||||
"Get snapshot with decoded data"
|
||||
(defn get-snapshot-data
|
||||
"Get a fully decoded snapshot for read-only preview or restoration.
|
||||
Returns the snapshot map with decoded :data field."
|
||||
[cfg file-id snapshot-id]
|
||||
(let [now (ct/now)]
|
||||
(->> (db/get-with-sql cfg [sql:get-snapshot file-id snapshot-id now]
|
||||
@ -326,7 +327,7 @@
|
||||
(sto/resolve cfg {::db/reuse-conn true})
|
||||
|
||||
snapshot
|
||||
(get-snapshot cfg file-id snapshot-id)]
|
||||
(get-snapshot-data cfg file-id snapshot-id)]
|
||||
|
||||
(when-not snapshot
|
||||
(ex/raise :type :not-found
|
||||
|
||||
@ -471,8 +471,14 @@
|
||||
{:name "0146-mod-access-token-table"
|
||||
:fn (mg/resource "app/migrations/sql/0146-mod-access-token-table.sql")}
|
||||
|
||||
{:name "0147-mod-team-invitation-table"
|
||||
:fn (mg/resource "app/migrations/sql/0147-mod-team-invitation-table.sql")}
|
||||
|
||||
{:name "0147-add-upload-session-table"
|
||||
:fn (mg/resource "app/migrations/sql/0147-add-upload-session-table.sql")}])
|
||||
:fn (mg/resource "app/migrations/sql/0147-add-upload-session-table.sql")}
|
||||
|
||||
{:name "0148-add-variant-name-team-font-variant"
|
||||
:fn (mg/resource "app/migrations/sql/0148-add-variant-name-team-font-variant.sql")}])
|
||||
|
||||
(defn apply-migrations!
|
||||
[pool name migrations]
|
||||
|
||||
@ -0,0 +1,13 @@
|
||||
ALTER TABLE team_invitation
|
||||
ADD COLUMN org_id uuid NULL;
|
||||
|
||||
ALTER TABLE team_invitation
|
||||
ALTER COLUMN team_id DROP NOT NULL;
|
||||
|
||||
ALTER TABLE team_invitation
|
||||
ADD CONSTRAINT team_invitation_team_or_org_not_null
|
||||
CHECK (team_id IS NOT NULL OR org_id IS NOT NULL);
|
||||
|
||||
CREATE UNIQUE INDEX team_invitation_org_unique
|
||||
ON team_invitation (org_id, email_to)
|
||||
WHERE team_id IS NULL;
|
||||
@ -0,0 +1,2 @@
|
||||
ALTER TABLE team_font_variant
|
||||
ADD COLUMN variant_name text NULL;
|
||||
@ -1,15 +1,23 @@
|
||||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;;
|
||||
;; Copyright (c) KALEIDOS INC
|
||||
|
||||
(ns app.nitrate
|
||||
"Module that make calls to the external nitrate aplication"
|
||||
(:require
|
||||
[app.common.exceptions :as ex]
|
||||
[app.common.json :as json]
|
||||
[app.common.logging :as l]
|
||||
[app.common.schema :as sm]
|
||||
[app.common.schema.generators :as sg]
|
||||
[app.common.time :as ct]
|
||||
[app.common.types.organization :as cto]
|
||||
[app.config :as cf]
|
||||
[app.http.client :as http]
|
||||
[app.rpc :as-alias rpc]
|
||||
[app.setup :as-alias setup]
|
||||
[app.util.json :as json]
|
||||
[clojure.core :as c]
|
||||
[integrant.core :as ig]))
|
||||
|
||||
@ -18,16 +26,16 @@
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(defn- request-builder
|
||||
[cfg method uri shared-key profile-id]
|
||||
[cfg method uri shared-key profile-id request-params]
|
||||
(fn []
|
||||
(http/req! cfg {:method method
|
||||
:headers {"content-type" "application/json"
|
||||
"accept" "application/json"
|
||||
"x-shared-key" shared-key
|
||||
"x-profile-id" (str profile-id)}
|
||||
:uri uri
|
||||
:version :http1.1})))
|
||||
|
||||
(http/req! cfg (cond-> {:method method
|
||||
:headers {"content-type" "application/json"
|
||||
"accept" "application/json"
|
||||
"x-shared-key" shared-key
|
||||
"x-profile-id" (str profile-id)}
|
||||
:uri uri
|
||||
:version :http1.1}
|
||||
(= method :post) (assoc :body (json/encode request-params :key-fn json/write-camel-key))))))
|
||||
|
||||
(defn- with-retries
|
||||
[handler max-retries]
|
||||
@ -47,24 +55,49 @@
|
||||
result)))))
|
||||
|
||||
|
||||
(defn- with-validate [handler uri schema]
|
||||
(defn- with-validate [handler uri schema & {:keys [throw-on-error?]}]
|
||||
(fn []
|
||||
(let [coercer-http (sm/coercer schema
|
||||
:type :validation
|
||||
:hint (str "invalid data received calling " uri))]
|
||||
(try
|
||||
(coercer-http (-> (handler) :body json/decode))
|
||||
(catch Exception e
|
||||
;; TODO Error handling
|
||||
(l/error :hint "error validating json response" :cause e)
|
||||
nil)))))
|
||||
(let [response (handler)
|
||||
status (:status response)]
|
||||
(when-not status
|
||||
(l/error :hint "could't do the nitrate request, it is probably down"
|
||||
:uri uri)
|
||||
;; TODO decide what to do when Nitrate is inaccesible
|
||||
nil)
|
||||
(cond
|
||||
(>= status 400)
|
||||
;; For error status codes (4xx, 5xx), fail immediately without validation
|
||||
(do
|
||||
(when (not= status 404) ;; Don't need to log 404
|
||||
(l/error :hint "nitrate request failed with error status"
|
||||
:uri uri
|
||||
:status status
|
||||
:body (:body response)))
|
||||
(if throw-on-error?
|
||||
(ex/raise :type :nitrate-http-error
|
||||
:status status
|
||||
:hint (str "nitrate HTTP " status " at " uri))
|
||||
nil))
|
||||
(= status 204) ;; 204 doesn't return any body
|
||||
nil
|
||||
:else ;; For success status codes, validate the response
|
||||
(let [coercer-http (sm/coercer schema
|
||||
:type :validation
|
||||
:hint (str "invalid data received calling " uri))
|
||||
data (-> response :body (json/decode :key-fn json/read-kebab-key))]
|
||||
(try
|
||||
(coercer-http data)
|
||||
(catch Exception e
|
||||
;; TODO Error handling
|
||||
(l/error :hint "error validating json response" :cause e)
|
||||
nil)))))))
|
||||
|
||||
(defn- request-to-nitrate
|
||||
[cfg method uri schema {:keys [::rpc/profile-id] :as params}]
|
||||
[cfg method uri schema {:keys [::rpc/profile-id request-params throw-on-error?] :as params}]
|
||||
(let [shared-key (-> cfg ::setup/shared-keys :nitrate)
|
||||
full-http-call (-> (request-builder cfg method uri shared-key profile-id)
|
||||
full-http-call (-> (request-builder cfg method uri shared-key profile-id request-params)
|
||||
(with-retries 3)
|
||||
(with-validate uri schema))]
|
||||
(with-validate uri schema :throw-on-error? throw-on-error?))]
|
||||
(full-http-call)))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
@ -80,11 +113,23 @@
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(def ^:private schema:organization
|
||||
(def ^:private schema:org-summary
|
||||
[:map
|
||||
[:id ::sm/uuid]
|
||||
[:name ::sm/text]
|
||||
[:slug ::sm/text]])
|
||||
[:owner-id ::sm/uuid]
|
||||
[:teams
|
||||
[:vector
|
||||
[:map
|
||||
[:id ::sm/uuid]
|
||||
[:is-your-penpot :boolean]]]]])
|
||||
|
||||
(def ^:private schema:profile-org
|
||||
[:map
|
||||
[:is-member :boolean]
|
||||
[:organization-id {:optional true} [:maybe ::sm/uuid]]
|
||||
[:default-team-id {:optional true} [:maybe ::sm/uuid]]])
|
||||
|
||||
|
||||
;; TODO Unify with schemas on backend/src/app/http/management.clj
|
||||
(def ^:private schema:timestamp
|
||||
@ -158,20 +203,158 @@
|
||||
[:map
|
||||
[:licenses ::sm/boolean]])
|
||||
|
||||
(defn- get-team-org
|
||||
(defn- get-team-org-api
|
||||
[cfg {:keys [team-id] :as params}]
|
||||
(let [baseuri (cf/get :nitrate-backend-uri)]
|
||||
(request-to-nitrate cfg :get (str baseuri "/api/teams/" (str team-id)) schema:organization params)))
|
||||
(request-to-nitrate cfg :get
|
||||
(str baseuri
|
||||
"/api/teams/"
|
||||
team-id)
|
||||
cto/schema:team-with-organization params)))
|
||||
|
||||
(defn- get-subscription
|
||||
(defn- get-org-membership-api
|
||||
[cfg {:keys [profile-id organization-id] :as params}]
|
||||
(let [baseuri (cf/get :nitrate-backend-uri)]
|
||||
(request-to-nitrate cfg :get
|
||||
(str baseuri
|
||||
"/api/organizations/"
|
||||
organization-id
|
||||
"/members/"
|
||||
profile-id)
|
||||
schema:profile-org params)))
|
||||
|
||||
(defn- get-org-membership-by-team-api
|
||||
[cfg {:keys [profile-id team-id] :as params}]
|
||||
(let [baseuri (cf/get :nitrate-backend-uri)]
|
||||
(request-to-nitrate cfg :get
|
||||
(str baseuri
|
||||
"/api/teams/"
|
||||
team-id
|
||||
"/users/"
|
||||
profile-id)
|
||||
schema:profile-org params)))
|
||||
|
||||
|
||||
(defn- get-org-summary-api
|
||||
[cfg {:keys [organization-id] :as params}]
|
||||
(let [baseuri (cf/get :nitrate-backend-uri)]
|
||||
(request-to-nitrate cfg :get
|
||||
(str baseuri
|
||||
"/api/organizations/"
|
||||
organization-id
|
||||
"/summary")
|
||||
schema:org-summary params)))
|
||||
|
||||
(defn- get-owned-orgs-api
|
||||
[cfg {:keys [profile-id] :as params}]
|
||||
(let [baseuri (cf/get :nitrate-backend-uri)]
|
||||
(request-to-nitrate cfg :get (str baseuri "/api/subscriptions/" (str profile-id)) schema:subscription params)))
|
||||
(request-to-nitrate cfg :get
|
||||
(str baseuri
|
||||
"/api/users/"
|
||||
profile-id
|
||||
"/owned-organizations")
|
||||
[:vector schema:org-summary]
|
||||
params)))
|
||||
|
||||
(defn- get-connectivity
|
||||
(defn- set-team-org-api
|
||||
[cfg {:keys [organization-id team-id is-default] :as params}]
|
||||
(let [baseuri (cf/get :nitrate-backend-uri)
|
||||
params (assoc params :request-params {:team-id team-id
|
||||
:is-your-penpot (true? is-default)})
|
||||
team (request-to-nitrate cfg :post
|
||||
(str baseuri
|
||||
"/api/organizations/"
|
||||
organization-id
|
||||
"/add-team")
|
||||
cto/schema:team-with-organization params)
|
||||
custom-photo (when-let [logo-id (get-in team [:organization :logo-id])]
|
||||
(str (cf/get :public-uri) "/assets/by-id/" logo-id))]
|
||||
(cond-> team
|
||||
custom-photo
|
||||
(assoc-in [:organization :custom-photo] custom-photo))))
|
||||
|
||||
(defn- add-profile-to-org-api
|
||||
[cfg {:keys [profile-id organization-id team-id email] :as params}]
|
||||
(let [baseuri (cf/get :nitrate-backend-uri)
|
||||
request-params (cond-> {:user-id profile-id :team-id team-id}
|
||||
(some? email) (assoc :email email))
|
||||
params (assoc params :request-params request-params)]
|
||||
(request-to-nitrate cfg :post
|
||||
(str baseuri
|
||||
"/api/organizations/"
|
||||
organization-id
|
||||
"/add-user")
|
||||
schema:profile-org params)))
|
||||
|
||||
(defn- remove-profile-from-org-api
|
||||
[cfg {:keys [profile-id organization-id] :as params}]
|
||||
(let [baseuri (cf/get :nitrate-backend-uri)
|
||||
params (assoc params :request-params {:user-id profile-id})]
|
||||
(request-to-nitrate cfg :post
|
||||
(str baseuri
|
||||
"/api/organizations/"
|
||||
organization-id
|
||||
"/remove-user")
|
||||
nil params)))
|
||||
|
||||
(defn- remove-profile-from-all-orgs-api
|
||||
[cfg {:keys [profile-id] :as params}]
|
||||
(let [baseuri (cf/get :nitrate-backend-uri)]
|
||||
(request-to-nitrate cfg :post
|
||||
(str baseuri
|
||||
"/api/users/"
|
||||
profile-id
|
||||
"/remove-organizations")
|
||||
nil params)))
|
||||
|
||||
(defn- remove-team-from-org-api
|
||||
[cfg {:keys [team-id organization-id] :as params}]
|
||||
(let [baseuri (cf/get :nitrate-backend-uri)
|
||||
params (assoc params :request-params {:team-id team-id})]
|
||||
(request-to-nitrate cfg :post
|
||||
(str baseuri
|
||||
"/api/organizations/"
|
||||
organization-id
|
||||
"/remove-team")
|
||||
nil params)))
|
||||
|
||||
(defn- delete-team-api
|
||||
[cfg {:keys [team-id] :as params}]
|
||||
(let [baseuri (cf/get :nitrate-backend-uri)]
|
||||
(request-to-nitrate cfg :delete
|
||||
(str baseuri
|
||||
"/api/teams/"
|
||||
team-id)
|
||||
nil params)))
|
||||
|
||||
(defn- get-subscription-api
|
||||
[cfg {:keys [profile-id] :as params}]
|
||||
(let [baseuri (cf/get :nitrate-backend-uri)]
|
||||
(request-to-nitrate cfg :get
|
||||
(str baseuri
|
||||
"/api/subscriptions/"
|
||||
profile-id)
|
||||
schema:subscription params)))
|
||||
|
||||
(defn- get-connectivity-api
|
||||
[cfg params]
|
||||
(let [baseuri (cf/get :nitrate-backend-uri)]
|
||||
(request-to-nitrate cfg :get (str baseuri "/api/connectivity") schema:connectivity params)))
|
||||
(request-to-nitrate cfg :get
|
||||
(str baseuri
|
||||
"/api/connectivity")
|
||||
schema:connectivity params)))
|
||||
|
||||
(def ^:private schema:redeem-result
|
||||
[:map
|
||||
[:cancel-at [:maybe schema:timestamp]]])
|
||||
|
||||
(defn- redeem-activation-code-api
|
||||
[cfg params]
|
||||
(let [baseuri (cf/get :nitrate-backend-uri)]
|
||||
(request-to-nitrate cfg :post
|
||||
(str baseuri "/api/activation-codes/redeem")
|
||||
schema:redeem-result
|
||||
(assoc params :throw-on-error? true))))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; INITIALIZATION
|
||||
@ -180,9 +363,20 @@
|
||||
(defmethod ig/init-key ::client
|
||||
[_ cfg]
|
||||
(when (contains? cf/flags :nitrate)
|
||||
{:get-team-org (partial get-team-org cfg)
|
||||
:get-subscription (partial get-subscription cfg)
|
||||
:connectivity (partial get-connectivity cfg)}))
|
||||
{:get-team-org (partial get-team-org-api cfg)
|
||||
:set-team-org (partial set-team-org-api cfg)
|
||||
:get-org-membership (partial get-org-membership-api cfg)
|
||||
:get-org-membership-by-team (partial get-org-membership-by-team-api cfg)
|
||||
:get-org-summary (partial get-org-summary-api cfg)
|
||||
:get-owned-orgs (partial get-owned-orgs-api cfg)
|
||||
:add-profile-to-org (partial add-profile-to-org-api cfg)
|
||||
:remove-profile-from-org (partial remove-profile-from-org-api cfg)
|
||||
:remove-profile-from-all-orgs (partial remove-profile-from-all-orgs-api cfg)
|
||||
:delete-team (partial delete-team-api cfg)
|
||||
:remove-team-from-org (partial remove-team-from-org-api cfg)
|
||||
:get-subscription (partial get-subscription-api cfg)
|
||||
:connectivity (partial get-connectivity-api cfg)
|
||||
:redeem-activation-code (partial redeem-activation-code-api cfg)}))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; UTILS
|
||||
@ -205,18 +399,18 @@
|
||||
|
||||
(defn add-org-info-to-team
|
||||
"Enriches a team map with organization information from Nitrate.
|
||||
Adds organization-id, organization-name, organization-slug, and your-penpot fields.
|
||||
Adds organization-id, organization-name, organization-slug, organization-owner-id, and your-penpot fields.
|
||||
Returns the original team unchanged if the request fails or org data is nil."
|
||||
[cfg team params]
|
||||
(try
|
||||
(let [params (assoc (or params {}) :team-id (:id team))
|
||||
org (call cfg :get-team-org params)]
|
||||
(let [params (assoc (or params {}) :team-id (:id team))
|
||||
team-with-org (call cfg :get-team-org params)
|
||||
org (:organization team-with-org)]
|
||||
(if (some? org)
|
||||
(assoc team
|
||||
:organization-id (:id org)
|
||||
:organization-name (:name org)
|
||||
:organization-slug (:slug org)
|
||||
:is-default (or (:is-default team) (true? (:isYourPenpot org))))
|
||||
(-> (cto/apply-organization team (assoc org :custom-photo
|
||||
(when-let [logo-id (:logo-id org)]
|
||||
(str (cf/get :public-uri) "/assets/by-id/" logo-id))))
|
||||
(assoc :is-default (or (:is-default team) (true? (:is-your-penpot team-with-org)))))
|
||||
team))
|
||||
(catch Throwable cause
|
||||
(l/error :hint "failed to get team organization info"
|
||||
@ -224,6 +418,23 @@
|
||||
:cause cause)
|
||||
team)))
|
||||
|
||||
(defn connectivity
|
||||
[cfg]
|
||||
(call cfg :connectivity {}))
|
||||
(defn set-team-organization
|
||||
"Associates a team with an organization in Nitrate.
|
||||
Requires organization-id and is-default in params.
|
||||
Throws an exception if the request fails."
|
||||
[cfg team params]
|
||||
(let [params (assoc (or params {})
|
||||
:team-id (:id team)
|
||||
:organization-id (:organization-id params)
|
||||
:is-default (:is-default params))
|
||||
result (call cfg :set-team-org params)]
|
||||
(when (nil? result)
|
||||
(ex/raise :type :internal
|
||||
:code :failed-to-set-team-org
|
||||
:context {:team-id (:id team)
|
||||
:organization-id (:organization-id params)}))
|
||||
team))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -372,9 +372,11 @@
|
||||
(throw cause))))))
|
||||
|
||||
(defn create-profile-rels
|
||||
[conn {:keys [id] :as profile}]
|
||||
[{:keys [::db/conn] :as cfg} {:keys [id] :as profile}]
|
||||
(assert (db/connection-map? cfg)
|
||||
"expected cfg with valid connection")
|
||||
(let [features (cfeat/get-enabled-features cf/flags)
|
||||
team (teams/create-team conn
|
||||
team (teams/create-team cfg
|
||||
{:profile-id id
|
||||
:name "Default"
|
||||
:features features
|
||||
@ -429,7 +431,7 @@
|
||||
(assoc :is-active is-active)
|
||||
(update :password auth/derive-password))
|
||||
profile (->> (create-profile cfg params)
|
||||
(create-profile-rels conn))]
|
||||
(create-profile-rels cfg))]
|
||||
(vary-meta profile assoc :created true))))
|
||||
|
||||
created? (-> profile meta :created true?)
|
||||
|
||||
@ -49,9 +49,9 @@
|
||||
:deleted-at (ct/in-future (cf/get-deletion-delay))
|
||||
:password (derive-password password)
|
||||
:props {}}
|
||||
profile (db/tx-run! cfg (fn [{:keys [::db/conn] :as cfg}]
|
||||
profile (db/tx-run! cfg (fn [cfg]
|
||||
(->> (auth/create-profile cfg params)
|
||||
(auth/create-profile-rels conn))))]
|
||||
(auth/create-profile-rels cfg))))]
|
||||
(with-meta {:email email
|
||||
:password password}
|
||||
{::audit/profile-id (:id profile)})))
|
||||
|
||||
@ -13,6 +13,7 @@
|
||||
[app.common.features :as cfeat]
|
||||
[app.common.files.helpers :as cfh]
|
||||
[app.common.files.migrations :as fmg]
|
||||
[app.common.files.stats :as cfs]
|
||||
[app.common.logging :as l]
|
||||
[app.common.schema :as sm]
|
||||
[app.common.schema.desc-js-like :as-alias smdj]
|
||||
@ -606,6 +607,76 @@
|
||||
(get-file-summary cfg id))
|
||||
|
||||
|
||||
;; --- COMMAND QUERY: get-file-stats
|
||||
|
||||
(def ^:private sql:file-stats-library-counts
|
||||
"SELECT
|
||||
(SELECT COUNT(*)
|
||||
FROM file_library_rel AS flr
|
||||
JOIN file AS fl ON (fl.id = flr.library_file_id)
|
||||
WHERE flr.file_id = ?::uuid
|
||||
AND (fl.deleted_at IS NULL OR fl.deleted_at > now())) AS library_count,
|
||||
(SELECT COUNT(*)
|
||||
FROM file_library_rel AS flr
|
||||
JOIN file AS fl ON (fl.id = flr.file_id)
|
||||
WHERE flr.library_file_id = ?::uuid
|
||||
AND (fl.deleted_at IS NULL OR fl.deleted_at > now())) AS referenced_by_count")
|
||||
|
||||
(defn- get-file-stats-library-counts
|
||||
[conn file-id]
|
||||
(let [row (db/exec-one! conn [sql:file-stats-library-counts file-id file-id])]
|
||||
{:library-count (or (:library-count row) 0)
|
||||
:referenced-by-count (or (:referenced-by-count row) 0)}))
|
||||
|
||||
(defn- get-file-stats
|
||||
[{:keys [::db/conn] :as cfg} file-id]
|
||||
(let [file (bfc/get-file cfg file-id)
|
||||
base (binding [pmap/*load-fn* (partial feat.fdata/load-pointer cfg file-id)]
|
||||
(cfs/calc-file-stats (:data file)))
|
||||
lib-cnt (get-file-stats-library-counts conn file-id)]
|
||||
(-> base
|
||||
(merge lib-cnt)
|
||||
(assoc :file-id file-id
|
||||
:revn (:revn file)
|
||||
:updated-at (:modified-at file)))))
|
||||
|
||||
(def ^:private schema:shape-counts
|
||||
[:map {:title "FileStatsShapeCounts"}
|
||||
[:total [::sm/int {:min 0}]]
|
||||
[:by-type [:map-of :keyword [::sm/int {:min 0}]]]])
|
||||
|
||||
(def ^:private schema:get-file-stats-result
|
||||
[:map {:title "FileStats"}
|
||||
[:file-id ::sm/uuid]
|
||||
[:page-count [::sm/int {:min 0}]]
|
||||
[:shape-counts schema:shape-counts]
|
||||
[:component-count [::sm/int {:min 0}]]
|
||||
[:deleted-component-count [::sm/int {:min 0}]]
|
||||
[:color-count [::sm/int {:min 0}]]
|
||||
[:typography-count [::sm/int {:min 0}]]
|
||||
[:library-count [::sm/int {:min 0}]]
|
||||
[:referenced-by-count [::sm/int {:min 0}]]
|
||||
[:revn [::sm/int {:min 0}]]
|
||||
[:updated-at ::ct/inst]])
|
||||
|
||||
(def ^:private schema:get-file-stats
|
||||
[:map {:title "get-file-stats"}
|
||||
[:id ::sm/uuid]])
|
||||
|
||||
(sv/defmethod ::get-file-stats
|
||||
"Return aggregate statistics for a single file: page count, shape
|
||||
counts by type, component/color/typography counts, and inbound and
|
||||
outbound library reference counts. Cheap alternative to `get-file`
|
||||
when only metrics are needed."
|
||||
{::doc/added "2.17"
|
||||
::sm/params schema:get-file-stats
|
||||
::sm/result schema:get-file-stats-result
|
||||
::db/transaction true}
|
||||
[{:keys [::db/conn] :as cfg} {:keys [::rpc/profile-id id]}]
|
||||
(check-read-permissions! conn profile-id id)
|
||||
(get-file-stats cfg id))
|
||||
|
||||
|
||||
;; --- COMMAND QUERY: get-file-libraries
|
||||
|
||||
(def ^:private schema:get-file-libraries
|
||||
@ -1155,38 +1226,39 @@
|
||||
AND t.id = ?
|
||||
AND f.id = ANY(?::uuid[])")
|
||||
|
||||
(defn- restore-file
|
||||
[conn file-id]
|
||||
(db/update! conn :file
|
||||
{:deleted-at nil
|
||||
:has-media-trimmed false}
|
||||
{:id file-id}
|
||||
{::db/return-keys false})
|
||||
(def ^:private sql:restore-files
|
||||
"UPDATE file SET deleted_at = null, has_media_trimmed = false
|
||||
WHERE id = ANY(?::uuid[])")
|
||||
|
||||
(db/update! conn :file-media-object
|
||||
{:deleted-at nil}
|
||||
{:file-id file-id}
|
||||
{::db/return-keys false})
|
||||
(def ^:private sql:restore-file-media-objects
|
||||
"UPDATE file_media_object SET deleted_at = null
|
||||
WHERE file_id = ANY(?::uuid[])")
|
||||
|
||||
(db/update! conn :file-change
|
||||
{:deleted-at nil}
|
||||
{:file-id file-id}
|
||||
{::db/return-keys false})
|
||||
(def ^:private sql:restore-file-changes
|
||||
"UPDATE file_change SET deleted_at = null
|
||||
WHERE file_id = ANY(?::uuid[])")
|
||||
|
||||
(db/update! conn :file-data
|
||||
{:deleted-at nil}
|
||||
{:file-id file-id}
|
||||
{::db/return-keys false})
|
||||
(def ^:private sql:restore-file-data
|
||||
"UPDATE file_data SET deleted_at = null
|
||||
WHERE file_id = ANY(?::uuid[])")
|
||||
|
||||
(db/update! conn :file-thumbnail
|
||||
{:deleted-at nil}
|
||||
{:file-id file-id}
|
||||
{::db/return-keys false})
|
||||
(def ^:private sql:restore-file-thumbnails
|
||||
"UPDATE file_thumbnail SET deleted_at = null
|
||||
WHERE file_id = ANY(?::uuid[])")
|
||||
|
||||
(db/update! conn :file-tagged-object-thumbnail
|
||||
{:deleted-at nil}
|
||||
{:file-id file-id}
|
||||
{::db/return-keys false}))
|
||||
(def ^:private sql:restore-file-tagged-object-thumbnails
|
||||
"UPDATE file_tagged_object_thumbnail SET deleted_at = null
|
||||
WHERE file_id = ANY(?::uuid[])")
|
||||
|
||||
(defn- restore-files
|
||||
[conn file-ids]
|
||||
(let [file-ids (db/create-array conn "uuid" file-ids)]
|
||||
(db/exec-one! conn [sql:restore-files file-ids])
|
||||
(db/exec-one! conn [sql:restore-file-media-objects file-ids])
|
||||
(db/exec-one! conn [sql:restore-file-changes file-ids])
|
||||
(db/exec-one! conn [sql:restore-file-data file-ids])
|
||||
(db/exec-one! conn [sql:restore-file-thumbnails file-ids])
|
||||
(db/exec-one! conn [sql:restore-file-tagged-object-thumbnails file-ids])))
|
||||
|
||||
(def ^:private sql:restore-projects
|
||||
"UPDATE project SET deleted_at = null WHERE id = ANY(?::uuid[])")
|
||||
@ -1207,17 +1279,18 @@
|
||||
(reduce (fn [result {:keys [id project-id]}]
|
||||
(let [index (-> result :files count)]
|
||||
(events/tap :progress {:file-id id :index (inc index) :total total-files})
|
||||
(restore-file conn id)
|
||||
|
||||
(-> result
|
||||
(update :files conj id)
|
||||
(update :projects conj project-id))))
|
||||
|
||||
{:files #{} :projectes #{}}
|
||||
{:files #{} :projects #{}}
|
||||
(db/plan conn [sql:resolve-editable-files team-id
|
||||
(db/create-array conn "uuid" ids)]))]
|
||||
|
||||
(restore-projects conn projects)
|
||||
(when (seq files)
|
||||
(restore-files conn files))
|
||||
|
||||
(when (seq projects)
|
||||
(restore-projects conn projects))
|
||||
|
||||
files))
|
||||
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
(:require
|
||||
[app.binfile.common :as bfc]
|
||||
[app.common.exceptions :as ex]
|
||||
[app.common.features :as-alias cfeat]
|
||||
[app.common.schema :as sm]
|
||||
[app.common.time :as ct]
|
||||
[app.db :as db]
|
||||
@ -35,6 +36,43 @@
|
||||
(files/check-read-permissions! conn profile-id file-id)
|
||||
(fsnap/get-visible-snapshots conn file-id))))
|
||||
|
||||
;; --- COMMAND QUERY: get-file-snapshot
|
||||
|
||||
(def ^:private schema:get-file-snapshot
|
||||
[:map {:title "get-file-snapshot"}
|
||||
[:file-id ::sm/uuid]
|
||||
[:id ::sm/uuid]
|
||||
[:features {:optional true} ::cfeat/features]])
|
||||
|
||||
(sv/defmethod ::get-file-snapshot
|
||||
"Retrieve a file bundle with data from a specific snapshot for
|
||||
read-only preview. Does not modify any database state."
|
||||
{::doc/added "2.16"
|
||||
::sm/params schema:get-file-snapshot
|
||||
::sm/result files/schema:file-with-permissions
|
||||
::db/transaction true}
|
||||
[{:keys [::db/conn] :as cfg} {:keys [::rpc/profile-id file-id id] :as params}]
|
||||
(let [perms (bfc/get-file-permissions conn profile-id file-id)]
|
||||
(files/check-read-permissions! perms)
|
||||
(let [snapshot (fsnap/get-snapshot-data cfg file-id id)]
|
||||
(when-not snapshot
|
||||
(ex/raise :type :not-found
|
||||
:code :snapshot-not-found
|
||||
:hint "unable to find snapshot with the provided id"
|
||||
:snapshot-id id
|
||||
:file-id file-id))
|
||||
;; Load current file metadata only (no data decoding) then overlay
|
||||
;; the snapshot data so the client receives the same shape as a
|
||||
;; normal get-file response but with historical page/object content.
|
||||
(let [base-file (bfc/get-file cfg file-id :load-data? false)]
|
||||
(-> base-file
|
||||
(assoc :data (:data snapshot))
|
||||
(assoc :version (:version snapshot))
|
||||
(assoc :features (:features snapshot))
|
||||
(assoc :revn (:revn snapshot))
|
||||
(assoc :vern (rand-int 100000))
|
||||
(assoc :permissions perms))))))
|
||||
|
||||
(def ^:private schema:create-file-snapshot
|
||||
[:map
|
||||
[:file-id ::sm/uuid]
|
||||
|
||||
@ -98,7 +98,8 @@
|
||||
[:font-id ::sm/uuid]
|
||||
[:font-family ::sm/text]
|
||||
[:font-weight [::sm/one-of {:format "number"} valid-weight]]
|
||||
[:font-style [::sm/one-of {:format "string"} valid-style]]])
|
||||
[:font-style [::sm/one-of {:format "string"} valid-style]]
|
||||
[:variant-name {:optional true} [:maybe ::sm/text]]])
|
||||
|
||||
;; FIXME: IMPORTANT: refactor this, we should not hold a whole db
|
||||
;; connection around the font creation
|
||||
@ -184,6 +185,7 @@
|
||||
:font-family (:font-family params)
|
||||
:font-weight (:font-weight params)
|
||||
:font-style (:font-style params)
|
||||
:variant-name (:variant-name params)
|
||||
:woff1-file-id (:id woff1)
|
||||
:woff2-file-id (:id woff2)
|
||||
:otf-file-id (:id otf)
|
||||
|
||||
@ -42,7 +42,7 @@
|
||||
(when-not provider
|
||||
(ex/raise :type :restriction
|
||||
:code :ldap-not-initialized
|
||||
:hide "ldap auth provider is not initialized"))
|
||||
:hint "ldap auth provider is not initialized"))
|
||||
|
||||
(let [info (ldap/authenticate provider params)]
|
||||
(when-not info
|
||||
@ -84,5 +84,5 @@
|
||||
(profile/get-profile-by-email conn))
|
||||
(->> (assoc info :is-active true :is-demo false)
|
||||
(auth/create-profile cfg)
|
||||
(auth/create-profile-rels conn)
|
||||
(auth/create-profile-rels cfg)
|
||||
(profile/strip-private-attrs))))))
|
||||
|
||||
@ -207,8 +207,7 @@
|
||||
(update :team-id bfc/lookup-index)
|
||||
(assoc :created-at timestamp)
|
||||
(assoc :modified-at timestamp))]
|
||||
(db/insert! conn :team-profile-rel params
|
||||
{::db/return-keys false})))
|
||||
(teams/add-profile-to-team! cfg params {::db/return-keys false})))
|
||||
|
||||
;; Duplicate team fonts
|
||||
(doseq [font fonts]
|
||||
@ -339,6 +338,21 @@
|
||||
;; --- COMMAND: Move project
|
||||
|
||||
(defn move-project
|
||||
"Moves a project from one team to another.
|
||||
|
||||
Performs comprehensive validation including:
|
||||
- Permission checks on both source and destination teams
|
||||
- Team compatibility verification between source and destination
|
||||
- File features compatibility with destination team
|
||||
|
||||
The operation also:
|
||||
- Updates the project's team assignment
|
||||
- Cleans up any broken library relations after the move
|
||||
|
||||
Throws:
|
||||
- :cant-move-to-same-team if trying to move project to its current team
|
||||
- Permission exceptions if user lacks required permissions
|
||||
- Team compatibility exceptions if teams are incompatible"
|
||||
[{:keys [::db/conn] :as cfg} {:keys [profile-id team-id project-id] :as params}]
|
||||
(let [project (db/get-by-id conn :project project-id {:columns [:id :team-id]})
|
||||
pids (->> (db/query conn :project {:team-id (:team-id project)} {:columns [:id]})
|
||||
|
||||
@ -255,7 +255,7 @@
|
||||
[:session-id ::sm/uuid]])
|
||||
|
||||
(sv/defmethod ::create-upload-session
|
||||
{::doc/added "2.16"
|
||||
{::doc/added "2.17"
|
||||
::sm/params schema:create-upload-session
|
||||
::sm/result schema:create-upload-session-result}
|
||||
[{:keys [::db/pool] :as cfg}
|
||||
@ -293,7 +293,7 @@
|
||||
[:index ::sm/int]])
|
||||
|
||||
(sv/defmethod ::upload-chunk
|
||||
{::doc/added "2.16"
|
||||
{::doc/added "2.17"
|
||||
::sm/params schema:upload-chunk
|
||||
::sm/result schema:upload-chunk-result}
|
||||
[{:keys [::db/pool] :as cfg}
|
||||
@ -389,7 +389,7 @@
|
||||
[:id {:optional true} ::sm/uuid]])
|
||||
|
||||
(sv/defmethod ::assemble-file-media-object
|
||||
{::doc/added "2.16"
|
||||
{::doc/added "2.17"
|
||||
::sm/params schema:assemble-file-media-object
|
||||
::climit/id [[:process-image/by-profile ::rpc/profile-id]
|
||||
[:process-image/global]]}
|
||||
|
||||
@ -1,20 +1,319 @@
|
||||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;;
|
||||
;; Copyright (c) KALEIDOS INC
|
||||
|
||||
(ns app.rpc.commands.nitrate
|
||||
"Nitrate API for Penpot. Provides nitrate-related endpoints to be called
|
||||
from Penpot frontend."
|
||||
(:require
|
||||
[app.common.data :as d]
|
||||
[app.common.exceptions :as ex]
|
||||
[app.common.schema :as sm]
|
||||
[app.common.time :as ct]
|
||||
[app.db :as db]
|
||||
[app.nitrate :as nitrate]
|
||||
[app.rpc :as-alias rpc]
|
||||
[app.rpc.commands.teams :as teams]
|
||||
[app.rpc.doc :as-alias doc]
|
||||
[app.rpc.notifications :as notifications]
|
||||
[app.util.services :as sv]))
|
||||
|
||||
|
||||
(defn assert-is-owner [cfg profile-id team-id]
|
||||
(let [perms (teams/get-permissions cfg profile-id team-id)]
|
||||
(when-not (:is-owner perms)
|
||||
(ex/raise :type :validation
|
||||
:code :insufficient-permissions))))
|
||||
|
||||
(defn assert-not-default-team [cfg team-id]
|
||||
(let [team (teams/get-team-info cfg {:id team-id})]
|
||||
(when (:is-default team)
|
||||
(ex/raise :type :validation
|
||||
:code :cant-move-default-team))))
|
||||
|
||||
(defn assert-membership [cfg profile-id organization-id]
|
||||
(let [membership (nitrate/call cfg :get-org-membership {:profile-id profile-id
|
||||
:organization-id organization-id})]
|
||||
(when-not (:organization-id membership)
|
||||
(ex/raise :type :validation
|
||||
:code :organization-doesnt-exists))
|
||||
|
||||
(when-not (:is-member membership)
|
||||
(ex/raise :type :validation
|
||||
:code :user-doesnt-belong-organization))))
|
||||
|
||||
|
||||
(def schema:connectivity
|
||||
[:map {:title "nitrate-connectivity"}
|
||||
[:licenses ::sm/boolean]])
|
||||
|
||||
(sv/defmethod ::get-nitrate-connectivity
|
||||
{::rpc/auth false
|
||||
::doc/added "1.18"
|
||||
{::rpc/auth true
|
||||
::doc/added "2.14"
|
||||
::sm/params [:map]
|
||||
::sm/result schema:connectivity}
|
||||
[cfg _params]
|
||||
(nitrate/connectivity cfg))
|
||||
(nitrate/call cfg :connectivity {}))
|
||||
|
||||
(def ^:private schema:redeem-activation-code-params
|
||||
[:map {:title "RedeemActivationCodeParams"}
|
||||
[:activation-code ::sm/text]])
|
||||
|
||||
(def ^:private schema:redeem-activation-code-result
|
||||
[:map {:title "RedeemActivationCodeResult"}
|
||||
[:cancel-at [:maybe ct/schema:inst]]])
|
||||
|
||||
(sv/defmethod ::redeem-nitrate-activation-code
|
||||
{::rpc/auth true
|
||||
::doc/added "2.14"
|
||||
::sm/params schema:redeem-activation-code-params
|
||||
::sm/result schema:redeem-activation-code-result}
|
||||
[cfg {:keys [::rpc/profile-id activation-code]}]
|
||||
(let [profile (db/get cfg :profile {:id profile-id})]
|
||||
(try
|
||||
(let [result (nitrate/call cfg :redeem-activation-code
|
||||
{:request-params {:code activation-code
|
||||
:penpot-id profile-id
|
||||
:email (:email profile)}})]
|
||||
(when-not result
|
||||
(ex/raise :type :validation
|
||||
:code :invalid-activation-code
|
||||
:hint "The activation code is invalid, expired or fully redeemed"))
|
||||
result)
|
||||
(catch Exception cause
|
||||
(let [{:keys [type status]} (ex-data cause)]
|
||||
(if (= type :nitrate-http-error)
|
||||
(ex/raise :type :validation
|
||||
:code (case status
|
||||
410 :expired-activation-code
|
||||
:invalid-activation-code)
|
||||
:cause cause)
|
||||
(throw cause)))))))
|
||||
|
||||
(def ^:private sql:prefix-team-name-and-unset-default
|
||||
"UPDATE team
|
||||
SET name = ? || name,
|
||||
is_default = FALSE
|
||||
WHERE id = ?;")
|
||||
|
||||
(def ^:private sql:get-member-teams-info
|
||||
"SELECT t.id,
|
||||
t.is_default,
|
||||
tpr.is_owner,
|
||||
(SELECT count(*) FROM team_profile_rel WHERE team_id = t.id) AS num_members,
|
||||
(SELECT array_agg(profile_id) FROM team_profile_rel WHERE team_id = t.id) AS member_ids
|
||||
FROM team AS t
|
||||
JOIN team_profile_rel AS tpr ON (tpr.team_id = t.id)
|
||||
WHERE tpr.profile_id = ?
|
||||
AND t.id = ANY(?)
|
||||
AND t.deleted_at IS NULL")
|
||||
|
||||
(def sql:get-team-files-count
|
||||
"SELECT count(*) AS total
|
||||
FROM file AS f
|
||||
JOIN project AS p ON (p.id = f.project_id)
|
||||
WHERE p.team_id = ?
|
||||
AND f.deleted_at IS NULL")
|
||||
|
||||
(def ^:private schema:leave-org
|
||||
[:map
|
||||
[:id ::sm/uuid]
|
||||
[:name ::sm/text]
|
||||
[:default-team-id ::sm/uuid]
|
||||
[:teams-to-delete
|
||||
[:vector ::sm/uuid]]
|
||||
[:teams-to-leave
|
||||
[:vector
|
||||
[:map
|
||||
[:id ::sm/uuid]
|
||||
[:reassign-to {:optional true} ::sm/uuid]]]]])
|
||||
|
||||
|
||||
(defn- get-organization-teams-for-user
|
||||
[{:keys [::db/conn] :as cfg} org-summary profile-id]
|
||||
(let [org-team-ids (->> (:teams org-summary)
|
||||
(map :id))
|
||||
ids-array (db/create-array conn "uuid" org-team-ids)]
|
||||
(db/exec! conn [sql:get-member-teams-info profile-id ids-array])))
|
||||
|
||||
(defn- calculate-valid-teams
|
||||
([org-teams default-team-id]
|
||||
(let [;; valid default team is the one which id is default-team-id
|
||||
valid-default-team (d/seek #(= default-team-id (:id %)) org-teams)
|
||||
|
||||
;; Remove your-penpot for the rest of validations
|
||||
org-teams (remove #(= default-team-id (:id %)) org-teams)
|
||||
|
||||
;; valid teams to delete are those that the user is owner, and only have one member
|
||||
valid-teams-to-delete-ids (->> org-teams
|
||||
(filter #(and (:is-owner %)
|
||||
(= (:num-members %) 1)))
|
||||
(map :id)
|
||||
(into #{}))
|
||||
;; valid teams to transfer are those that the user is owner, and have more than one member
|
||||
valid-teams-to-transfer (->> org-teams
|
||||
(filter #(and (:is-owner %)
|
||||
(> (:num-members %) 1))))
|
||||
|
||||
;; valid teams to exit are those that the user isn't owner, and have more than one member
|
||||
valid-teams-to-exit (->> org-teams
|
||||
(filter #(and (not (:is-owner %))
|
||||
(> (:num-members %) 1))))]
|
||||
{:valid-teams-to-delete-ids valid-teams-to-delete-ids
|
||||
:valid-teams-to-transfer valid-teams-to-transfer
|
||||
:valid-teams-to-exit valid-teams-to-exit
|
||||
:valid-default-team valid-default-team})))
|
||||
|
||||
(defn get-valid-teams [cfg organization-id profile-id default-team-id]
|
||||
(let [org-summary (nitrate/call cfg :get-org-summary {:organization-id organization-id})
|
||||
org-teams (get-organization-teams-for-user cfg org-summary profile-id)]
|
||||
(calculate-valid-teams org-teams default-team-id)))
|
||||
|
||||
(defn- assert-valid-teams [cfg profile-id organization-id default-team-id teams-to-delete teams-to-leave]
|
||||
(let [org-summary (nitrate/call cfg :get-org-summary {:organization-id organization-id})
|
||||
org-teams (get-organization-teams-for-user cfg org-summary profile-id)
|
||||
{:keys [valid-teams-to-delete-ids
|
||||
valid-teams-to-transfer
|
||||
valid-teams-to-exit
|
||||
valid-default-team]} (calculate-valid-teams org-teams default-team-id)
|
||||
|
||||
|
||||
|
||||
valid-teams-to-exit-ids (->> valid-teams-to-exit (map :id) (into #{}))
|
||||
valid-teams-to-transfer-ids (->> valid-teams-to-transfer (map :id) (into #{}))
|
||||
valid-teams-to-leave-ids (into valid-teams-to-transfer-ids valid-teams-to-exit-ids)
|
||||
|
||||
valid-default-team-id? (some? valid-default-team)
|
||||
|
||||
|
||||
|
||||
valid-teams-to-delete? (= valid-teams-to-delete-ids (into #{} teams-to-delete))
|
||||
|
||||
;; for every team in teams-to-leave, check that:
|
||||
;; - if it has a reassign-to, it belongs to valid-teams-to-transfer and
|
||||
;; the reassign-to is a member of the team and not the current user;
|
||||
;; - if it hasn't a reassign-to, check that it belongs to valid-teams-to-exit
|
||||
teams-by-id (d/index-by :id org-teams)
|
||||
valid-teams-to-leave? (and
|
||||
(= valid-teams-to-leave-ids (->> teams-to-leave (map :id) (into #{})))
|
||||
(every? (fn [{:keys [id reassign-to]}]
|
||||
(if reassign-to
|
||||
(let [members (db/pgarray->set (:member-ids (get teams-by-id id)))]
|
||||
(and (contains? valid-teams-to-transfer-ids id)
|
||||
(not= reassign-to profile-id)
|
||||
(contains? members reassign-to)))
|
||||
(contains? valid-teams-to-exit-ids id)))
|
||||
teams-to-leave))]
|
||||
;; the org owner cannot leave
|
||||
(when (= (:owner-id org-summary) profile-id)
|
||||
(ex/raise :type :validation
|
||||
:code :org-owner-cannot-leave))
|
||||
|
||||
(when (or
|
||||
(not valid-teams-to-delete?)
|
||||
(not valid-teams-to-leave?)
|
||||
(not valid-default-team-id?))
|
||||
(ex/raise :type :validation
|
||||
:code :not-valid-teams))))
|
||||
|
||||
|
||||
(defn leave-org
|
||||
[{:keys [::db/conn] :as cfg} {:keys [profile-id id name default-team-id teams-to-delete teams-to-leave skip-validation] :as params}]
|
||||
(let [org-prefix (str "[" (d/sanitize-string name) "] ")
|
||||
|
||||
default-team-files-count (-> (db/exec-one! conn [sql:get-team-files-count default-team-id])
|
||||
:total)
|
||||
delete-default-team? (= default-team-files-count 0)]
|
||||
|
||||
|
||||
|
||||
|
||||
;; assert that the received teams are valid, checking the different constraints
|
||||
(when-not skip-validation
|
||||
(assert-valid-teams cfg profile-id id default-team-id teams-to-delete teams-to-leave))
|
||||
|
||||
(assert-membership cfg profile-id id)
|
||||
|
||||
;; delete the teams-to-delete
|
||||
(doseq [id teams-to-delete]
|
||||
(teams/delete-team cfg {:profile-id profile-id :team-id id}))
|
||||
|
||||
;; leave the teams-to-leave
|
||||
(doseq [{:keys [id reassign-to]} teams-to-leave]
|
||||
(teams/leave-team cfg {:profile-id profile-id :id id :reassign-to reassign-to}))
|
||||
|
||||
;; Delete default-team-id if empty; otherwise keep it and prefix the name.
|
||||
(if delete-default-team?
|
||||
(do
|
||||
(db/update! conn :team {:is-default false} {:id default-team-id})
|
||||
(teams/delete-team cfg {:profile-id profile-id :team-id default-team-id}))
|
||||
(db/exec! conn [sql:prefix-team-name-and-unset-default org-prefix default-team-id]))
|
||||
|
||||
;; Api call to nitrate
|
||||
(nitrate/call cfg :remove-profile-from-org {:profile-id profile-id :organization-id id})
|
||||
|
||||
nil))
|
||||
|
||||
|
||||
(sv/defmethod ::leave-org
|
||||
{::rpc/auth true
|
||||
::doc/added "2.15"
|
||||
::sm/params schema:leave-org
|
||||
::db/transaction true}
|
||||
[cfg {:keys [::rpc/profile-id] :as params}]
|
||||
(leave-org cfg (assoc params :profile-id profile-id)))
|
||||
|
||||
|
||||
(def ^:private schema:remove-team-from-org
|
||||
[:map
|
||||
[:team-id ::sm/uuid]
|
||||
[:organization-id ::sm/uuid]
|
||||
[:organization-name ::sm/text]])
|
||||
|
||||
(sv/defmethod ::remove-team-from-org
|
||||
{::doc/added "2.17"
|
||||
::sm/params schema:remove-team-from-org}
|
||||
[cfg {:keys [::rpc/profile-id team-id organization-id organization-name]}]
|
||||
|
||||
(assert-is-owner cfg profile-id team-id)
|
||||
(assert-not-default-team cfg team-id)
|
||||
(assert-membership cfg profile-id organization-id)
|
||||
|
||||
;; Api call to nitrate
|
||||
(nitrate/call cfg :remove-team-from-org {:team-id team-id :organization-id organization-id})
|
||||
|
||||
;; Notify connected users
|
||||
(notifications/notify-team-change cfg {:id team-id :organization {:name organization-name}} "dashboard.team-no-longer-belong-org")
|
||||
nil)
|
||||
|
||||
|
||||
(def ^:private schema:add-team-to-organization
|
||||
[:map
|
||||
[:team-id ::sm/uuid]
|
||||
[:organization-id ::sm/uuid]])
|
||||
|
||||
(sv/defmethod ::add-team-to-organization
|
||||
{::rpc/auth true
|
||||
::doc/added "2.17"
|
||||
::sm/params schema:add-team-to-organization
|
||||
::db/transaction true}
|
||||
[cfg {:keys [::rpc/profile-id team-id organization-id]}]
|
||||
|
||||
(assert-is-owner cfg profile-id team-id)
|
||||
(assert-not-default-team cfg team-id)
|
||||
(assert-membership cfg profile-id organization-id)
|
||||
|
||||
(let [team-members (db/query cfg :team-profile-rel {:team-id team-id})]
|
||||
;; Add teammates to the org if needed
|
||||
(doseq [{member-id :profile-id} team-members
|
||||
:when (not= member-id profile-id)]
|
||||
(teams/initialize-user-in-nitrate-org cfg member-id organization-id)))
|
||||
|
||||
;; Api call to nitrate
|
||||
(let [team (nitrate/call cfg :set-team-org {:team-id team-id :organization-id organization-id :is-default false})]
|
||||
|
||||
;; Notify connected users
|
||||
(notifications/notify-team-change cfg team "dashboard.team-belong-org"))
|
||||
nil)
|
||||
|
||||
@ -315,6 +315,25 @@
|
||||
(climit/invoke! generate-thumbnail file))]
|
||||
(sto/put-object! storage params)))
|
||||
|
||||
;; --- MUTATION: Delete Photo
|
||||
|
||||
(sv/defmethod ::delete-profile-photo
|
||||
{::doc/added "2.17"
|
||||
::sm/params [:map]
|
||||
::sm/result :nil
|
||||
::db/transaction true}
|
||||
[{:keys [::db/conn ::sto/storage]} {:keys [::rpc/profile-id]}]
|
||||
(let [profile (get-profile conn profile-id ::db/for-update true)]
|
||||
(when-let [id (:photo-id profile)]
|
||||
(sto/touch-object! storage id))
|
||||
|
||||
(db/update! conn :profile
|
||||
{:photo-id nil}
|
||||
{:id profile-id}
|
||||
{::db/return-keys false})
|
||||
|
||||
nil))
|
||||
|
||||
;; --- MUTATION: Request Email Change
|
||||
|
||||
(declare ^:private request-email-change!)
|
||||
@ -463,6 +482,9 @@
|
||||
{:deleted-at deleted-at}
|
||||
{:id profile-id})
|
||||
|
||||
;; Api call to nitrate
|
||||
(nitrate/call cfg :remove-profile-from-all-orgs {:profile-id profile-id})
|
||||
|
||||
;; Schedule cascade deletion to a worker
|
||||
(wrk/submit! {::db/conn conn
|
||||
::wrk/task :delete-object
|
||||
|
||||
@ -471,8 +471,8 @@
|
||||
;; --- COMMAND QUERY: get-team-info
|
||||
|
||||
(defn get-team-info
|
||||
[{:keys [::db/conn] :as cfg} {:keys [id] :as params}]
|
||||
(-> (db/get* conn :team
|
||||
[cfg {:keys [id] :as params}]
|
||||
(-> (db/get* cfg :team
|
||||
{:id id}
|
||||
{::sql/columns [:id :is-default :features]})
|
||||
(decode-row)))
|
||||
@ -499,7 +499,9 @@
|
||||
[:map {:title "create-team"}
|
||||
[:name types.team/schema:team-name]
|
||||
[:features {:optional true} ::cfeat/features]
|
||||
[:id {:optional true} ::sm/uuid]])
|
||||
[:id {:optional true} ::sm/uuid]
|
||||
[:organization-id {:optional true} ::sm/uuid]
|
||||
[:is-default {:optional true} :boolean]])
|
||||
|
||||
(sv/defmethod ::create-team
|
||||
{::doc/added "1.17"
|
||||
@ -520,17 +522,89 @@
|
||||
(with-meta team
|
||||
{::audit/props {:id (:id team)}})))
|
||||
|
||||
|
||||
(defn create-default-org-team
|
||||
[cfg profile-id organization-id]
|
||||
(quotes/check! cfg {::quotes/id ::quotes/teams-per-profile
|
||||
::quotes/profile-id profile-id})
|
||||
|
||||
(let [features (-> (cfeat/get-enabled-features cf/flags)
|
||||
(set/difference cfeat/frontend-only-features)
|
||||
(set/difference cfeat/no-team-inheritable-features))
|
||||
params {:profile-id profile-id
|
||||
:name "Your Penpot"
|
||||
:features features
|
||||
:organization-id organization-id
|
||||
:is-default true}
|
||||
team (create-team cfg params)]
|
||||
(select-keys team [:id])))
|
||||
|
||||
(defn initialize-user-in-nitrate-org
|
||||
"If needed, create a default team for the user on the organization,
|
||||
and notify Nitrate that an user has been added to an org."
|
||||
([cfg profile-id organization-id]
|
||||
(initialize-user-in-nitrate-org cfg profile-id organization-id nil))
|
||||
([cfg profile-id organization-id email]
|
||||
(assert (db/connection-map? cfg)
|
||||
"expected cfg with valid connection")
|
||||
(when (contains? cf/flags :nitrate)
|
||||
(db/tx-run!
|
||||
cfg
|
||||
(fn [{:keys [::db/conn] :as tx-cfg}]
|
||||
|
||||
(let [membership (nitrate/call cfg :get-org-membership {:profile-id profile-id
|
||||
:organization-id organization-id})]
|
||||
;; Only when the user doesn't belong to the organization yet
|
||||
(when (and
|
||||
(some? (:organization-id membership)) ;; the organization exists
|
||||
(not (:is-member membership))) ;; the user is not a member of the org yet
|
||||
|
||||
|
||||
(let [organization-id organization-id
|
||||
default-team (create-default-org-team (assoc tx-cfg ::db/conn conn) profile-id organization-id)
|
||||
default-team-id (:id default-team)
|
||||
result (nitrate/call tx-cfg :add-profile-to-org (cond-> {:profile-id profile-id
|
||||
:team-id default-team-id
|
||||
:organization-id organization-id}
|
||||
(some? email) (assoc :email email)))]
|
||||
(when (not (:is-member result))
|
||||
(ex/raise :type :internal
|
||||
:code :failed-add-profile-org-nitrate
|
||||
:context {:profile-id profile-id
|
||||
:organization-id organization-id
|
||||
:default-team-id default-team-id}))
|
||||
default-team-id))))))))
|
||||
|
||||
(defn add-profile-to-team!
|
||||
([cfg params]
|
||||
(add-profile-to-team! cfg params nil))
|
||||
([{:keys [::db/conn] :as cfg} {:keys [:profile-id :team-id] :as params} options]
|
||||
(assert (db/connection-map? cfg)
|
||||
"expected cfg with valid connection")
|
||||
(when (contains? cf/flags :nitrate)
|
||||
(let [membership (nitrate/call cfg :get-org-membership-by-team {:profile-id profile-id :team-id team-id})]
|
||||
;; Only when the team belong to an organization and the user is not a member
|
||||
(when (and
|
||||
(some? (:organization-id membership)) ;; the team do belong to an organization
|
||||
(not (:is-member membership))) ;; the user is not a member of the org yet
|
||||
(initialize-user-in-nitrate-org cfg profile-id (:organization-id membership)))))
|
||||
(db/insert! conn :team-profile-rel params options)))
|
||||
|
||||
(defn create-team
|
||||
"This is a complete team creation process, it creates the team
|
||||
object and all related objects (default role and default project)."
|
||||
[cfg-or-conn params]
|
||||
(let [conn (db/get-connection cfg-or-conn)
|
||||
team (create-team* conn params)
|
||||
[{:keys [::db/conn] :as cfg} params]
|
||||
(assert (db/connection-map? cfg)
|
||||
"expected cfg with valid connection")
|
||||
(let [team (create-team* conn params)
|
||||
params (assoc params
|
||||
:team-id (:id team)
|
||||
:role :owner)
|
||||
project (create-team-default-project conn params)]
|
||||
(create-team-role conn params)
|
||||
(create-team-role cfg params)
|
||||
;; Set team organization in Nitrate if organization-id is provided
|
||||
(when (and (contains? cf/flags :nitrate) (:organization-id params))
|
||||
(nitrate/set-team-organization cfg team params))
|
||||
(assoc team :default-project-id (:id project))))
|
||||
|
||||
(defn- create-team*
|
||||
@ -546,11 +620,13 @@
|
||||
(decode-row team)))
|
||||
|
||||
(defn- create-team-role
|
||||
[conn {:keys [profile-id team-id role] :as params}]
|
||||
[cfg {:keys [profile-id team-id role] :as params}]
|
||||
(assert (db/connection-map? cfg)
|
||||
"expected cfg with valid connection")
|
||||
(let [params {:team-id team-id
|
||||
:profile-id profile-id}]
|
||||
(->> (perms/assign-role-flags params role)
|
||||
(db/insert! conn :team-profile-rel))))
|
||||
(add-profile-to-team! cfg))))
|
||||
|
||||
(defn- create-team-default-project
|
||||
[conn {:keys [profile-id team-id] :as params}]
|
||||
@ -609,7 +685,7 @@
|
||||
;; --- Mutation: Leave Team
|
||||
|
||||
(defn leave-team
|
||||
[conn {:keys [profile-id id reassign-to]}]
|
||||
[{:keys [::db/conn ::mbus/msgbus]} {:keys [profile-id id reassign-to]}]
|
||||
(let [perms (get-permissions conn profile-id id)
|
||||
members (get-team-members conn id)]
|
||||
|
||||
@ -624,7 +700,9 @@
|
||||
;; if the `reassign-to` is filled and has a different value
|
||||
;; than the current profile-id, we proceed to reassing the
|
||||
;; owner role to profile identified by the `reassign-to`.
|
||||
(and reassign-to (not= reassign-to profile-id))
|
||||
;; Ignore the reasignation if the current profile is not
|
||||
;; the owner
|
||||
(and reassign-to (not= reassign-to profile-id) (:is-owner perms))
|
||||
(let [member (d/seek #(= reassign-to (:id %)) members)]
|
||||
(when-not member
|
||||
(ex/raise :type :not-found :code :member-does-not-exist))
|
||||
@ -638,7 +716,15 @@
|
||||
;; assign owner role to new profile
|
||||
(db/update! conn :team-profile-rel
|
||||
(get types.team/permissions-for-role :owner)
|
||||
{:team-id id :profile-id reassign-to}))
|
||||
{:team-id id :profile-id reassign-to})
|
||||
|
||||
;; notify new owner
|
||||
(mbus/pub! msgbus
|
||||
:topic reassign-to
|
||||
:message {:type :team-role-change
|
||||
:topic reassign-to
|
||||
:team-id id
|
||||
:role :owner}))
|
||||
|
||||
;; and finally, if all other conditions does not match and the
|
||||
;; current profile is owner, we dont allow it because there
|
||||
@ -663,32 +749,44 @@
|
||||
{::doc/added "1.17"
|
||||
::sm/params schema:leave-team
|
||||
::db/transaction true}
|
||||
[{:keys [::db/conn] :as cfg} {:keys [::rpc/profile-id] :as params}]
|
||||
(leave-team conn (assoc params :profile-id profile-id)))
|
||||
[cfg {:keys [::rpc/profile-id] :as params}]
|
||||
(leave-team cfg (assoc params :profile-id profile-id)))
|
||||
|
||||
|
||||
;; --- Mutation: Delete Team
|
||||
|
||||
(defn- delete-team
|
||||
(defn delete-team
|
||||
"Mark a team for deletion"
|
||||
[conn {:keys [id] :as team}]
|
||||
[{:keys [::db/conn] :as cfg} {:keys [profile-id team-id]}]
|
||||
|
||||
(let [delay (ldel/get-deletion-delay team)
|
||||
team (db/update! conn :team
|
||||
{:deleted-at (ct/in-future delay)}
|
||||
{:id id}
|
||||
{::db/return-keys true})]
|
||||
(let [team (get-team conn :profile-id profile-id :team-id team-id)
|
||||
perms (get team :permissions)]
|
||||
|
||||
(when-not (:is-owner perms)
|
||||
(ex/raise :type :validation
|
||||
:code :only-owner-can-delete-team))
|
||||
|
||||
(when (:is-default team)
|
||||
(ex/raise :type :validation
|
||||
:code :non-deletable-team
|
||||
:hint "impossible to delete default team"))
|
||||
|
||||
(wrk/submit! {::db/conn conn
|
||||
::wrk/task :delete-object
|
||||
::wrk/params {:object :team
|
||||
:deleted-at (:deleted-at team)
|
||||
:id id}})
|
||||
team))
|
||||
(let [delay (ldel/get-deletion-delay team)
|
||||
team (db/update! conn :team
|
||||
{:deleted-at (ct/in-future delay)}
|
||||
{:id team-id}
|
||||
{::db/return-keys true})]
|
||||
|
||||
;; Api call to nitrate
|
||||
(when (contains? cf/flags :nitrate)
|
||||
(nitrate/call cfg :delete-team {:profile-id profile-id :team-id team-id}))
|
||||
|
||||
(wrk/submit! {::db/conn conn
|
||||
::wrk/task :delete-object
|
||||
::wrk/params {:object :team
|
||||
:deleted-at (:deleted-at team)
|
||||
:id team-id}})
|
||||
team)))
|
||||
|
||||
(def ^:private schema:delete-team
|
||||
[:map {:title "delete-team"}
|
||||
@ -698,16 +796,9 @@
|
||||
{::doc/added "1.17"
|
||||
::sm/params schema:delete-team
|
||||
::db/transaction true}
|
||||
[{:keys [::db/conn] :as cfg} {:keys [::rpc/profile-id id] :as params}]
|
||||
(let [team (get-team conn :profile-id profile-id :team-id id)
|
||||
perms (get team :permissions)]
|
||||
|
||||
(when-not (:is-owner perms)
|
||||
(ex/raise :type :validation
|
||||
:code :only-owner-can-delete-team))
|
||||
|
||||
(delete-team conn team)
|
||||
nil))
|
||||
[cfg {:keys [::rpc/profile-id id] :as params}]
|
||||
(delete-team cfg {:team-id id :profile-id profile-id})
|
||||
nil)
|
||||
|
||||
;; --- Mutation: Team Update Role
|
||||
|
||||
|
||||
@ -22,6 +22,7 @@
|
||||
[app.email.blacklist :as email.blacklist]
|
||||
[app.loggers.audit :as audit]
|
||||
[app.main :as-alias main]
|
||||
[app.nitrate :as nitrate]
|
||||
[app.rpc :as-alias rpc]
|
||||
[app.rpc.commands.profile :as profile]
|
||||
[app.rpc.commands.teams :as teams]
|
||||
@ -36,20 +37,29 @@
|
||||
;; --- Mutation: Create Team Invitation
|
||||
|
||||
(def sql:upsert-team-invitation
|
||||
"insert into team_invitation(id, team_id, email_to, created_by, role, valid_until)
|
||||
values (?, ?, ?, ?, ?, ?)
|
||||
"insert into team_invitation(id, team_id, org_id, email_to, created_by, role, valid_until)
|
||||
values (?, ?, null, ?, ?, ?, ?)
|
||||
on conflict(team_id, email_to) do
|
||||
update set role = ?, valid_until = ?, updated_at = now()
|
||||
returning *")
|
||||
|
||||
(def sql:upsert-org-invitation
|
||||
"insert into team_invitation(id, team_id, org_id, email_to, created_by, role, valid_until)
|
||||
values (?, null, ?, ?, ?, ?, ?)
|
||||
on conflict(org_id, email_to) where team_id is null do
|
||||
update set role = ?, valid_until = ?, updated_at = now()
|
||||
returning *")
|
||||
|
||||
(defn- create-invitation-token
|
||||
[cfg {:keys [profile-id valid-until team-id member-id member-email role]}]
|
||||
[cfg {:keys [profile-id valid-until organization-id organization-name team-id member-id member-email role]}]
|
||||
(tokens/generate cfg
|
||||
{:iss :team-invitation
|
||||
:exp valid-until
|
||||
:profile-id profile-id
|
||||
:role role
|
||||
:team-id team-id
|
||||
:organization-id organization-id
|
||||
:organization-name organization-name
|
||||
:member-email member-email
|
||||
:member-id member-id}))
|
||||
|
||||
@ -75,19 +85,41 @@
|
||||
[:role types.team/schema:role]
|
||||
[:email ::sm/email]])
|
||||
|
||||
(def ^:private schema:create-org-invitation
|
||||
[:map {:title "params:create-org-invitation"}
|
||||
[::rpc/profile-id ::sm/uuid]
|
||||
[:organization
|
||||
[:map
|
||||
[:id ::sm/uuid]
|
||||
[:name :string]
|
||||
[:initials [:maybe :string]]
|
||||
[:logo ::sm/uri]]]
|
||||
[:profile
|
||||
[:map
|
||||
[:id ::sm/uuid]
|
||||
[:fullname :string]]]
|
||||
[:role types.team/schema:role]
|
||||
[:email ::sm/email]])
|
||||
|
||||
(def ^:private check-create-invitation-params
|
||||
(sm/check-fn schema:create-invitation))
|
||||
|
||||
(def ^:private check-create-org-invitation-params
|
||||
(sm/check-fn schema:create-org-invitation))
|
||||
|
||||
(defn- allow-invitation-emails?
|
||||
[member]
|
||||
(let [notifications (dm/get-in member [:props :notifications])]
|
||||
(not= :none (:email-invites notifications))))
|
||||
|
||||
(defn- create-invitation
|
||||
[{:keys [::db/conn] :as cfg} {:keys [team profile role email] :as params}]
|
||||
[{:keys [::db/conn] :as cfg} {:keys [team organization profile role email] :as params}]
|
||||
|
||||
(assert (db/connection? conn) "expected valid connection on cfg parameter")
|
||||
(assert (check-create-invitation-params params))
|
||||
(assert (db/connection-map? cfg)
|
||||
"expected cfg with valid connection")
|
||||
(if organization
|
||||
(assert (check-create-org-invitation-params params))
|
||||
(assert (check-create-invitation-params params)))
|
||||
|
||||
(let [email (profile/clean-email email)
|
||||
member (profile/get-profile-by-email conn email)]
|
||||
@ -110,9 +142,12 @@
|
||||
:profile-id (:id member)}
|
||||
(get types.team/permissions-for-role role))]
|
||||
|
||||
;; Insert the invited member to the team
|
||||
(db/insert! conn :team-profile-rel params
|
||||
{::db/on-conflict-do-nothing? true})
|
||||
(if organization
|
||||
;; Insert the invited member to the org
|
||||
(when (contains? cf/flags :nitrate)
|
||||
(teams/initialize-user-in-nitrate-org cfg (:id member) (:id organization) email))
|
||||
;; Insert the invited member to the team
|
||||
(teams/add-profile-to-team! cfg params {::db/on-conflict-do-nothing? true}))
|
||||
|
||||
;; If profile is not yet verified, mark it as verified because
|
||||
;; accepting an invitation link serves as verification.
|
||||
@ -129,18 +164,30 @@
|
||||
(teams/check-email-spam conn email true)
|
||||
|
||||
(let [id (uuid/next)
|
||||
expire (ct/in-future "168h") ;; 7 days
|
||||
invitation (db/exec-one! conn [sql:upsert-team-invitation id
|
||||
(:id team) (str/lower email)
|
||||
(:id profile)
|
||||
(name role) expire
|
||||
(name role) expire])
|
||||
expire (if organization
|
||||
(ct/in-future "876000h") ;; Organization invitations doesn't expire
|
||||
(ct/in-future "168h")) ;; 7 days
|
||||
invitation (db/exec-one! conn (if organization
|
||||
[sql:upsert-org-invitation id
|
||||
(:id organization)
|
||||
(str/lower email)
|
||||
(:id profile)
|
||||
(name role) expire
|
||||
(name role) expire]
|
||||
[sql:upsert-team-invitation id
|
||||
(:id team)
|
||||
(str/lower email)
|
||||
(:id profile)
|
||||
(name role) expire
|
||||
(name role) expire]))
|
||||
updated? (not= id (:id invitation))
|
||||
profile-id (:id profile)
|
||||
tprops {:profile-id profile-id
|
||||
:invitation-id (:id invitation)
|
||||
:valid-until expire
|
||||
:team-id (:id team)
|
||||
:organization-id (:id organization)
|
||||
:organization-name (:name organization)
|
||||
:member-email (:email-to invitation)
|
||||
:member-id (:id member)
|
||||
:role role}
|
||||
@ -152,28 +199,58 @@
|
||||
|
||||
(let [props (-> (dissoc tprops :profile-id)
|
||||
(audit/clean-props))
|
||||
evname (if updated?
|
||||
"update-team-invitation"
|
||||
"create-team-invitation")
|
||||
evname (cond
|
||||
(and updated? organization) "update-org-invitation"
|
||||
updated? "update-team-invitation"
|
||||
organization "create-org-invitation"
|
||||
:else "create-team-invitation")
|
||||
event (-> (audit/event-from-rpc-params params)
|
||||
(assoc ::audit/name evname)
|
||||
(assoc ::audit/props props))]
|
||||
(audit/submit! cfg event))
|
||||
|
||||
(when (allow-invitation-emails? member)
|
||||
(eml/send! {::eml/conn conn
|
||||
::eml/factory eml/invite-to-team
|
||||
:public-uri (cf/get :public-uri)
|
||||
:to email
|
||||
:invited-by (:fullname profile)
|
||||
:team (:name team)
|
||||
:token itoken
|
||||
:extra-data ptoken}))
|
||||
(if organization
|
||||
(when (contains? cf/flags :nitrate)
|
||||
(eml/send! {::eml/conn conn
|
||||
::eml/factory eml/invite-to-org
|
||||
:public-uri (cf/get :public-uri)
|
||||
:to email
|
||||
:invited-by (:fullname profile)
|
||||
:user-name (:fullname member)
|
||||
:organization-name (:name organization)
|
||||
:organization-logo (:logo organization)
|
||||
:organization-initials (:initials organization)
|
||||
:token itoken
|
||||
:extra-data ptoken}))
|
||||
(let [team (if (contains? cf/flags :nitrate)
|
||||
(nitrate/add-org-info-to-team cfg team {})
|
||||
team)]
|
||||
(eml/send! {::eml/conn conn
|
||||
::eml/factory eml/invite-to-team
|
||||
:public-uri (cf/get :public-uri)
|
||||
:to email
|
||||
:invited-by (:fullname profile)
|
||||
:team (:name team)
|
||||
:organization (:organization-name team)
|
||||
:token itoken
|
||||
:extra-data ptoken}))))
|
||||
|
||||
itoken)))))
|
||||
|
||||
(defn create-org-invitation
|
||||
[cfg {:keys [::rpc/profile-id id name initials logo] :as params}]
|
||||
(let [profile (db/get-by-id cfg :profile profile-id)]
|
||||
(create-invitation cfg
|
||||
(assoc params
|
||||
:organization {:id id :name name :initials initials :logo logo}
|
||||
:profile profile
|
||||
:role :editor))))
|
||||
|
||||
(defn- add-member-to-team
|
||||
[conn profile team role member]
|
||||
[{:keys [::db/conn] :as cfg} profile team role member]
|
||||
(assert (db/connection-map? cfg)
|
||||
"expected cfg with valid connection")
|
||||
|
||||
(let [team-id (:id team)
|
||||
params (merge
|
||||
@ -193,7 +270,7 @@
|
||||
::quotes/team-id team-id})
|
||||
|
||||
;; Insert the member to the team
|
||||
(db/insert! conn :team-profile-rel params {::db/on-conflict-do-nothing? true})
|
||||
(teams/add-profile-to-team! cfg params {::db/on-conflict-do-nothing? true})
|
||||
|
||||
;; Delete any request
|
||||
(db/delete! conn :team-access-request
|
||||
@ -275,7 +352,7 @@
|
||||
(filter #(contains? invitation-emails (key %)))
|
||||
(map (fn [[email member]]
|
||||
(let [role (:role (first (filter #(= (:email %) email) invitation-data)))]
|
||||
(add-member-to-team conn profile team role member))))
|
||||
(add-member-to-team cfg profile team role member))))
|
||||
(doall))
|
||||
|
||||
invitations))
|
||||
|
||||
@ -16,8 +16,10 @@
|
||||
[app.http.session :as session]
|
||||
[app.loggers.audit :as audit]
|
||||
[app.main :as-alias main]
|
||||
[app.nitrate :as nitrate]
|
||||
[app.rpc :as-alias rpc]
|
||||
[app.rpc.commands.profile :as profile]
|
||||
[app.rpc.commands.teams :as teams]
|
||||
[app.rpc.doc :as-alias doc]
|
||||
[app.rpc.helpers :as rph]
|
||||
[app.rpc.quotes :as quotes]
|
||||
@ -86,52 +88,74 @@
|
||||
;; --- Team Invitation
|
||||
|
||||
(defn- accept-invitation
|
||||
[{:keys [::db/conn] :as cfg} {:keys [team-id role member-email] :as claims} invitation member]
|
||||
[{:keys [::db/conn] :as cfg}
|
||||
{:keys [team-id organization-id role member-email] :as claims} invitation member]
|
||||
(let [;; Update the role if there is an invitation
|
||||
role (or (some-> invitation :role keyword) role)
|
||||
params (merge
|
||||
{:team-id team-id
|
||||
:profile-id (:id member)}
|
||||
(get types.team/permissions-for-role role))]
|
||||
id-member (:id member)]
|
||||
|
||||
;; Do not allow blocked users accept invitations.
|
||||
(when (:is-blocked member)
|
||||
(ex/raise :type :restriction
|
||||
:code :profile-blocked))
|
||||
|
||||
(quotes/check! cfg {::quotes/id ::quotes/profiles-per-team
|
||||
::quotes/profile-id (:id member)
|
||||
::quotes/team-id team-id})
|
||||
(when team-id
|
||||
(quotes/check! cfg {::quotes/id ::quotes/profiles-per-team
|
||||
::quotes/profile-id id-member
|
||||
::quotes/team-id team-id}))
|
||||
|
||||
;; Insert the invited member to the team
|
||||
(db/insert! conn :team-profile-rel params {::db/on-conflict-do-nothing? true})
|
||||
(let [params (merge
|
||||
{:team-id team-id
|
||||
:profile-id id-member}
|
||||
(get types.team/permissions-for-role role))
|
||||
|
||||
;; If profile is not yet verified, mark it as verified because
|
||||
;; accepting an invitation link serves as verification.
|
||||
(when-not (:is-active member)
|
||||
(db/update! conn :profile
|
||||
{:is-active true}
|
||||
{:id (:id member)}))
|
||||
accepted-team-id (if organization-id
|
||||
;; Insert the invited member to the org
|
||||
(when (contains? cf/flags :nitrate)
|
||||
(teams/initialize-user-in-nitrate-org cfg id-member organization-id member-email))
|
||||
;; Insert the invited member to the team
|
||||
(do (teams/add-profile-to-team! cfg params {::db/on-conflict-do-nothing? true})
|
||||
team-id))]
|
||||
|
||||
;; Delete the invitation
|
||||
(db/delete! conn :team-invitation
|
||||
{:team-id team-id :email-to member-email})
|
||||
(when-not accepted-team-id
|
||||
(ex/raise :type :internal
|
||||
:code :accept-invitation-failed
|
||||
:hint "the accept invitation has failed"))
|
||||
|
||||
;; Delete any request
|
||||
(db/delete! conn :team-access-request
|
||||
{:team-id team-id :requester-id (:id member)})
|
||||
|
||||
(assoc member :is-active true)))
|
||||
;; If profile is not yet verified, mark it as verified because
|
||||
;; accepting an invitation link serves as verification.
|
||||
(when-not (:is-active member)
|
||||
(db/update! conn :profile
|
||||
{:is-active true}
|
||||
{:id id-member}))
|
||||
|
||||
;; Delete the invitation
|
||||
(db/delete! conn :team-invitation
|
||||
(cond-> {:email-to member-email}
|
||||
team-id (assoc :team-id team-id)
|
||||
organization-id (assoc :org-id organization-id)))
|
||||
|
||||
;; Delete any request (only applicable for team invitations)
|
||||
(when team-id
|
||||
(db/delete! conn :team-access-request
|
||||
{:team-id team-id :requester-id id-member}))
|
||||
|
||||
accepted-team-id)))
|
||||
|
||||
(def schema:team-invitation-claims
|
||||
[:map {:title "TeamInvitationClaims"}
|
||||
[:iss :keyword]
|
||||
[:exp ::ct/inst]
|
||||
[:profile-id ::sm/uuid]
|
||||
[:role types.team/schema:role]
|
||||
[:team-id ::sm/uuid]
|
||||
[:member-email ::sm/email]
|
||||
[:member-id {:optional true} ::sm/uuid]])
|
||||
[:and
|
||||
[:map {:title "TeamInvitationClaims"}
|
||||
[:iss :keyword]
|
||||
[:exp ::ct/inst]
|
||||
[:profile-id ::sm/uuid]
|
||||
[:role types.team/schema:role]
|
||||
[:team-id {:optional true} ::sm/uuid]
|
||||
[:organization-id {:optional true} ::sm/uuid]
|
||||
[:member-email ::sm/email]
|
||||
[:member-id {:optional true} ::sm/uuid]]
|
||||
[:fn {:error/message "team-id or organization-id must be present"}
|
||||
(fn [m] (or (:team-id m) (:organization-id m)))]])
|
||||
|
||||
(def valid-team-invitation-claims?
|
||||
(sm/lazy-validator schema:team-invitation-claims))
|
||||
@ -139,7 +163,7 @@
|
||||
(defmethod process-token :team-invitation
|
||||
[{:keys [::db/conn] :as cfg}
|
||||
{:keys [::rpc/profile-id token] :as params}
|
||||
{:keys [member-id team-id member-email] :as claims}]
|
||||
{:keys [member-id team-id organization-id member-email] :as claims}]
|
||||
|
||||
(when-not (valid-team-invitation-claims? claims)
|
||||
(ex/raise :type :validation
|
||||
@ -147,19 +171,45 @@
|
||||
:hint "invitation token contains unexpected data"))
|
||||
|
||||
(let [invitation (db/get* conn :team-invitation
|
||||
{:team-id team-id :email-to member-email})
|
||||
(cond-> {:email-to member-email}
|
||||
team-id (assoc :team-id team-id)
|
||||
organization-id (assoc :org-id organization-id)))
|
||||
profile (db/get* conn :profile
|
||||
{:id profile-id}
|
||||
{:columns [:id :email]})
|
||||
registration-disabled? (not (contains? cf/flags :registration))]
|
||||
(when (nil? invitation)
|
||||
(ex/raise :type :validation
|
||||
:code :invalid-token
|
||||
:hint "no invitation associated with the token"))
|
||||
{:columns [:id :email :default-team-id]})
|
||||
registration-disabled? (not (contains? cf/flags :registration))
|
||||
|
||||
org-invitation? (and (contains? cf/flags :nitrate) organization-id)
|
||||
membership (when org-invitation?
|
||||
(nitrate/call cfg :get-org-membership {:profile-id profile-id
|
||||
:organization-id organization-id}))]
|
||||
|
||||
(if profile
|
||||
(do
|
||||
(when-not (or (= member-id profile-id)
|
||||
(= member-email (:email profile)))
|
||||
(ex/raise :type :validation
|
||||
:code :invalid-token
|
||||
:reason :email-mismatch
|
||||
:hint "logged-in user does not matches the invitation"))
|
||||
|
||||
(when (:is-member membership)
|
||||
(ex/raise :type :validation
|
||||
:code :already-an-org-member
|
||||
:team-id (:default-team-id membership)
|
||||
:hint "the user is already a member of the organization"))
|
||||
|
||||
(when (and org-invitation? (not (:organization-id membership)))
|
||||
(ex/raise :type :validation
|
||||
:code :org-not-found
|
||||
:team-id (:default-team-id profile)
|
||||
:hint "the organization doesn't exist"))
|
||||
|
||||
(when (nil? invitation)
|
||||
(ex/raise :type :validation
|
||||
:code :invalid-token
|
||||
:hint "no invitation associated with the token"))
|
||||
|
||||
(if (some? profile)
|
||||
(if (or (= member-id profile-id)
|
||||
(= member-email (:email profile)))
|
||||
|
||||
;; if we have logged-in user and it matches the invitation we proceed
|
||||
;; with accepting the invitation and joining the current profile to the
|
||||
@ -187,17 +237,16 @@
|
||||
:profile-id (:id profile)
|
||||
:email (:email profile))))))
|
||||
|
||||
(accept-invitation cfg claims invitation profile)
|
||||
(assoc claims :state :created))
|
||||
|
||||
(ex/raise :type :validation
|
||||
:code :invalid-token
|
||||
:hint "logged-in user does not matches the invitation"))
|
||||
(let [accepted-team-id (accept-invitation cfg claims invitation profile)]
|
||||
(cond-> (assoc claims :state :created)
|
||||
;; when the invitation is to an org, instead of a team, add the
|
||||
;; accepted-team-id as :org-team-id
|
||||
(:organization-id claims)
|
||||
(assoc :org-team-id accepted-team-id)))))
|
||||
|
||||
;; If we have not logged-in user, and invitation comes with member-id we
|
||||
;; redirect user to login, if no memeber-id is present and in the invitation
|
||||
;; token and registration is enabled, we redirect user the the register page.
|
||||
|
||||
{:invitation-token token
|
||||
:iss :team-invitation
|
||||
:redirect-to (if (or member-id registration-disabled?) :auth-login :auth-register)
|
||||
|
||||
@ -28,19 +28,25 @@
|
||||
(update :pages-index select-keys allowed)))
|
||||
|
||||
(defn obfuscate-email
|
||||
"Obfuscate the `email` for share-link members so the viewer only sees a
|
||||
partially redacted address. Accepts any string shape (including nil,
|
||||
missing `@`, or a domain with no `.`) and falls back to a fully-masked
|
||||
result rather than throwing — the function is called while building the
|
||||
view-only bundle for anonymous viewers, so an NPE here would abort the
|
||||
entire share-link response."
|
||||
[email]
|
||||
(let [[name domain]
|
||||
(str/split email "@" 2)
|
||||
(str/split (or email "") "@" 2)
|
||||
|
||||
[_ rest]
|
||||
(str/split domain "." 2)
|
||||
(str/split (or domain "") "." 2)
|
||||
|
||||
name
|
||||
(if (> (count name) 3)
|
||||
(str (subs name 0 1) (apply str (take (dec (count name)) (repeat "*"))))
|
||||
"****")]
|
||||
|
||||
(str name "@****." rest)))
|
||||
(str name "@****" (when rest (str "." rest)))))
|
||||
|
||||
(defn anonymize-member
|
||||
[member]
|
||||
|
||||
@ -8,22 +8,35 @@
|
||||
"Internal Nitrate HTTP RPC API. Provides authenticated access to
|
||||
organization management and token validation endpoints."
|
||||
(:require
|
||||
[app.common.features :as cfeat]
|
||||
[app.common.data :as d]
|
||||
[app.common.exceptions :as ex]
|
||||
[app.common.schema :as sm]
|
||||
[app.common.time :as ct]
|
||||
[app.common.types.organization :refer [schema:team-with-organization]]
|
||||
[app.common.types.profile :refer [schema:profile, schema:basic-profile]]
|
||||
[app.common.types.team :refer [schema:team]]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.config :as cf]
|
||||
[app.db :as db]
|
||||
[app.msgbus :as mbus]
|
||||
[app.media :as media]
|
||||
[app.nitrate :as nitrate]
|
||||
[app.rpc :as-alias rpc]
|
||||
[app.rpc.commands.files :as files]
|
||||
[app.rpc.commands.nitrate :as cnit]
|
||||
[app.rpc.commands.profile :as profile]
|
||||
[app.rpc.commands.teams :as teams]
|
||||
[app.rpc.commands.teams-invitations :as ti]
|
||||
[app.rpc.doc :as doc]
|
||||
[app.rpc.quotes :as quotes]
|
||||
[app.rpc.notifications :as notifications]
|
||||
[app.storage :as sto]
|
||||
[app.util.services :as sv]
|
||||
[clojure.set :as set]))
|
||||
[app.worker :as wrk]))
|
||||
|
||||
|
||||
(defn- profile-to-map [profile]
|
||||
{:id (:id profile)
|
||||
:name (:fullname profile)
|
||||
:email (:email profile)
|
||||
:photo-url (files/resolve-public-uri (get profile :photo-id))})
|
||||
|
||||
;; ---- API: authenticate
|
||||
|
||||
@ -33,11 +46,9 @@
|
||||
::sm/params [:map]
|
||||
::sm/result schema:profile}
|
||||
[cfg {:keys [::rpc/profile-id] :as params}]
|
||||
(let [profile (profile/get-profile cfg profile-id)]
|
||||
{:id (get profile :id)
|
||||
:name (get profile :fullname)
|
||||
:email (get profile :email)
|
||||
:photo-url (files/resolve-public-uri (get profile :photo-id))}))
|
||||
(let [profile (profile/get-profile cfg profile-id)]
|
||||
(-> (profile-to-map profile)
|
||||
(assoc :theme (:theme profile)))))
|
||||
|
||||
;; ---- API: get-teams
|
||||
|
||||
@ -53,13 +64,26 @@
|
||||
;; ---- API: get-penpot-version
|
||||
|
||||
(def ^:private schema:get-penpot-version-result
|
||||
[:map [:version ::sm/text]])
|
||||
[:map
|
||||
[:version
|
||||
[:map
|
||||
[:full [:maybe ::sm/text]]
|
||||
[:branch [:maybe ::sm/text]]
|
||||
[:base [:maybe ::sm/text]]
|
||||
[:main [:maybe ::sm/text]]
|
||||
[:major [:maybe ::sm/text]]
|
||||
[:minor [:maybe ::sm/text]]
|
||||
[:patch [:maybe ::sm/text]]
|
||||
[:modifier [:maybe ::sm/text]]
|
||||
[:commit [:maybe ::sm/text]]
|
||||
[:commit-hash [:maybe ::sm/text]]]]])
|
||||
|
||||
(sv/defmethod ::get-penpot-version
|
||||
"Get the current Penpot version"
|
||||
{::doc/added "2.14"
|
||||
::sm/params [:map]
|
||||
::sm/result schema:get-penpot-version-result}
|
||||
::sm/result schema:get-penpot-version-result
|
||||
::rpc/auth false}
|
||||
[_cfg _params]
|
||||
{:version cf/version})
|
||||
|
||||
@ -76,29 +100,47 @@
|
||||
(->> (db/exec! cfg [sql:get-teams current-user-id])
|
||||
(map #(select-keys % [:id :name])))))
|
||||
|
||||
;; ---- API: notify-team-change
|
||||
;; ---- API: upload-org-logo
|
||||
|
||||
(def ^:private schema:notify-team-change
|
||||
(def ^:private schema:upload-org-logo
|
||||
[:map
|
||||
[:id ::sm/uuid]
|
||||
[:content media/schema:upload]
|
||||
[:organization-id ::sm/uuid]
|
||||
[:organization-name ::sm/text]])
|
||||
[:previous-id {:optional true} ::sm/uuid]])
|
||||
|
||||
(def ^:private schema:upload-org-logo-result
|
||||
[:map [:id ::sm/uuid]])
|
||||
|
||||
(sv/defmethod ::upload-org-logo
|
||||
"Store an organization logo in penpot storage and return its ID.
|
||||
Accepts an optional previous-id to mark the old logo for garbage
|
||||
collection when replacing an existing one."
|
||||
{::doc/added "2.17"
|
||||
::sm/params schema:upload-org-logo
|
||||
::sm/result schema:upload-org-logo-result}
|
||||
[{:keys [::sto/storage]} {:keys [content organization-id previous-id]}]
|
||||
(when previous-id
|
||||
(sto/touch-object! storage previous-id))
|
||||
(let [hash (sto/calculate-hash (:path content))
|
||||
data (-> (sto/content (:path content))
|
||||
(sto/wrap-with-hash hash))
|
||||
obj (sto/put-object! storage {::sto/content data
|
||||
::sto/deduplicate? true
|
||||
:bucket "organization"
|
||||
:content-type (:mtype content)
|
||||
:organization-id organization-id})]
|
||||
{:id (:id obj)}))
|
||||
|
||||
;; ---- API: notify-team-change
|
||||
|
||||
(sv/defmethod ::notify-team-change
|
||||
"Notify to Penpot a team change from nitrate"
|
||||
{::doc/added "2.14"
|
||||
::sm/params schema:notify-team-change
|
||||
::sm/params schema:team-with-organization
|
||||
::rpc/auth false}
|
||||
[cfg {:keys [id organization-id organization-name]}]
|
||||
(let [msgbus (::mbus/msgbus cfg)]
|
||||
(mbus/pub! msgbus
|
||||
;;TODO There is a bug on dashboard with teams notifications.
|
||||
;;For now we send it to uuid/zero instead of team-id
|
||||
:topic uuid/zero
|
||||
:message {:type :team-org-change
|
||||
:team-id id
|
||||
:organization-id organization-id
|
||||
:organization-name organization-name})))
|
||||
[cfg team]
|
||||
(notifications/notify-team-change cfg (select-keys team [:id :is-your-penpot :organization]) nil)
|
||||
nil)
|
||||
|
||||
;; ---- API: notify-user-added-to-organization
|
||||
|
||||
@ -113,18 +155,8 @@
|
||||
{::doc/added "2.14"
|
||||
::sm/params schema:notify-user-added-to-organization
|
||||
::rpc/auth false}
|
||||
[cfg {:keys [profile-id]}]
|
||||
(quotes/check! cfg {::quotes/id ::quotes/teams-per-profile
|
||||
::quotes/profile-id profile-id})
|
||||
|
||||
(let [features (-> (cfeat/get-enabled-features cf/flags)
|
||||
(set/difference cfeat/frontend-only-features)
|
||||
(set/difference cfeat/no-team-inheritable-features))
|
||||
params {:profile-id profile-id
|
||||
:name "Default"
|
||||
:features features}
|
||||
team (db/tx-run! cfg teams/create-team params)]
|
||||
(select-keys team [:id])))
|
||||
[cfg {:keys [profile-id organization-id]}]
|
||||
(db/tx-run! cfg teams/create-default-org-team profile-id organization-id))
|
||||
|
||||
|
||||
;; ---- API: get-managed-profiles
|
||||
@ -158,3 +190,440 @@
|
||||
(let [current-user-id (-> (profile/get-profile cfg profile-id) :id)]
|
||||
(db/exec! cfg [sql:get-managed-profiles current-user-id current-user-id])))
|
||||
|
||||
;; ---- API: get-teams-summary
|
||||
|
||||
(def ^:private sql:get-teams-summary
|
||||
"SELECT t.id, t.name, t.is_default
|
||||
FROM team AS t
|
||||
WHERE t.id = ANY(?)
|
||||
AND t.deleted_at IS NULL;")
|
||||
|
||||
(def ^:private sql:get-files-count
|
||||
"SELECT COUNT(f.*) AS count
|
||||
FROM file AS f
|
||||
JOIN project AS p ON f.project_id = p.id
|
||||
JOIN team AS t ON t.id = p.team_id
|
||||
WHERE p.team_id = ANY(?)
|
||||
AND t.deleted_at IS NULL
|
||||
AND p.deleted_at IS NULL
|
||||
AND f.deleted_at IS NULL;")
|
||||
|
||||
(def ^:private schema:get-teams-summary-params
|
||||
[:map
|
||||
[:ids [:or ::sm/uuid [:vector ::sm/uuid]]]])
|
||||
|
||||
(def ^:private schema:get-teams-summary-result
|
||||
[:map
|
||||
[:teams [:vector [:map
|
||||
[:id ::sm/uuid]
|
||||
[:name ::sm/text]
|
||||
[:is-default ::sm/boolean]]]]
|
||||
[:num-files ::sm/int]])
|
||||
|
||||
(sv/defmethod ::get-teams-summary
|
||||
"Get summary information for a list of teams"
|
||||
{::doc/added "2.15"
|
||||
::sm/params schema:get-teams-summary-params
|
||||
::sm/result schema:get-teams-summary-result}
|
||||
[cfg {:keys [ids]}]
|
||||
(let [;; Handle one or multiple params
|
||||
ids (cond
|
||||
(uuid? ids)
|
||||
[ids]
|
||||
|
||||
(and (vector? ids) (every? uuid? ids))
|
||||
ids
|
||||
|
||||
:else
|
||||
[])]
|
||||
(db/run! cfg (fn [{:keys [::db/conn]}]
|
||||
(let [ids-array (db/create-array conn "uuid" ids)
|
||||
teams (db/exec! conn [sql:get-teams-summary ids-array])
|
||||
files-count (-> (db/exec-one! conn [sql:get-files-count ids-array]) :count)]
|
||||
{:teams teams
|
||||
:num-files files-count})))))
|
||||
|
||||
|
||||
;; ---- API: delete-teams-keeping-your-penpot-projects
|
||||
|
||||
(def ^:private sql:prefix-teams-name-and-unset-default
|
||||
"UPDATE team
|
||||
SET name = ? || name,
|
||||
is_default = FALSE
|
||||
WHERE id = ANY(?)
|
||||
RETURNING id, name;")
|
||||
|
||||
(def ^:private sql:get-teams-files-counts
|
||||
"SELECT p.team_id, COUNT(f.*) AS total
|
||||
FROM file AS f
|
||||
JOIN project AS p ON (p.id = f.project_id)
|
||||
JOIN team AS t ON (t.id = p.team_id)
|
||||
WHERE t.id = ANY(?)
|
||||
AND t.deleted_at IS NULL
|
||||
AND p.deleted_at IS NULL
|
||||
AND f.deleted_at IS NULL
|
||||
GROUP BY p.team_id;")
|
||||
|
||||
(def ^:private sql:soft-delete-teams
|
||||
"UPDATE team
|
||||
SET deleted_at = ?
|
||||
WHERE id = ANY(?)
|
||||
RETURNING id, deleted_at;")
|
||||
|
||||
|
||||
;; ---- API: notify-organization-deletion
|
||||
|
||||
(def ^:private schema:notify-organization-deletion
|
||||
[:map
|
||||
[:organization-id ::sm/uuid]])
|
||||
|
||||
|
||||
(defn- soft-delete-teams!
|
||||
"Soft-delete the provided team ids and submit a delete task per team."
|
||||
[{:keys [::db/conn] :as cfg} team-ids]
|
||||
(when (seq team-ids)
|
||||
(let [delay (cf/get-deletion-delay)
|
||||
deleted-at (ct/in-future delay)
|
||||
updated (db/exec! conn [sql:soft-delete-teams
|
||||
deleted-at
|
||||
(db/create-array conn "uuid" team-ids)])]
|
||||
(doseq [{:keys [id deleted-at]} updated]
|
||||
(wrk/submit! {::db/conn conn
|
||||
::wrk/task :delete-object
|
||||
::wrk/params {:object :team
|
||||
:deleted-at deleted-at
|
||||
:id id}}))))
|
||||
nil)
|
||||
|
||||
(defn manage-deleted-organization-teams
|
||||
"For a list of teams, rename those with files and delete those without, then notify users."
|
||||
[cfg {:keys [teams organization-name]}]
|
||||
(let [teams (->> teams (filter uuid?) distinct (into []))]
|
||||
(when (seq teams)
|
||||
(let [org-prefix (str "[" (d/sanitize-string organization-name) "] ")]
|
||||
(db/tx-run!
|
||||
cfg
|
||||
(fn [{:keys [::db/conn] :as cfg}]
|
||||
(let [teams-array (db/create-array conn "uuid" teams)
|
||||
teams-with-files (->> (db/exec! conn [sql:get-teams-files-counts teams-array])
|
||||
(filter (fn [{:keys [total]}] (pos? total)))
|
||||
(map :team-id)
|
||||
(into #{}))
|
||||
teams-to-keep (->> teams (filter teams-with-files) (into []))
|
||||
teams-to-delete (->> teams (remove teams-with-files) (into []))]
|
||||
|
||||
;; Rename teams that have files in one go
|
||||
(when (seq teams-to-keep)
|
||||
(db/exec! conn [sql:prefix-teams-name-and-unset-default
|
||||
org-prefix
|
||||
(db/create-array conn "uuid" teams-to-keep)]))
|
||||
|
||||
;; Soft-delete empty teams in one go
|
||||
(soft-delete-teams! cfg teams-to-delete)
|
||||
|
||||
(notifications/notify-organization-deletion cfg organization-name teams teams-to-delete)
|
||||
nil)))))))
|
||||
|
||||
|
||||
(sv/defmethod ::notify-organization-deletion
|
||||
"For a list of teams, rename them with the name of the deleted org, and notify
|
||||
of the deletion to the connected users"
|
||||
{::doc/added "2.15"
|
||||
::sm/params schema:notify-organization-deletion
|
||||
::rpc/auth false}
|
||||
[cfg {:keys [organization-id]}]
|
||||
(let [org-summary (nitrate/call cfg :get-org-summary {:organization-id organization-id})
|
||||
teams (->> (:teams org-summary)
|
||||
(map :id))]
|
||||
(manage-deleted-organization-teams cfg {:teams teams :organization-name (:name org-summary)})
|
||||
nil))
|
||||
|
||||
;; ---- API: notify-user-organizations-deletion
|
||||
|
||||
(def ^:private schema:notify-user-organizations-deletion
|
||||
[:map
|
||||
[:profile-id ::sm/uuid]])
|
||||
|
||||
(sv/defmethod ::notify-user-organizations-deletion
|
||||
"For a given user, find all owned organizations and rename or delete their teams."
|
||||
{::doc/added "2.18"
|
||||
::sm/params schema:notify-user-organizations-deletion}
|
||||
[cfg {:keys [profile-id]}]
|
||||
(let [owned-orgs (nitrate/call cfg :get-owned-orgs {:profile-id profile-id})]
|
||||
(doseq [org owned-orgs]
|
||||
(let [organization-name (:name org)
|
||||
teams (map :id (:teams org))]
|
||||
(manage-deleted-organization-teams cfg {:teams teams :organization-name organization-name}))))
|
||||
nil)
|
||||
|
||||
|
||||
|
||||
|
||||
;; ---- API: get-profile-by-email
|
||||
|
||||
(def ^:private sql:get-profile-by-email
|
||||
"SELECT DISTINCT id, fullname, email, photo_id
|
||||
FROM profile
|
||||
WHERE email = ?
|
||||
AND deleted_at IS NULL;")
|
||||
|
||||
(sv/defmethod ::get-profile-by-email
|
||||
"Get profile by email"
|
||||
{::doc/added "2.15"
|
||||
::sm/params [:map [:email ::sm/email]]
|
||||
::sm/result schema:profile}
|
||||
[cfg {:keys [email]}]
|
||||
(let [profile (db/exec-one! cfg [sql:get-profile-by-email email])]
|
||||
(when-not profile
|
||||
(ex/raise :type :not-found
|
||||
:code :profile-not-found
|
||||
:hint "profile does not exist"
|
||||
:email email))
|
||||
(profile-to-map profile)))
|
||||
|
||||
|
||||
;; ---- API: get-profile-by-id
|
||||
|
||||
(def ^:private sql:get-profile-by-id
|
||||
"SELECT DISTINCT id, fullname, email, photo_id
|
||||
FROM profile
|
||||
WHERE id = ?
|
||||
AND deleted_at IS NULL;")
|
||||
|
||||
(sv/defmethod ::get-profile-by-id
|
||||
"Get profile by email"
|
||||
{::doc/added "2.15"
|
||||
::sm/params [:map [:id ::sm/uuid]]
|
||||
::sm/result schema:profile}
|
||||
[cfg {:keys [id]}]
|
||||
(let [profile (db/exec-one! cfg [sql:get-profile-by-id id])]
|
||||
(when-not profile
|
||||
(ex/raise :type :not-found
|
||||
:code :profile-not-found
|
||||
:hint "profile does not exist"
|
||||
:id id))
|
||||
(profile-to-map profile)))
|
||||
|
||||
|
||||
;; ---- API: get-org-member-team-counts
|
||||
|
||||
(def ^:private sql:get-org-member-team-counts
|
||||
"SELECT tpr.profile_id, COUNT(DISTINCT t.id) AS team_count
|
||||
FROM team_profile_rel AS tpr
|
||||
JOIN team AS t ON t.id = tpr.team_id
|
||||
WHERE t.id = ANY(?)
|
||||
AND t.deleted_at IS NULL
|
||||
AND t.is_default IS FALSE
|
||||
GROUP BY tpr.profile_id;")
|
||||
|
||||
(def ^:private schema:get-org-member-team-counts-params
|
||||
[:map [:team-ids [:or ::sm/uuid [:vector ::sm/uuid]]]])
|
||||
|
||||
(def ^:private schema:get-org-member-team-counts-result
|
||||
[:vector [:map
|
||||
[:profile-id ::sm/uuid]
|
||||
[:team-count ::sm/int]]])
|
||||
|
||||
(sv/defmethod ::get-org-member-team-counts
|
||||
"Get the number of non-default teams each profile belongs to within a set of teams."
|
||||
{::doc/added "2.15"
|
||||
::sm/params schema:get-org-member-team-counts-params
|
||||
::sm/result schema:get-org-member-team-counts-result
|
||||
::rpc/auth false}
|
||||
[cfg {:keys [team-ids]}]
|
||||
(let [team-ids (cond
|
||||
(uuid? team-ids)
|
||||
[team-ids]
|
||||
|
||||
(and (vector? team-ids) (every? uuid? team-ids))
|
||||
team-ids
|
||||
|
||||
:else
|
||||
[])]
|
||||
(if (empty? team-ids)
|
||||
[]
|
||||
(db/run! cfg (fn [{:keys [::db/conn]}]
|
||||
(let [ids-array (db/create-array conn "uuid" team-ids)]
|
||||
(db/exec! conn [sql:get-org-member-team-counts ids-array])))))))
|
||||
|
||||
|
||||
;; API: invite-to-org
|
||||
|
||||
(sv/defmethod ::invite-to-org
|
||||
"Invite to organization"
|
||||
{::doc/added "2.15"
|
||||
::sm/params [:map
|
||||
[:email ::sm/email]
|
||||
[:id ::sm/uuid]
|
||||
[:name ::sm/text]
|
||||
[:initials [:maybe :string]]
|
||||
[:logo ::sm/uri]]}
|
||||
[cfg params]
|
||||
(db/tx-run! cfg ti/create-org-invitation params)
|
||||
nil)
|
||||
|
||||
|
||||
;; API: get-org-invitations
|
||||
|
||||
(def ^:private sql:get-org-invitations
|
||||
"SELECT DISTINCT ON (email_to)
|
||||
ti.id,
|
||||
ti.org_id AS organization_id,
|
||||
ti.email_to AS email,
|
||||
ti.created_at AS sent_at,
|
||||
p.fullname AS name,
|
||||
p.photo_id
|
||||
FROM team_invitation AS ti
|
||||
LEFT JOIN profile AS p
|
||||
ON p.email = ti.email_to
|
||||
AND p.deleted_at IS NULL
|
||||
WHERE ti.valid_until >= now()
|
||||
AND (ti.org_id = ? OR ti.team_id = ANY(?))
|
||||
ORDER BY ti.email_to, ti.valid_until DESC, ti.created_at DESC;")
|
||||
|
||||
(def ^:private schema:get-org-invitations-params
|
||||
[:map
|
||||
[:organization-id ::sm/uuid]])
|
||||
|
||||
(def ^:private schema:get-org-invitations-result
|
||||
[:vector
|
||||
[:map
|
||||
[:id ::sm/uuid]
|
||||
[:organization-id {:optional true} [:maybe ::sm/uuid]]
|
||||
[:email ::sm/email]
|
||||
[:sent-at ::sm/inst]
|
||||
[:name {:optional true} [:maybe ::sm/text]]
|
||||
[:photo-url {:optional true} ::sm/uri]]])
|
||||
|
||||
(sv/defmethod ::get-org-invitations
|
||||
"Get valid invitations for an organization, returning at most one invitation per email."
|
||||
{::doc/added "2.16"
|
||||
::sm/params schema:get-org-invitations-params
|
||||
::sm/result schema:get-org-invitations-result}
|
||||
[cfg {:keys [organization-id]}]
|
||||
(let [org-summary (nitrate/call cfg :get-org-summary {:organization-id organization-id})
|
||||
team-ids (->> (:teams org-summary)
|
||||
(map :id)
|
||||
(filter uuid?)
|
||||
(into []))]
|
||||
(db/run! cfg (fn [{:keys [::db/conn]}]
|
||||
(let [ids-array (db/create-array conn "uuid" team-ids)]
|
||||
(->> (db/exec! conn [sql:get-org-invitations organization-id ids-array])
|
||||
(mapv (fn [{:keys [photo-id] :as invitation}]
|
||||
(cond-> (dissoc invitation :photo-id)
|
||||
photo-id
|
||||
(assoc :photo-url (files/resolve-public-uri photo-id)))))))))))
|
||||
|
||||
|
||||
;; API: delete-org-invitations
|
||||
|
||||
(def ^:private sql:delete-org-invitations
|
||||
"DELETE FROM team_invitation AS ti
|
||||
WHERE ti.email_to = ?
|
||||
AND (ti.org_id = ? OR ti.team_id = ANY(?));")
|
||||
|
||||
(def ^:private schema:delete-org-invitations-params
|
||||
[:map
|
||||
[:organization-id ::sm/uuid]
|
||||
[:email ::sm/email]])
|
||||
|
||||
(sv/defmethod ::delete-org-invitations
|
||||
"Delete all invitations for one email in an organization scope (org + org teams)."
|
||||
{::doc/added "2.16"
|
||||
::sm/params schema:delete-org-invitations-params}
|
||||
[cfg {:keys [organization-id email]}]
|
||||
(let [org-summary (nitrate/call cfg :get-org-summary {:organization-id organization-id})
|
||||
clean-email (profile/clean-email email)
|
||||
team-ids (->> (:teams org-summary)
|
||||
(map :id)
|
||||
(filter uuid?)
|
||||
(into []))]
|
||||
(db/run! cfg (fn [{:keys [::db/conn]}]
|
||||
(let [ids-array (db/create-array conn "uuid" team-ids)]
|
||||
(db/exec! conn [sql:delete-org-invitations clean-email organization-id ids-array]))))
|
||||
nil))
|
||||
|
||||
|
||||
|
||||
;; API: remove-from-org
|
||||
|
||||
(def ^:private sql:get-reassign-to
|
||||
"SELECT tpr.profile_id
|
||||
FROM team_profile_rel AS tpr
|
||||
WHERE tpr.team_id = ?
|
||||
AND tpr.profile_id <> ?
|
||||
AND tpr.is_owner IS NOT TRUE
|
||||
ORDER BY CASE
|
||||
WHEN tpr.is_admin IS TRUE THEN 1
|
||||
ELSE 2
|
||||
END,
|
||||
tpr.created_at,
|
||||
tpr.profile_id
|
||||
LIMIT 1;")
|
||||
|
||||
(defn add-reassign-to [cfg profile-id team-to-transfer]
|
||||
(let [reassign-to (-> (db/exec-one! cfg [sql:get-reassign-to (:id team-to-transfer) profile-id])
|
||||
:profile-id)]
|
||||
(when-not reassign-to
|
||||
(ex/raise :type :validation
|
||||
:code :nobody-to-reassign-team))
|
||||
|
||||
(assoc team-to-transfer :reassign-to reassign-to)))
|
||||
|
||||
(sv/defmethod ::remove-from-org
|
||||
"Remove an user from an organization"
|
||||
{::doc/added "2.17"
|
||||
::sm/params [:map
|
||||
[:profile-id ::sm/uuid]
|
||||
[:organization-id ::sm/uuid]
|
||||
[:organization-name ::sm/text]
|
||||
[:default-team-id ::sm/uuid]]
|
||||
::db/transaction true}
|
||||
[cfg {:keys [profile-id organization-id organization-name default-team-id] :as params}]
|
||||
(let [{:keys [valid-teams-to-delete-ids
|
||||
valid-teams-to-transfer
|
||||
valid-teams-to-exit]} (cnit/get-valid-teams cfg organization-id profile-id default-team-id)
|
||||
add-reassign-to (partial add-reassign-to cfg profile-id)
|
||||
|
||||
valid-teams-to-leave (into valid-teams-to-exit
|
||||
(map add-reassign-to valid-teams-to-transfer))]
|
||||
|
||||
(cnit/leave-org cfg (assoc params
|
||||
:id organization-id
|
||||
:name organization-name
|
||||
:teams-to-delete valid-teams-to-delete-ids
|
||||
:teams-to-leave valid-teams-to-leave
|
||||
:skip-validation true))
|
||||
(notifications/notify-user-org-change cfg profile-id organization-id organization-name "dashboard.user-no-longer-belong-org")
|
||||
nil))
|
||||
|
||||
;; API: get-remove-from-org-summary
|
||||
|
||||
(def ^:private schema:get-remove-from-org-summary-result
|
||||
[:map
|
||||
[:teams-to-delete ::sm/int]
|
||||
[:teams-to-transfer ::sm/int]
|
||||
[:teams-to-exit ::sm/int]])
|
||||
|
||||
(sv/defmethod ::get-remove-from-org-summary
|
||||
"Get a summary of the teams that would be deleted, transferred, or exited
|
||||
if the user were removed from the organization"
|
||||
{::doc/added "2.17"
|
||||
::sm/params [:map
|
||||
[:profile-id ::sm/uuid]
|
||||
[:organization-id ::sm/uuid]
|
||||
[:default-team-id ::sm/uuid]]
|
||||
::sm/result schema:get-remove-from-org-summary-result
|
||||
::db/transaction true}
|
||||
[cfg {:keys [profile-id organization-id default-team-id]}]
|
||||
(let [{:keys [valid-teams-to-delete-ids
|
||||
valid-teams-to-transfer
|
||||
valid-teams-to-exit
|
||||
valid-default-team]} (cnit/get-valid-teams cfg organization-id profile-id default-team-id)]
|
||||
(when-not valid-default-team
|
||||
(ex/raise :type :validation
|
||||
:code :not-valid-teams))
|
||||
{:teams-to-delete (count valid-teams-to-delete-ids)
|
||||
:teams-to-transfer (count valid-teams-to-transfer)
|
||||
:teams-to-exit (count valid-teams-to-exit)}))
|
||||
|
||||
|
||||
44
backend/src/app/rpc/notifications.clj
Normal file
44
backend/src/app/rpc/notifications.clj
Normal file
@ -0,0 +1,44 @@
|
||||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;;
|
||||
;; Copyright (c) KALEIDOS INC
|
||||
|
||||
(ns app.rpc.notifications
|
||||
(:require
|
||||
[app.common.uuid :as uuid]
|
||||
[app.msgbus :as mbus]))
|
||||
|
||||
(defn notify-team-change
|
||||
[cfg team notification]
|
||||
(let [msgbus (::mbus/msgbus cfg)]
|
||||
(mbus/pub! msgbus
|
||||
;;TODO There is a bug on dashboard with teams notifications.
|
||||
;;For now we send it to uuid/zero instead of team-id
|
||||
:topic uuid/zero
|
||||
:message {:type :team-org-change
|
||||
:team team
|
||||
:notification notification})))
|
||||
|
||||
|
||||
(defn notify-user-org-change
|
||||
[cfg profile-id organization-id organization-name notification]
|
||||
(let [msgbus (::mbus/msgbus cfg)]
|
||||
(mbus/pub! msgbus
|
||||
:topic profile-id
|
||||
:message {:type :user-org-change
|
||||
:topic profile-id
|
||||
:organization-id organization-id
|
||||
:organization-name organization-name
|
||||
:notification notification})))
|
||||
|
||||
|
||||
(defn notify-organization-deletion
|
||||
[cfg organization-name teams deleted-teams]
|
||||
(let [msgbus (::mbus/msgbus cfg)]
|
||||
(mbus/pub! msgbus
|
||||
:topic uuid/zero
|
||||
:message {:type :organization-deleted
|
||||
:organization-name organization-name
|
||||
:teams teams
|
||||
:deleted-teams deleted-teams})))
|
||||
@ -53,7 +53,7 @@
|
||||
:or {is-active true}}]
|
||||
(some-> (get-current-system)
|
||||
(db/tx-run!
|
||||
(fn [{:keys [::db/conn] :as system}]
|
||||
(fn [system]
|
||||
(let [password (derive-password password)
|
||||
params {:id (uuid/next)
|
||||
:email email
|
||||
@ -62,7 +62,7 @@
|
||||
:password password
|
||||
:props {}}]
|
||||
(->> (cmd.auth/create-profile system params)
|
||||
(cmd.auth/create-profile-rels conn)))))))
|
||||
(cmd.auth/create-profile-rels system)))))))
|
||||
|
||||
(defmethod exec-command "update-profile"
|
||||
[{:keys [fullname email password is-active]}]
|
||||
|
||||
@ -588,7 +588,7 @@
|
||||
::audit/tracked-at (ct/now)})
|
||||
|
||||
|
||||
(#'files/restore-file conn file-id))
|
||||
(#'files/restore-files conn [file-id]))
|
||||
:restored))))
|
||||
|
||||
(defn delete-project!
|
||||
@ -622,7 +622,7 @@
|
||||
(doseq [{:keys [id]} (db/query conn :file
|
||||
{:project-id project-id}
|
||||
{::sql/columns [:id]})]
|
||||
(#'files/restore-file conn id))
|
||||
(#'files/restore-files conn [id]))
|
||||
|
||||
:restored)
|
||||
|
||||
@ -905,5 +905,4 @@
|
||||
(let [params (-> rel
|
||||
(assoc :id (uuid/next))
|
||||
(assoc :team-id (:id team)))]
|
||||
(db/insert! conn :team-profile-rel params
|
||||
{::db/return-keys false}))))))))
|
||||
(teams/add-profile-to-team! cfg params {::db/return-keys false}))))))))
|
||||
|
||||
@ -44,6 +44,7 @@
|
||||
"file-object-thumbnail"
|
||||
"file-thumbnail"
|
||||
"profile"
|
||||
"organization"
|
||||
"tempfile"
|
||||
"file-data"
|
||||
"file-data-fragment"
|
||||
|
||||
@ -166,6 +166,7 @@
|
||||
"profile" (process-objects! conn has-profile-refs? bucket objects)
|
||||
"file-data" (process-objects! conn has-file-data-refs? bucket objects)
|
||||
"tempfile" (process-objects! conn (constantly false) bucket objects)
|
||||
"organization" (process-objects! conn (constantly false) bucket objects)
|
||||
(ex/raise :type :internal
|
||||
:code :unexpected-unknown-reference
|
||||
:hint (dm/fmt "unknown reference '%'" bucket))))
|
||||
|
||||
55
backend/test/backend_tests/auth_oidc_test.clj
Normal file
55
backend/test/backend_tests/auth_oidc_test.clj
Normal file
@ -0,0 +1,55 @@
|
||||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;;
|
||||
;; Copyright (c) KALEIDOS INC
|
||||
|
||||
(ns backend-tests.auth-oidc-test
|
||||
(:require
|
||||
[app.auth.oidc :as oidc]
|
||||
[clojure.test :as t]))
|
||||
|
||||
(def ^:private oidc-provider
|
||||
{:id "oidc"
|
||||
:type "oidc"})
|
||||
|
||||
(t/deftest parse-attr-path-supports-dot-and-double-underscore
|
||||
(t/is
|
||||
(= [:oidc/resource-access :penpot_roles :roles]
|
||||
(#'oidc/parse-attr-path oidc-provider "resource_access__penpot_roles__roles")))
|
||||
(t/is
|
||||
(= [:oidc/ocs :data :email]
|
||||
(#'oidc/parse-attr-path oidc-provider "ocs.data.email"))))
|
||||
|
||||
(t/deftest process-user-info-supports-dot-notation-nested-attrs
|
||||
(let [provider (assoc oidc-provider
|
||||
:email-attr "ocs.data.email"
|
||||
:name-attr "ocs.data.display-name")
|
||||
info (#'oidc/process-user-info provider
|
||||
{}
|
||||
{:email_verified true
|
||||
:ocs {:data {:email "nextcloud@example.com"
|
||||
:display-name "Nextcloud User"}}})]
|
||||
(t/is (= "nextcloud@example.com" (:email info)))
|
||||
(t/is (= "Nextcloud User" (:fullname info)))
|
||||
(t/is (true? (:email-verified info)))))
|
||||
|
||||
;; The provider's `:user-info-source` value arrives as a string (enforced by
|
||||
;; the malli schema in `app.config` and used as-is by the hard-coded Google /
|
||||
;; GitHub provider maps), so the dispatch must interpret strings — not
|
||||
;; keywords — to actually honour `PENPOT_OIDC_USER_INFO_SOURCE=userinfo`.
|
||||
(t/deftest select-user-info-source-interprets-config-strings
|
||||
(t/testing "explicit string values map to keyword dispatch tokens"
|
||||
(t/is (= :token (#'oidc/select-user-info-source "token")))
|
||||
(t/is (= :userinfo (#'oidc/select-user-info-source "userinfo"))))
|
||||
|
||||
(t/testing "missing or explicit \"auto\" falls back to auto dispatch"
|
||||
(t/is (= :auto (#'oidc/select-user-info-source "auto")))
|
||||
(t/is (= :auto (#'oidc/select-user-info-source nil))))
|
||||
|
||||
(t/testing "unknown values fall back to auto dispatch safely"
|
||||
(t/is (= :auto (#'oidc/select-user-info-source "unknown")))
|
||||
;; Guards against the reverse regression — a stray keyword value must
|
||||
;; not silently slip through as if it were the matching string.
|
||||
(t/is (= :auto (#'oidc/select-user-info-source :token)))
|
||||
(t/is (= :auto (#'oidc/select-user-info-source :userinfo)))))
|
||||
@ -186,10 +186,10 @@
|
||||
:is-demo false}
|
||||
params)]
|
||||
(db/run! system
|
||||
(fn [{:keys [::db/conn] :as cfg}]
|
||||
(fn [cfg]
|
||||
(->> params
|
||||
(cmd.auth/create-profile cfg)
|
||||
(cmd.auth/create-profile-rels conn)))))))
|
||||
(cmd.auth/create-profile-rels cfg)))))))
|
||||
|
||||
(defn create-project*
|
||||
([i params] (create-project* *system* i params))
|
||||
@ -234,10 +234,10 @@
|
||||
(dm/with-open [conn (db/open system)]
|
||||
(let [id (mk-uuid "team" i)
|
||||
features (cfeat/get-enabled-features cf/flags)]
|
||||
(teams/create-team conn {:id id
|
||||
:profile-id profile-id
|
||||
:features features
|
||||
:name (str "team" i)})))))
|
||||
(teams/create-team {::db/conn conn} {:id id
|
||||
:profile-id profile-id
|
||||
:features features
|
||||
:name (str "team" i)})))))
|
||||
|
||||
(defn create-file-media-object*
|
||||
([params] (create-file-media-object* *system* params))
|
||||
@ -283,9 +283,10 @@
|
||||
([params] (create-team-role* *system* params))
|
||||
([system {:keys [team-id profile-id role] :or {role :owner}}]
|
||||
(dm/with-open [conn (db/open system)]
|
||||
(#'teams/create-team-role conn {:team-id team-id
|
||||
:profile-id profile-id
|
||||
:role role}))))
|
||||
(#'teams/create-team-role {::db/conn conn}
|
||||
{:team-id team-id
|
||||
:profile-id profile-id
|
||||
:role role}))))
|
||||
|
||||
(defn create-project-role*
|
||||
([params] (create-project-role* *system* params))
|
||||
@ -384,6 +385,31 @@
|
||||
(dissoc ::type)
|
||||
(assoc :app.rpc/request-at (ct/now)))))))
|
||||
|
||||
(defn management-command!
|
||||
([data]
|
||||
(management-command! data nil))
|
||||
([{:keys [::type] :as data} flags-to-add]
|
||||
(let [flags (reduce conj cf/flags (or flags-to-add []))
|
||||
|
||||
resolve-management-methods
|
||||
(requiring-resolve 'app.rpc/resolve-management-methods)
|
||||
|
||||
methods
|
||||
(with-redefs [cf/flags flags]
|
||||
(resolve-management-methods *system*))
|
||||
|
||||
[_ method-fn]
|
||||
(get methods type)]
|
||||
|
||||
(when-not method-fn
|
||||
(ex/raise :type :assertion
|
||||
:code :rpc-method-not-found
|
||||
:hint (str/ffmt "management rpc method '%' not found" (name type))))
|
||||
|
||||
(try-on! (method-fn (-> data
|
||||
(dissoc ::type)
|
||||
(assoc :app.rpc/request-at (ct/now))))))))
|
||||
|
||||
(defn run-task!
|
||||
([name]
|
||||
(run-task! name {}))
|
||||
|
||||
@ -2121,3 +2121,92 @@
|
||||
(t/is (= 1 (count rows)))
|
||||
(t/is (= (:created-at row1) #penpot/inst "2025-10-31T00:00:00Z"))
|
||||
(t/is (nil? (:deleted-at row1))))))))
|
||||
|
||||
(t/deftest get-file-stats-empty-file
|
||||
(let [profile (th/create-profile* 1 {:is-active true})
|
||||
file (th/create-file* 1 {:profile-id (:id profile)
|
||||
:project-id (:default-project-id profile)
|
||||
:is-shared false})
|
||||
out (th/command! {::th/type :get-file-stats
|
||||
::rpc/profile-id (:id profile)
|
||||
:id (:id file)})]
|
||||
|
||||
;; (th/print-result! out)
|
||||
(t/is (nil? (:error out)))
|
||||
|
||||
(let [result (:result out)]
|
||||
(t/is (= (:id file) (:file-id result)))
|
||||
(t/is (pos? (:page-count result)))
|
||||
(t/is (zero? (:component-count result)))
|
||||
(t/is (zero? (:deleted-component-count result)))
|
||||
(t/is (zero? (:color-count result)))
|
||||
(t/is (zero? (:typography-count result)))
|
||||
(t/is (zero? (:library-count result)))
|
||||
(t/is (zero? (:referenced-by-count result)))
|
||||
(t/is (contains? result :shape-counts))
|
||||
(t/is (zero? (get-in result [:shape-counts :total])))
|
||||
(t/is (= {} (get-in result [:shape-counts :by-type]))))))
|
||||
|
||||
(t/deftest get-file-stats-with-shapes
|
||||
(let [profile (th/create-profile* 1 {:is-active true})
|
||||
file (th/create-file* 1 {:profile-id (:id profile)
|
||||
:project-id (:default-project-id profile)
|
||||
:is-shared false})
|
||||
page-id (-> file :data :pages first)
|
||||
rect-id (uuid/random)
|
||||
frame-id (uuid/random)]
|
||||
|
||||
(update-file!
|
||||
:file-id (:id file)
|
||||
:profile-id (:id profile)
|
||||
:revn 0
|
||||
:vern 0
|
||||
:changes
|
||||
[{:type :add-obj
|
||||
:page-id page-id
|
||||
:id frame-id
|
||||
:parent-id uuid/zero
|
||||
:frame-id uuid/zero
|
||||
:components-v2 true
|
||||
:obj (cts/setup-shape
|
||||
{:id frame-id
|
||||
:name "frame"
|
||||
:frame-id uuid/zero
|
||||
:parent-id uuid/zero
|
||||
:type :frame})}
|
||||
{:type :add-obj
|
||||
:page-id page-id
|
||||
:id rect-id
|
||||
:parent-id frame-id
|
||||
:frame-id frame-id
|
||||
:components-v2 true
|
||||
:obj (cts/setup-shape
|
||||
{:id rect-id
|
||||
:name "rect"
|
||||
:frame-id frame-id
|
||||
:parent-id frame-id
|
||||
:type :rect})}])
|
||||
|
||||
(let [out (th/command! {::th/type :get-file-stats
|
||||
::rpc/profile-id (:id profile)
|
||||
:id (:id file)})
|
||||
result (:result out)]
|
||||
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (= 2 (get-in result [:shape-counts :total])))
|
||||
(t/is (= 1 (get-in result [:shape-counts :by-type :rect])))
|
||||
(t/is (= 1 (get-in result [:shape-counts :by-type :frame]))))))
|
||||
|
||||
(t/deftest get-file-stats-forbidden
|
||||
(let [owner (th/create-profile* 1 {:is-active true})
|
||||
other (th/create-profile* 2 {:is-active true})
|
||||
file (th/create-file* 1 {:profile-id (:id owner)
|
||||
:project-id (:default-project-id owner)
|
||||
:is-shared false})
|
||||
out (th/command! {::th/type :get-file-stats
|
||||
::rpc/profile-id (:id other)
|
||||
:id (:id file)})]
|
||||
|
||||
(t/is (not (nil? (:error out))))
|
||||
(let [edata (-> out :error ex-data)]
|
||||
(t/is (= :not-found (:type edata))))))
|
||||
|
||||
930
backend/test/backend_tests/rpc_management_nitrate_test.clj
Normal file
930
backend/test/backend_tests/rpc_management_nitrate_test.clj
Normal file
@ -0,0 +1,930 @@
|
||||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;;
|
||||
;; Copyright (c) KALEIDOS INC
|
||||
|
||||
(ns backend-tests.rpc-management-nitrate-test
|
||||
(:require
|
||||
[app.common.data :as d]
|
||||
[app.common.time :as ct]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.config :as cf]
|
||||
[app.db :as-alias db]
|
||||
[app.msgbus :as mbus]
|
||||
[app.nitrate :as nitrate]
|
||||
[app.rpc :as-alias rpc]
|
||||
[app.worker :as wrk]
|
||||
[backend-tests.helpers :as th]
|
||||
[clojure.set :as set]
|
||||
[clojure.test :as t]
|
||||
[cuerdas.core :as str]))
|
||||
|
||||
(t/use-fixtures :once th/state-init)
|
||||
(t/use-fixtures :each th/database-reset)
|
||||
|
||||
(defn- management-command-with-nitrate!
|
||||
[data]
|
||||
(th/management-command! data [:nitrate]))
|
||||
|
||||
(t/deftest authenticate-success
|
||||
(let [profile (th/create-profile* 1 {:is-active true
|
||||
:fullname "Nitrate User"})
|
||||
out (management-command-with-nitrate! {::th/type :authenticate
|
||||
::rpc/profile-id (:id profile)})]
|
||||
(t/is (th/success? out))
|
||||
(t/is (= (:id profile) (-> out :result :id)))
|
||||
(t/is (= "Nitrate User" (-> out :result :name)))
|
||||
(t/is (= (:email profile) (-> out :result :email)))
|
||||
(t/is (nil? (-> out :result :photo-url)))))
|
||||
|
||||
(t/deftest authenticate-requires-authentication
|
||||
(let [out (management-command-with-nitrate! {::th/type :authenticate})]
|
||||
(t/is (not (th/success? out)))
|
||||
(t/is (= :authentication (th/ex-type (:error out))))
|
||||
(t/is (= :authentication-required (th/ex-code (:error out))))))
|
||||
|
||||
(t/deftest get-penpot-version
|
||||
(let [out (management-command-with-nitrate! {::th/type :get-penpot-version})
|
||||
version (-> out :result :version)]
|
||||
(t/is (th/success? out))
|
||||
(t/is (= #{:full :branch :base :main :major :minor :patch :modifier :commit :commit-hash}
|
||||
(set (keys version))))
|
||||
(doseq [k [:full :branch :base :main :major :minor :patch :modifier :commit :commit-hash]]
|
||||
(t/is (or (nil? (get version k))
|
||||
(string? (get version k)))))
|
||||
(t/is (= cf/version version))))
|
||||
|
||||
(t/deftest get-teams-returns-only-owned-non-default-non-deleted
|
||||
(let [profile (th/create-profile* 1 {:is-active true})
|
||||
other (th/create-profile* 2 {:is-active true})
|
||||
owned-team (th/create-team* 1 {:profile-id (:id profile)})
|
||||
deleted-team (th/create-team* 2 {:profile-id (:id profile)})
|
||||
_ (th/db-update! :team
|
||||
{:deleted-at (ct/now)}
|
||||
{:id (:id deleted-team)})
|
||||
other-team (th/create-team* 3 {:profile-id (:id other)})
|
||||
_ (th/create-team-role* {:team-id (:id other-team)
|
||||
:profile-id (:id profile)
|
||||
:role :editor})
|
||||
out (management-command-with-nitrate! {::th/type :get-teams
|
||||
::rpc/profile-id (:id profile)})]
|
||||
(t/is (th/success? out))
|
||||
(t/is (= #{(:id owned-team)}
|
||||
(->> out :result (map :id) set)))
|
||||
(t/is (= #{(:name owned-team)}
|
||||
(->> out :result (map :name) set)))))
|
||||
|
||||
(t/deftest notify-team-change-publishes-event
|
||||
(let [team-id (uuid/random)
|
||||
organization-id (uuid/random)
|
||||
organization {:id organization-id
|
||||
:name "Acme Inc"
|
||||
:slug "acme-inc"
|
||||
:owner-id (uuid/random)
|
||||
:avatar-bg-url "http://example.com/avatar.svg"}
|
||||
calls (atom [])
|
||||
out (with-redefs [mbus/pub! (fn [_cfg & {:keys [topic message]}]
|
||||
(swap! calls conj {:topic topic
|
||||
:message message}))]
|
||||
(management-command-with-nitrate! {::th/type :notify-team-change
|
||||
:id team-id
|
||||
:is-your-penpot false
|
||||
:organization organization}))]
|
||||
(t/is (th/success? out))
|
||||
(t/is (= 1 (count @calls)))
|
||||
(t/is (= uuid/zero (-> @calls first :topic)))
|
||||
(let [msg (-> @calls first :message)]
|
||||
(t/is (= :team-org-change (:type msg)))
|
||||
(t/is (= nil (:notification msg)))
|
||||
(t/is (= team-id (-> msg :team :id)))
|
||||
(t/is (= false (-> msg :team :is-your-penpot)))
|
||||
(t/is (= (:id organization) (-> msg :team :organization :id)))
|
||||
(t/is (= (:name organization) (-> msg :team :organization :name)))
|
||||
(t/is (= (:slug organization) (-> msg :team :organization :slug)))
|
||||
(t/is (= (:owner-id organization) (-> msg :team :organization :owner-id)))
|
||||
(t/is (= (:avatar-bg-url organization) (str (-> msg :team :organization :avatar-bg-url)))))))
|
||||
|
||||
(t/deftest notify-user-added-to-organization-creates-default-org-team
|
||||
(let [profile (th/create-profile* 1 {:is-active true})
|
||||
before-teams (->> (th/db-query :team-profile-rel {:profile-id (:id profile)
|
||||
:is-owner true})
|
||||
(map :team-id)
|
||||
set)
|
||||
out (management-command-with-nitrate! {::th/type :notify-user-added-to-organization
|
||||
:profile-id (:id profile)
|
||||
:organization-id (uuid/random)
|
||||
:role "owner"})
|
||||
after-teams (->> (th/db-query :team-profile-rel {:profile-id (:id profile)
|
||||
:is-owner true})
|
||||
(map :team-id)
|
||||
set)
|
||||
new-team-id (first (set/difference after-teams before-teams))
|
||||
new-team (th/db-get :team {:id new-team-id})]
|
||||
(t/is (th/success? out))
|
||||
(t/is (= 1 (count (set/difference after-teams before-teams))))
|
||||
(t/is (= "Your Penpot" (:name new-team)))
|
||||
(t/is (true? (:is-default new-team)))))
|
||||
|
||||
(t/deftest get-managed-profiles-returns-unique-members-for-owned-teams
|
||||
(let [owner (th/create-profile* 1 {:is-active true})
|
||||
member1 (th/create-profile* 2 {:is-active true})
|
||||
member2 (th/create-profile* 3 {:is-active true})
|
||||
team1 (th/create-team* 1 {:profile-id (:id owner)})
|
||||
team2 (th/create-team* 2 {:profile-id (:id owner)})
|
||||
_ (th/create-team-role* {:team-id (:id team1)
|
||||
:profile-id (:id member1)
|
||||
:role :editor})
|
||||
_ (th/create-team-role* {:team-id (:id team1)
|
||||
:profile-id (:id member2)
|
||||
:role :editor})
|
||||
_ (th/create-team-role* {:team-id (:id team2)
|
||||
:profile-id (:id member1)
|
||||
:role :editor})
|
||||
out (management-command-with-nitrate! {::th/type :get-managed-profiles
|
||||
::rpc/profile-id (:id owner)})]
|
||||
(t/is (th/success? out))
|
||||
(t/is (= #{(:id member1) (:id member2)}
|
||||
(->> out :result (map :id) set)))
|
||||
(t/is (= #{(:email member1) (:email member2)}
|
||||
(->> out :result (map :email) set)))))
|
||||
|
||||
(t/deftest get-teams-summary-returns-teams-and-files-count
|
||||
(let [profile (th/create-profile* 1 {:is-active true})
|
||||
team1 (th/create-team* 1 {:profile-id (:id profile)})
|
||||
team2 (th/create-team* 2 {:profile-id (:id profile)})
|
||||
proj1 (th/create-project* 1 {:profile-id (:id profile)
|
||||
:team-id (:id team1)})
|
||||
proj2 (th/create-project* 2 {:profile-id (:id profile)
|
||||
:team-id (:id team2)})
|
||||
_ (th/create-file* 1 {:profile-id (:id profile)
|
||||
:project-id (:id proj1)})
|
||||
_ (th/create-file* 2 {:profile-id (:id profile)
|
||||
:project-id (:id proj2)})
|
||||
out (management-command-with-nitrate! {::th/type :get-teams-summary
|
||||
::rpc/profile-id (:id profile)
|
||||
:ids [(:id team1) (:id team2)]})]
|
||||
(t/is (th/success? out))
|
||||
(t/is (= 2 (-> out :result :num-files)))
|
||||
(t/is (= #{(:id team1) (:id team2)}
|
||||
(->> out :result :teams (map :id) set)))))
|
||||
|
||||
(t/deftest notify-organization-deletion-prefixes-teams-and-publishes-org-deleted-event
|
||||
(let [profile (th/create-profile* 1 {:is-active true})
|
||||
;; One team will have files -> it will be kept and renamed.
|
||||
team-with-files (th/db-get :team {:id (:default-team-id profile)})
|
||||
project (th/create-project* 1 {:profile-id (:id profile)
|
||||
:team-id (:id team-with-files)})
|
||||
_ (th/create-file* 1 {:profile-id (:id profile)
|
||||
:project-id (:id project)})
|
||||
|
||||
;; One team will be empty -> it will be soft-deleted.
|
||||
empty-team (th/create-team* 1 {:profile-id (:id profile)})
|
||||
|
||||
organization-id (uuid/random)
|
||||
organization-name "Acme / Design"
|
||||
expected-start (str "[" (d/sanitize-string organization-name) "] ")
|
||||
org-summary {:id organization-id
|
||||
:name organization-name
|
||||
:teams [{:id (:id team-with-files)}
|
||||
{:id (:id empty-team)}]}
|
||||
calls (atom [])
|
||||
submitted (atom [])
|
||||
out (with-redefs [nitrate/call (fn [_cfg method params]
|
||||
(t/is (= :get-org-summary method))
|
||||
(t/is (= {:organization-id organization-id} params))
|
||||
org-summary)
|
||||
wrk/submit! (fn [task]
|
||||
(swap! submitted conj task)
|
||||
nil)
|
||||
mbus/pub! (fn [_cfg & {:keys [topic message]}]
|
||||
(swap! calls conj {:topic topic
|
||||
:message message}))]
|
||||
(management-command-with-nitrate! {::th/type :notify-organization-deletion
|
||||
::rpc/profile-id (:id profile)
|
||||
:organization-id organization-id}))
|
||||
updated-with-files (th/db-get :team {:id (:id team-with-files)} {::db/remove-deleted false})
|
||||
updated-empty (th/db-get :team {:id (:id empty-team)} {::db/remove-deleted false})]
|
||||
(t/is (th/success? out))
|
||||
(t/is (nil? (:result out)))
|
||||
|
||||
;; Team with files is kept, unset as default, and renamed with org prefix.
|
||||
(t/is (false? (:is-default updated-with-files)))
|
||||
(t/is (str/starts-with? (:name updated-with-files) expected-start))
|
||||
(t/is (nil? (:deleted-at updated-with-files)))
|
||||
|
||||
;; Empty team is soft-deleted and a delete task is submitted.
|
||||
(t/is (some? (:deleted-at updated-empty)))
|
||||
(t/is (= 1 (count @submitted)))
|
||||
|
||||
;; A single organization-deleted event is published.
|
||||
(t/is (= 1 (count @calls)))
|
||||
(let [{:keys [topic message]} (first @calls)]
|
||||
(t/is (= uuid/zero topic))
|
||||
(t/is (= :organization-deleted (:type message)))
|
||||
(t/is (= organization-name (:organization-name message)))
|
||||
(t/is (= #{(:id team-with-files) (:id empty-team)}
|
||||
(set (:teams message))))
|
||||
(t/is (= #{(:id empty-team)}
|
||||
(set (:deleted-teams message)))))))
|
||||
|
||||
(t/deftest notify-user-organizations-deletion-renames-or-deletes-teams-and-publishes-per-org-events
|
||||
(let [profile (th/create-profile* 1 {:is-active true})
|
||||
;; org-1: one team with files, one empty
|
||||
org-1-team-files (th/db-get :team {:id (:default-team-id profile)})
|
||||
org-1-proj (th/create-project* 1 {:profile-id (:id profile)
|
||||
:team-id (:id org-1-team-files)})
|
||||
_ (th/create-file* 1 {:profile-id (:id profile)
|
||||
:project-id (:id org-1-proj)})
|
||||
org-1-team-empty (th/create-team* 1 {:profile-id (:id profile)})
|
||||
|
||||
;; org-2: one team with files, one empty
|
||||
org-2-team-files (th/create-team* 2 {:profile-id (:id profile)})
|
||||
org-2-proj (th/create-project* 2 {:profile-id (:id profile)
|
||||
:team-id (:id org-2-team-files)})
|
||||
_ (th/create-file* 2 {:profile-id (:id profile)
|
||||
:project-id (:id org-2-proj)})
|
||||
org-2-team-empty (th/create-team* 3 {:profile-id (:id profile)})
|
||||
|
||||
org-1-id (uuid/random)
|
||||
org-2-id (uuid/random)
|
||||
org-1-name "Org One / Design"
|
||||
org-2-name "Org Two"
|
||||
org-1-prefix (str "[" (d/sanitize-string org-1-name) "] ")
|
||||
org-2-prefix (str "[" (d/sanitize-string org-2-name) "] ")
|
||||
owned-orgs [{:id org-1-id
|
||||
:name org-1-name
|
||||
:teams [{:id (:id org-1-team-files)}
|
||||
{:id (:id org-1-team-empty)}]}
|
||||
{:id org-2-id
|
||||
:name org-2-name
|
||||
:teams [{:id (:id org-2-team-files)}
|
||||
{:id (:id org-2-team-empty)}]}]
|
||||
calls (atom [])
|
||||
submitted (atom [])
|
||||
out (with-redefs [nitrate/call (fn [_cfg method params]
|
||||
(case method
|
||||
:get-owned-orgs
|
||||
(do
|
||||
(t/is (= {:profile-id (:id profile)} params))
|
||||
owned-orgs)
|
||||
nil))
|
||||
wrk/submit! (fn [task]
|
||||
(swap! submitted conj task)
|
||||
nil)
|
||||
mbus/pub! (fn [_cfg & {:keys [topic message]}]
|
||||
(swap! calls conj {:topic topic
|
||||
:message message}))]
|
||||
(management-command-with-nitrate! {::th/type :notify-user-organizations-deletion
|
||||
::rpc/profile-id (:id profile)
|
||||
:profile-id (:id profile)}))
|
||||
org-1-updated-files (th/db-get :team {:id (:id org-1-team-files)} {::db/remove-deleted false})
|
||||
org-1-updated-empty (th/db-get :team {:id (:id org-1-team-empty)} {::db/remove-deleted false})
|
||||
org-2-updated-files (th/db-get :team {:id (:id org-2-team-files)} {::db/remove-deleted false})
|
||||
org-2-updated-empty (th/db-get :team {:id (:id org-2-team-empty)} {::db/remove-deleted false})
|
||||
msgs (->> @calls (map :message) vec)
|
||||
org-msg (fn [org-name]
|
||||
(first (filter #(= org-name (:organization-name %)) msgs)))]
|
||||
(t/is (th/success? out))
|
||||
(t/is (nil? (:result out)))
|
||||
|
||||
;; org-1: team with files renamed; empty team deleted
|
||||
(t/is (false? (:is-default org-1-updated-files)))
|
||||
(t/is (str/starts-with? (:name org-1-updated-files) org-1-prefix))
|
||||
(t/is (nil? (:deleted-at org-1-updated-files)))
|
||||
(t/is (some? (:deleted-at org-1-updated-empty)))
|
||||
|
||||
;; org-2: team with files renamed; empty team deleted
|
||||
(t/is (false? (:is-default org-2-updated-files)))
|
||||
(t/is (str/starts-with? (:name org-2-updated-files) org-2-prefix))
|
||||
(t/is (nil? (:deleted-at org-2-updated-files)))
|
||||
(t/is (some? (:deleted-at org-2-updated-empty)))
|
||||
|
||||
;; two delete tasks (one per empty team)
|
||||
(t/is (= 2 (count @submitted)))
|
||||
|
||||
;; one organization-deleted event per org
|
||||
(t/is (= 2 (count @calls)))
|
||||
(t/is (every? #(= uuid/zero (:topic %)) @calls))
|
||||
(t/is (= #{:organization-deleted}
|
||||
(set (map (comp :type :message) @calls))))
|
||||
|
||||
(let [m1 (org-msg org-1-name)
|
||||
m2 (org-msg org-2-name)]
|
||||
(t/is (some? m1))
|
||||
(t/is (some? m2))
|
||||
(t/is (= #{(:id org-1-team-files) (:id org-1-team-empty)}
|
||||
(set (:teams m1))))
|
||||
(t/is (= #{(:id org-1-team-empty)}
|
||||
(set (:deleted-teams m1))))
|
||||
(t/is (= #{(:id org-2-team-files) (:id org-2-team-empty)}
|
||||
(set (:teams m2))))
|
||||
(t/is (= #{(:id org-2-team-empty)}
|
||||
(set (:deleted-teams m2)))))))
|
||||
|
||||
(t/deftest get-profile-by-email-success-and-not-found
|
||||
(let [profile (th/create-profile* 1 {:is-active true
|
||||
:fullname "Lookup by Email"})
|
||||
ok-out (management-command-with-nitrate! {::th/type :get-profile-by-email
|
||||
::rpc/profile-id (:id profile)
|
||||
:email (:email profile)})
|
||||
ko-out (management-command-with-nitrate! {::th/type :get-profile-by-email
|
||||
::rpc/profile-id (:id profile)
|
||||
:email "not-found@example.com"})]
|
||||
(t/is (th/success? ok-out))
|
||||
(t/is (= (:id profile) (-> ok-out :result :id)))
|
||||
(t/is (= "Lookup by Email" (-> ok-out :result :name)))
|
||||
(t/is (nil? (-> ok-out :result :photo-url)))
|
||||
|
||||
(t/is (not (th/success? ko-out)))
|
||||
(t/is (= :not-found (th/ex-type (:error ko-out))))
|
||||
(t/is (= :profile-not-found (th/ex-code (:error ko-out))))))
|
||||
|
||||
(t/deftest get-profile-by-id-success-and-not-found
|
||||
(let [profile (th/create-profile* 1 {:is-active true
|
||||
:fullname "Lookup by Id"})
|
||||
ok-out (management-command-with-nitrate! {::th/type :get-profile-by-id
|
||||
::rpc/profile-id (:id profile)
|
||||
:id (:id profile)})
|
||||
ko-out (management-command-with-nitrate! {::th/type :get-profile-by-id
|
||||
::rpc/profile-id (:id profile)
|
||||
:id (uuid/random)})]
|
||||
(t/is (th/success? ok-out))
|
||||
(t/is (= (:id profile) (-> ok-out :result :id)))
|
||||
(t/is (= "Lookup by Id" (-> ok-out :result :name)))
|
||||
(t/is (nil? (-> ok-out :result :photo-url)))
|
||||
|
||||
(t/is (not (th/success? ko-out)))
|
||||
(t/is (= :not-found (th/ex-type (:error ko-out))))
|
||||
(t/is (= :profile-not-found (th/ex-code (:error ko-out))))))
|
||||
|
||||
(t/deftest get-org-invitations-returns-valid-deduped-by-email
|
||||
(let [profile (th/create-profile* 1 {:is-active true})
|
||||
team-1 (th/create-team* 1 {:profile-id (:id profile)})
|
||||
team-2 (th/create-team* 2 {:profile-id (:id profile)})
|
||||
org-id (uuid/random)
|
||||
org-summary {:id org-id
|
||||
:teams [{:id (:id team-1)}
|
||||
{:id (:id team-2)}]}
|
||||
params {::th/type :get-org-invitations
|
||||
::rpc/profile-id (:id profile)
|
||||
:organization-id org-id}]
|
||||
|
||||
;; Same email appears in org and team invitations; only one should be returned.
|
||||
(th/db-insert! :team-invitation
|
||||
{:id (uuid/random)
|
||||
:org-id org-id
|
||||
:team-id nil
|
||||
:email-to "dup@example.com"
|
||||
:created-by (:id profile)
|
||||
:role "editor"
|
||||
:valid-until (ct/in-future "24h")})
|
||||
|
||||
(th/db-insert! :team-invitation
|
||||
{:id (uuid/random)
|
||||
:team-id (:id team-1)
|
||||
:org-id nil
|
||||
:email-to "dup@example.com"
|
||||
:created-by (:id profile)
|
||||
:role "admin"
|
||||
:valid-until (ct/in-future "72h")})
|
||||
|
||||
(th/db-insert! :team-invitation
|
||||
{:id (uuid/random)
|
||||
:team-id (:id team-2)
|
||||
:org-id nil
|
||||
:email-to "valid@example.com"
|
||||
:created-by (:id profile)
|
||||
:role "editor"
|
||||
:valid-until (ct/in-future "48h")})
|
||||
|
||||
;; Expired invitation should be ignored.
|
||||
(th/db-insert! :team-invitation
|
||||
{:id (uuid/random)
|
||||
:org-id org-id
|
||||
:team-id nil
|
||||
:email-to "expired@example.com"
|
||||
:created-by (:id profile)
|
||||
:role "editor"
|
||||
:valid-until (ct/in-past "1h")})
|
||||
|
||||
(let [out (with-redefs [nitrate/call (fn [_cfg method _params]
|
||||
(case method
|
||||
:get-org-summary org-summary
|
||||
nil))]
|
||||
(management-command-with-nitrate! params))
|
||||
result (:result out)
|
||||
emails (->> result (map :email) set)
|
||||
dedup (->> result
|
||||
(filter #(= "dup@example.com" (:email %)))
|
||||
first)]
|
||||
(t/is (th/success? out))
|
||||
(t/is (= #{"dup@example.com" "valid@example.com"} emails))
|
||||
(t/is (= 2 (count result)))
|
||||
(t/is (some? (:id dedup)))
|
||||
(t/is (some? (:sent-at dedup)))
|
||||
(t/is (nil? (:organization-id dedup)))
|
||||
(t/is (nil? (:team-id dedup)))
|
||||
(t/is (nil? (:role dedup)))
|
||||
(t/is (nil? (:valid-until dedup))))))
|
||||
|
||||
(t/deftest get-org-invitations-includes-org-level-invitations-when-no-teams
|
||||
(let [profile (th/create-profile* 1 {:is-active true})
|
||||
org-id (uuid/random)
|
||||
org-summary {:id org-id
|
||||
:teams []}
|
||||
params {::th/type :get-org-invitations
|
||||
::rpc/profile-id (:id profile)
|
||||
:organization-id org-id}]
|
||||
|
||||
(th/db-insert! :team-invitation
|
||||
{:id (uuid/random)
|
||||
:org-id org-id
|
||||
:team-id nil
|
||||
:email-to "org-only@example.com"
|
||||
:created-by (:id profile)
|
||||
:role "editor"
|
||||
:valid-until (ct/in-future "24h")})
|
||||
|
||||
(let [out (with-redefs [nitrate/call (fn [_cfg method _params]
|
||||
(case method
|
||||
:get-org-summary org-summary
|
||||
nil))]
|
||||
(management-command-with-nitrate! params))
|
||||
result (:result out)]
|
||||
(t/is (th/success? out))
|
||||
(t/is (= 1 (count result)))
|
||||
(t/is (= "org-only@example.com" (-> result first :email)))
|
||||
(t/is (some? (-> result first :sent-at))))))
|
||||
|
||||
(t/deftest get-org-invitations-returns-existing-profile-data
|
||||
(let [profile (th/create-profile* 1 {:is-active true})
|
||||
invited (th/create-profile* 2 {:is-active true
|
||||
:fullname "Invited User"})
|
||||
photo-id (uuid/random)
|
||||
_ (th/db-insert! :storage-object {:id photo-id
|
||||
:backend "assets-fs"})
|
||||
_ (th/db-update! :profile {:photo-id photo-id} {:id (:id invited)})
|
||||
org-id (uuid/random)
|
||||
org-summary {:id org-id
|
||||
:teams []}
|
||||
params {::th/type :get-org-invitations
|
||||
::rpc/profile-id (:id profile)
|
||||
:organization-id org-id}]
|
||||
|
||||
(th/db-insert! :team-invitation
|
||||
{:id (uuid/random)
|
||||
:org-id org-id
|
||||
:team-id nil
|
||||
:email-to (:email invited)
|
||||
:created-by (:id profile)
|
||||
:role "editor"
|
||||
:valid-until (ct/in-future "24h")})
|
||||
|
||||
(let [out (with-redefs [nitrate/call (fn [_cfg method _params]
|
||||
(case method
|
||||
:get-org-summary org-summary
|
||||
nil))]
|
||||
(management-command-with-nitrate! params))
|
||||
invitation (-> out :result first)]
|
||||
(t/is (th/success? out))
|
||||
(t/is (= "Invited User" (:name invitation)))
|
||||
(t/is (some? (:sent-at invitation)))
|
||||
(t/is (str/ends-with? (:photo-url invitation)
|
||||
(str "/assets/by-id/" photo-id))))))
|
||||
|
||||
(t/deftest delete-org-invitations-removes-org-and-org-team-invitations-for-email
|
||||
(let [profile (th/create-profile* 1 {:is-active true})
|
||||
team-1 (th/create-team* 1 {:profile-id (:id profile)})
|
||||
team-2 (th/create-team* 2 {:profile-id (:id profile)})
|
||||
outside-team (th/create-team* 3 {:profile-id (:id profile)})
|
||||
org-id (uuid/random)
|
||||
org-summary {:id org-id
|
||||
:teams [{:id (:id team-1)}
|
||||
{:id (:id team-2)}]}
|
||||
target-email "target@example.com"
|
||||
params {::th/type :delete-org-invitations
|
||||
::rpc/profile-id (:id profile)
|
||||
:organization-id org-id
|
||||
:email "TARGET@example.com"}]
|
||||
|
||||
;; Should be deleted: org-level invitation for same org+email.
|
||||
(th/db-insert! :team-invitation
|
||||
{:id (uuid/random)
|
||||
:org-id org-id
|
||||
:team-id nil
|
||||
:email-to target-email
|
||||
:created-by (:id profile)
|
||||
:role "editor"
|
||||
:valid-until (ct/in-future "24h")})
|
||||
|
||||
;; Should be deleted: team-level invitation for teams belonging to org summary.
|
||||
(th/db-insert! :team-invitation
|
||||
{:id (uuid/random)
|
||||
:team-id (:id team-1)
|
||||
:org-id nil
|
||||
:email-to target-email
|
||||
:created-by (:id profile)
|
||||
:role "editor"
|
||||
:valid-until (ct/in-past "1h")})
|
||||
|
||||
;; Should remain: different email.
|
||||
(th/db-insert! :team-invitation
|
||||
{:id (uuid/random)
|
||||
:team-id (:id team-2)
|
||||
:org-id nil
|
||||
:email-to "other@example.com"
|
||||
:created-by (:id profile)
|
||||
:role "editor"
|
||||
:valid-until (ct/in-future "24h")})
|
||||
|
||||
;; Should remain: same email but outside org scope.
|
||||
(th/db-insert! :team-invitation
|
||||
{:id (uuid/random)
|
||||
:team-id (:id outside-team)
|
||||
:org-id nil
|
||||
:email-to target-email
|
||||
:created-by (:id profile)
|
||||
:role "editor"
|
||||
:valid-until (ct/in-future "24h")})
|
||||
|
||||
(let [out (with-redefs [nitrate/call (fn [_cfg method _params]
|
||||
(case method
|
||||
:get-org-summary org-summary
|
||||
nil))]
|
||||
(management-command-with-nitrate! params))
|
||||
remaining-target (th/db-query :team-invitation {:email-to target-email})
|
||||
remaining-other (th/db-query :team-invitation {:email-to "other@example.com"})]
|
||||
(t/is (th/success? out))
|
||||
(t/is (nil? (:result out)))
|
||||
(t/is (= 1 (count remaining-target)))
|
||||
(t/is (= (:id outside-team) (:team-id (first remaining-target))))
|
||||
(t/is (= 1 (count remaining-other))))))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Tests: remove-from-org
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(defn- make-org-summary
|
||||
[& {:keys [organization-id organization-name owner-id your-penpot-teams org-teams]
|
||||
:or {your-penpot-teams [] org-teams []}}]
|
||||
{:id organization-id
|
||||
:name organization-name
|
||||
:owner-id owner-id
|
||||
:teams (into
|
||||
(mapv (fn [id] {:id id :is-your-penpot true}) your-penpot-teams)
|
||||
(mapv (fn [id] {:id id :is-your-penpot false}) org-teams))})
|
||||
|
||||
(defn- nitrate-call-mock
|
||||
[org-summary]
|
||||
(fn [_cfg method _params]
|
||||
(case method
|
||||
:get-org-summary org-summary
|
||||
:get-org-membership {:organization-id (:id org-summary)
|
||||
:is-member true}
|
||||
:remove-profile-from-org nil
|
||||
nil)))
|
||||
|
||||
(t/deftest remove-from-org-happy-path-no-extra-teams
|
||||
;; User is only in its default team (which has files); it should be
|
||||
;; kept, renamed and unset as default. A notification must be sent.
|
||||
(let [org-owner (th/create-profile* 1 {:is-active true})
|
||||
user (th/create-profile* 2 {:is-active true})
|
||||
org-team (th/create-team* 1 {:profile-id (:id user)})
|
||||
project (th/create-project* 1 {:profile-id (:id user)
|
||||
:team-id (:id org-team)})
|
||||
_ (th/create-file* 1 {:profile-id (:id user)
|
||||
:project-id (:id project)})
|
||||
organization-id (uuid/random)
|
||||
org-summary (make-org-summary
|
||||
:organization-id organization-id
|
||||
:organization-name "Acme Org"
|
||||
:owner-id (:id org-owner)
|
||||
:your-penpot-teams [(:id org-team)]
|
||||
:org-teams [])
|
||||
calls (atom [])
|
||||
out (with-redefs [nitrate/call (nitrate-call-mock org-summary)
|
||||
mbus/pub! (fn [_bus & {:keys [topic message]}]
|
||||
(swap! calls conj {:topic topic :message message}))]
|
||||
(management-command-with-nitrate!
|
||||
{::th/type :remove-from-org
|
||||
::rpc/profile-id (:id org-owner)
|
||||
:profile-id (:id user)
|
||||
:organization-id organization-id
|
||||
:organization-name "Acme Org"
|
||||
:default-team-id (:id org-team)}))]
|
||||
(t/is (th/success? out))
|
||||
(t/is (nil? (:result out)))
|
||||
|
||||
;; default team preserved, renamed and unset as default
|
||||
(let [team (th/db-get :team {:id (:id org-team)})]
|
||||
(t/is (false? (:is-default team)))
|
||||
(t/is (str/starts-with? (:name team) "[Acme Org] ")))
|
||||
|
||||
;; exactly one notification sent to the user
|
||||
(t/is (= 1 (count @calls)))
|
||||
(let [msg (-> @calls first :message)]
|
||||
(t/is (= :user-org-change (:type msg)))
|
||||
(t/is (= (:id user) (:topic msg)))
|
||||
(t/is (= organization-id (:organization-id msg)))
|
||||
(t/is (= "Acme Org" (:organization-name msg)))
|
||||
(t/is (= "dashboard.user-no-longer-belong-org" (:notification msg))))))
|
||||
|
||||
(t/deftest remove-from-org-deletes-empty-default-team
|
||||
;; When the default team has no files it should be soft-deleted.
|
||||
(let [org-owner (th/create-profile* 1 {:is-active true})
|
||||
user (th/create-profile* 2 {:is-active true})
|
||||
org-team (th/create-team* 2 {:profile-id (:id user)})
|
||||
organization-id (uuid/random)
|
||||
org-summary (make-org-summary
|
||||
:organization-id organization-id
|
||||
:organization-name "Acme Org"
|
||||
:owner-id (:id org-owner)
|
||||
:your-penpot-teams [(:id org-team)]
|
||||
:org-teams [])
|
||||
out (with-redefs [nitrate/call (nitrate-call-mock org-summary)
|
||||
mbus/pub! (fn [& _] nil)]
|
||||
(management-command-with-nitrate!
|
||||
{::th/type :remove-from-org
|
||||
::rpc/profile-id (:id org-owner)
|
||||
:profile-id (:id user)
|
||||
:organization-id organization-id
|
||||
:organization-name "Acme Org"
|
||||
:default-team-id (:id org-team)}))]
|
||||
(t/is (th/success? out))
|
||||
(let [team (th/db-get :team {:id (:id org-team)} {::db/remove-deleted false})]
|
||||
(t/is (some? (:deleted-at team))))))
|
||||
|
||||
(t/deftest remove-from-org-deletes-sole-owner-team
|
||||
;; When the user is the sole member of an org team it should be deleted.
|
||||
(let [org-owner (th/create-profile* 1 {:is-active true})
|
||||
user (th/create-profile* 2 {:is-active true})
|
||||
extra-team (th/create-team* 3 {:profile-id (:id user)})
|
||||
org-team (th/create-team* 99 {:profile-id (:id user)})
|
||||
organization-id (uuid/random)
|
||||
org-summary (make-org-summary
|
||||
:organization-id organization-id
|
||||
:organization-name "Acme Org"
|
||||
:owner-id (:id org-owner)
|
||||
:your-penpot-teams [(:id org-team)]
|
||||
:org-teams [(:id extra-team)])
|
||||
out (with-redefs [nitrate/call (nitrate-call-mock org-summary)
|
||||
mbus/pub! (fn [& _] nil)]
|
||||
(management-command-with-nitrate!
|
||||
{::th/type :remove-from-org
|
||||
::rpc/profile-id (:id org-owner)
|
||||
:profile-id (:id user)
|
||||
:organization-id organization-id
|
||||
:organization-name "Acme Org"
|
||||
:default-team-id (:id org-team)}))]
|
||||
(t/is (th/success? out))
|
||||
(let [team (th/db-get :team {:id (:id extra-team)} {::db/remove-deleted false})]
|
||||
(t/is (some? (:deleted-at team))))))
|
||||
|
||||
(t/deftest remove-from-org-transfers-ownership-of-multi-member-team
|
||||
;; When the user owns a team that has another non-owner member, ownership
|
||||
;; is transferred to that member by the endpoint automatically.
|
||||
(let [org-owner (th/create-profile* 1 {:is-active true})
|
||||
user (th/create-profile* 2 {:is-active true})
|
||||
candidate (th/create-profile* 3 {:is-active true})
|
||||
extra-team (th/create-team* 4 {:profile-id (:id user)})
|
||||
_ (th/create-team-role* {:team-id (:id extra-team)
|
||||
:profile-id (:id candidate)
|
||||
:role :editor})
|
||||
org-team (th/create-team* 99 {:profile-id (:id user)})
|
||||
organization-id (uuid/random)
|
||||
org-summary (make-org-summary
|
||||
:organization-id organization-id
|
||||
:organization-name "Acme Org"
|
||||
:owner-id (:id org-owner)
|
||||
:your-penpot-teams [(:id org-team)]
|
||||
:org-teams [(:id extra-team)])
|
||||
out (with-redefs [nitrate/call (nitrate-call-mock org-summary)
|
||||
mbus/pub! (fn [& _] nil)]
|
||||
(management-command-with-nitrate!
|
||||
{::th/type :remove-from-org
|
||||
::rpc/profile-id (:id org-owner)
|
||||
:profile-id (:id user)
|
||||
:organization-id organization-id
|
||||
:organization-name "Acme Org"
|
||||
:default-team-id (:id org-team)}))]
|
||||
(t/is (th/success? out))
|
||||
;; user no longer in extra-team
|
||||
(let [rel (th/db-get :team-profile-rel {:team-id (:id extra-team) :profile-id (:id user)})]
|
||||
(t/is (nil? rel)))
|
||||
;; candidate promoted to owner
|
||||
(let [rel (th/db-get :team-profile-rel {:team-id (:id extra-team) :profile-id (:id candidate)})]
|
||||
(t/is (true? (:is-owner rel))))))
|
||||
|
||||
(t/deftest remove-from-org-exits-non-owned-team
|
||||
;; When the user is a non-owner member of an org team, they simply leave.
|
||||
(let [org-owner (th/create-profile* 1 {:is-active true})
|
||||
user (th/create-profile* 2 {:is-active true})
|
||||
extra-team (th/create-team* 5 {:profile-id (:id org-owner)})
|
||||
_ (th/create-team-role* {:team-id (:id extra-team)
|
||||
:profile-id (:id user)
|
||||
:role :editor})
|
||||
org-team (th/create-team* 99 {:profile-id (:id user)})
|
||||
organization-id (uuid/random)
|
||||
org-summary (make-org-summary
|
||||
:organization-id organization-id
|
||||
:organization-name "Acme Org"
|
||||
:owner-id (:id org-owner)
|
||||
:your-penpot-teams [(:id org-team)]
|
||||
:org-teams [(:id extra-team)])
|
||||
out (with-redefs [nitrate/call (nitrate-call-mock org-summary)
|
||||
mbus/pub! (fn [& _] nil)]
|
||||
(management-command-with-nitrate!
|
||||
{::th/type :remove-from-org
|
||||
::rpc/profile-id (:id org-owner)
|
||||
:profile-id (:id user)
|
||||
:organization-id organization-id
|
||||
:organization-name "Acme Org"
|
||||
:default-team-id (:id org-team)}))]
|
||||
(t/is (th/success? out))
|
||||
;; user no longer a member of extra-team
|
||||
(let [rel (th/db-get :team-profile-rel {:team-id (:id extra-team) :profile-id (:id user)})]
|
||||
(t/is (nil? rel)))
|
||||
;; team still exists for the owner
|
||||
(let [team (th/db-get :team {:id (:id extra-team)})]
|
||||
(t/is (some? team)))))
|
||||
|
||||
(t/deftest remove-from-org-error-nobody-to-reassign
|
||||
;; When the user owns a multi-member team but every other member is
|
||||
;; also an owner, the auto-selection query finds nobody and raises.
|
||||
(let [other-owner (th/create-profile* 1 {:is-active true})
|
||||
user (th/create-profile* 2 {:is-active true})
|
||||
extra-team (th/create-team* 6 {:profile-id (:id user)})
|
||||
;; add other-owner to the team and make them co-owner directly in DB
|
||||
_ (th/create-team-role* {:team-id (:id extra-team)
|
||||
:profile-id (:id other-owner)
|
||||
:role :editor})
|
||||
_ (th/db-update! :team-profile-rel
|
||||
{:is-owner true :is-admin false}
|
||||
{:team-id (:id extra-team) :profile-id (:id other-owner)})
|
||||
org-team (th/create-team* 99 {:profile-id (:id user)})
|
||||
organization-id (uuid/random)
|
||||
org-summary (make-org-summary
|
||||
:organization-id organization-id
|
||||
:organization-name "Acme Org"
|
||||
:owner-id (:id other-owner)
|
||||
:your-penpot-teams [(:id org-team)]
|
||||
:org-teams [(:id extra-team)])
|
||||
out (with-redefs [nitrate/call (nitrate-call-mock org-summary)
|
||||
mbus/pub! (fn [& _] nil)]
|
||||
(management-command-with-nitrate!
|
||||
{::th/type :remove-from-org
|
||||
::rpc/profile-id (:id other-owner)
|
||||
:profile-id (:id user)
|
||||
:organization-id organization-id
|
||||
:organization-name "Acme Org"
|
||||
:default-team-id (:id org-team)}))]
|
||||
(t/is (not (th/success? out)))
|
||||
(t/is (= :validation (th/ex-type (:error out))))
|
||||
(t/is (= :nobody-to-reassign-team (th/ex-code (:error out))))))
|
||||
|
||||
;; Tests: get-remove-from-org-summary
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(t/deftest get-remove-from-org-summary-no-extra-teams
|
||||
;; User only has a default team — nothing to delete/transfer/exit.
|
||||
(let [org-owner (th/create-profile* 1 {:is-active true})
|
||||
user (th/create-profile* 2 {:is-active true})
|
||||
org-team (th/create-team* 1 {:profile-id (:id user)})
|
||||
organization-id (uuid/random)
|
||||
org-summary (make-org-summary
|
||||
:organization-id organization-id
|
||||
:organization-name "Acme Org"
|
||||
:owner-id (:id org-owner)
|
||||
:your-penpot-teams [(:id org-team)]
|
||||
:org-teams [])
|
||||
out (with-redefs [nitrate/call (nitrate-call-mock org-summary)]
|
||||
(management-command-with-nitrate!
|
||||
{::th/type :get-remove-from-org-summary
|
||||
::rpc/profile-id (:id org-owner)
|
||||
:profile-id (:id user)
|
||||
:organization-id organization-id
|
||||
:default-team-id (:id org-team)}))]
|
||||
(t/is (th/success? out))
|
||||
(t/is (= {:teams-to-delete 0
|
||||
:teams-to-transfer 0
|
||||
:teams-to-exit 0}
|
||||
(:result out)))))
|
||||
|
||||
(t/deftest get-remove-from-org-summary-with-teams-to-delete
|
||||
;; User owns a sole-member extra org team → 1 to delete.
|
||||
(let [org-owner (th/create-profile* 1 {:is-active true})
|
||||
user (th/create-profile* 2 {:is-active true})
|
||||
extra-team (th/create-team* 3 {:profile-id (:id user)})
|
||||
org-team (th/create-team* 99 {:profile-id (:id user)})
|
||||
organization-id (uuid/random)
|
||||
org-summary (make-org-summary
|
||||
:organization-id organization-id
|
||||
:organization-name "Acme Org"
|
||||
:owner-id (:id org-owner)
|
||||
:your-penpot-teams [(:id org-team)]
|
||||
:org-teams [(:id extra-team)])
|
||||
out (with-redefs [nitrate/call (nitrate-call-mock org-summary)]
|
||||
(management-command-with-nitrate!
|
||||
{::th/type :get-remove-from-org-summary
|
||||
::rpc/profile-id (:id org-owner)
|
||||
:profile-id (:id user)
|
||||
:organization-id organization-id
|
||||
:default-team-id (:id org-team)}))]
|
||||
(t/is (th/success? out))
|
||||
(t/is (= {:teams-to-delete 1
|
||||
:teams-to-transfer 0
|
||||
:teams-to-exit 0}
|
||||
(:result out)))))
|
||||
|
||||
(t/deftest get-remove-from-org-summary-with-teams-to-transfer
|
||||
;; User owns a multi-member extra org team → 1 to transfer.
|
||||
(let [org-owner (th/create-profile* 1 {:is-active true})
|
||||
user (th/create-profile* 2 {:is-active true})
|
||||
candidate (th/create-profile* 3 {:is-active true})
|
||||
extra-team (th/create-team* 4 {:profile-id (:id user)})
|
||||
_ (th/create-team-role* {:team-id (:id extra-team)
|
||||
:profile-id (:id candidate)
|
||||
:role :editor})
|
||||
org-team (th/create-team* 99 {:profile-id (:id user)})
|
||||
organization-id (uuid/random)
|
||||
org-summary (make-org-summary
|
||||
:organization-id organization-id
|
||||
:organization-name "Acme Org"
|
||||
:owner-id (:id org-owner)
|
||||
:your-penpot-teams [(:id org-team)]
|
||||
:org-teams [(:id extra-team)])
|
||||
out (with-redefs [nitrate/call (nitrate-call-mock org-summary)]
|
||||
(management-command-with-nitrate!
|
||||
{::th/type :get-remove-from-org-summary
|
||||
::rpc/profile-id (:id org-owner)
|
||||
:profile-id (:id user)
|
||||
:organization-id organization-id
|
||||
:default-team-id (:id org-team)}))]
|
||||
(t/is (th/success? out))
|
||||
(t/is (= {:teams-to-delete 0
|
||||
:teams-to-transfer 1
|
||||
:teams-to-exit 0}
|
||||
(:result out)))))
|
||||
|
||||
(t/deftest get-remove-from-org-summary-with-teams-to-exit
|
||||
;; User is a non-owner member of an org team → 1 to exit.
|
||||
(let [org-owner (th/create-profile* 1 {:is-active true})
|
||||
user (th/create-profile* 2 {:is-active true})
|
||||
extra-team (th/create-team* 5 {:profile-id (:id org-owner)})
|
||||
_ (th/create-team-role* {:team-id (:id extra-team)
|
||||
:profile-id (:id user)
|
||||
:role :editor})
|
||||
org-team (th/create-team* 99 {:profile-id (:id user)})
|
||||
organization-id (uuid/random)
|
||||
org-summary (make-org-summary
|
||||
:organization-id organization-id
|
||||
:organization-name "Acme Org"
|
||||
:owner-id (:id org-owner)
|
||||
:your-penpot-teams [(:id org-team)]
|
||||
:org-teams [(:id extra-team)])
|
||||
out (with-redefs [nitrate/call (nitrate-call-mock org-summary)]
|
||||
(management-command-with-nitrate!
|
||||
{::th/type :get-remove-from-org-summary
|
||||
::rpc/profile-id (:id org-owner)
|
||||
:profile-id (:id user)
|
||||
:organization-id organization-id
|
||||
:default-team-id (:id org-team)}))]
|
||||
(t/is (th/success? out))
|
||||
(t/is (= {:teams-to-delete 0
|
||||
:teams-to-transfer 0
|
||||
:teams-to-exit 1}
|
||||
(:result out)))))
|
||||
|
||||
(t/deftest get-remove-from-org-summary-does-not-mutate
|
||||
;; Calling the summary endpoint must not modify any teams.
|
||||
(let [org-owner (th/create-profile* 1 {:is-active true})
|
||||
user (th/create-profile* 2 {:is-active true})
|
||||
extra-team (th/create-team* 6 {:profile-id (:id user)})
|
||||
org-team (th/create-team* 99 {:profile-id (:id user)})
|
||||
organization-id (uuid/random)
|
||||
org-summary (make-org-summary
|
||||
:organization-id organization-id
|
||||
:organization-name "Acme Org"
|
||||
:owner-id (:id org-owner)
|
||||
:your-penpot-teams [(:id org-team)]
|
||||
:org-teams [(:id extra-team)])
|
||||
_ (with-redefs [nitrate/call (nitrate-call-mock org-summary)]
|
||||
(management-command-with-nitrate!
|
||||
{::th/type :get-remove-from-org-summary
|
||||
::rpc/profile-id (:id org-owner)
|
||||
:profile-id (:id user)
|
||||
:organization-id organization-id
|
||||
:default-team-id (:id org-team)}))]
|
||||
;; Both teams must still exist and be undeleted
|
||||
(let [t1 (th/db-get :team {:id (:id org-team)})]
|
||||
(t/is (some? t1))
|
||||
(t/is (nil? (:deleted-at t1))))
|
||||
(let [t2 (th/db-get :team {:id (:id extra-team)})]
|
||||
(t/is (some? t2))
|
||||
(t/is (nil? (:deleted-at t2))))
|
||||
;; User must still be a member of both teams
|
||||
(let [rel1 (th/db-get :team-profile-rel {:team-id (:id org-team) :profile-id (:id user)})]
|
||||
(t/is (some? rel1)))
|
||||
(let [rel2 (th/db-get :team-profile-rel {:team-id (:id extra-team) :profile-id (:id user)})]
|
||||
(t/is (some? rel2)))))
|
||||
686
backend/test/backend_tests/rpc_nitrate_test.clj
Normal file
686
backend/test/backend_tests/rpc_nitrate_test.clj
Normal file
@ -0,0 +1,686 @@
|
||||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;;
|
||||
;; Copyright (c) KALEIDOS INC
|
||||
|
||||
(ns backend-tests.rpc-nitrate-test
|
||||
(:require
|
||||
[app.common.uuid :as uuid]
|
||||
[app.db :as-alias db]
|
||||
[app.nitrate :as nitrate]
|
||||
[app.rpc :as-alias rpc]
|
||||
[app.rpc.commands.nitrate]
|
||||
[backend-tests.helpers :as th]
|
||||
[clojure.test :as t]
|
||||
[cuerdas.core :as str]))
|
||||
|
||||
(t/use-fixtures :once th/state-init)
|
||||
(t/use-fixtures :each th/database-reset)
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Helpers
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(defn- make-org-summary
|
||||
[& {:keys [organization-id organization-name owner-id your-penpot-teams org-teams]
|
||||
:or {your-penpot-teams [] org-teams []}}]
|
||||
{:id organization-id
|
||||
:name organization-name
|
||||
:owner-id owner-id
|
||||
:teams (into
|
||||
(mapv (fn [id] {:id id :is-your-penpot true}) your-penpot-teams)
|
||||
(mapv (fn [id] {:id id :is-your-penpot false}) org-teams))})
|
||||
|
||||
(defn- nitrate-call-mock
|
||||
"Creates a mock for nitrate/call that returns the given org-summary for
|
||||
:get-org-summary, a valid membership for :get-org-membership, and nil for
|
||||
any other method."
|
||||
[org-summary]
|
||||
(fn [_cfg method _params]
|
||||
(case method
|
||||
:get-org-summary org-summary
|
||||
:get-org-membership {:is-member true
|
||||
:organization-id (:id org-summary)}
|
||||
nil)))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Tests
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(t/deftest leave-org-happy-path-no-extra-teams
|
||||
(let [profile-owner (th/create-profile* 1 {:is-active true})
|
||||
profile-user (th/create-profile* 2 {:is-active true})
|
||||
|
||||
org-default-team (th/create-team* 99 {:profile-id (:id profile-user)})
|
||||
project (th/create-project* 99 {:profile-id (:id profile-user)
|
||||
:team-id (:id org-default-team)})
|
||||
_ (th/create-file* 99 {:profile-id (:id profile-user)
|
||||
:project-id (:id project)})
|
||||
|
||||
organization-id (uuid/random)
|
||||
;; The user's personal penpot team in the org context
|
||||
your-penpot-id (:id org-default-team)
|
||||
|
||||
org-summary (make-org-summary
|
||||
:organization-id organization-id
|
||||
:organization-name "Test Org"
|
||||
:owner-id (:id profile-owner)
|
||||
:your-penpot-teams [your-penpot-id]
|
||||
:org-teams [])]
|
||||
|
||||
(with-redefs [nitrate/call (nitrate-call-mock org-summary)]
|
||||
(let [data {::th/type :leave-org
|
||||
::rpc/profile-id (:id profile-user)
|
||||
:id organization-id
|
||||
:name "Test Org"
|
||||
:default-team-id your-penpot-id
|
||||
:teams-to-delete []
|
||||
:teams-to-leave []}
|
||||
out (th/command! data)]
|
||||
|
||||
;; (th/print-result! out)
|
||||
(t/is (th/success? out))
|
||||
(t/is (nil? (:result out)))
|
||||
|
||||
;; The personal team must be renamed with the org prefix and
|
||||
;; unset as a default team.
|
||||
(let [team (th/db-get :team {:id your-penpot-id})]
|
||||
(t/is (str/starts-with? (:name team) "[Test Org] "))
|
||||
(t/is (false? (:is-default team))))))))
|
||||
|
||||
(t/deftest leave-org-deletes-org-default-team-when-empty
|
||||
(let [profile-owner (th/create-profile* 1 {:is-active true})
|
||||
profile-user (th/create-profile* 2 {:is-active true})
|
||||
org-default-team (th/create-team* 98 {:profile-id (:id profile-user)})
|
||||
|
||||
organization-id (uuid/random)
|
||||
your-penpot-id (:id org-default-team)
|
||||
|
||||
org-summary (make-org-summary
|
||||
:organization-id organization-id
|
||||
:organization-name "Test Org"
|
||||
:owner-id (:id profile-owner)
|
||||
:your-penpot-teams [your-penpot-id]
|
||||
:org-teams [])]
|
||||
|
||||
(with-redefs [nitrate/call (nitrate-call-mock org-summary)]
|
||||
(let [data {::th/type :leave-org
|
||||
::rpc/profile-id (:id profile-user)
|
||||
:id organization-id
|
||||
:name "Test Org"
|
||||
:default-team-id your-penpot-id
|
||||
:teams-to-delete []
|
||||
:teams-to-leave []}
|
||||
out (th/command! data)]
|
||||
|
||||
(t/is (th/success? out))
|
||||
|
||||
;; Empty org default team should be soft-deleted.
|
||||
(let [team (th/db-get :team {:id your-penpot-id} {::db/remove-deleted false})]
|
||||
(t/is (some? (:deleted-at team))))))))
|
||||
|
||||
(t/deftest leave-org-keeps-and-renames-org-default-team-when-has-files
|
||||
(let [profile-owner (th/create-profile* 1 {:is-active true})
|
||||
profile-user (th/create-profile* 2 {:is-active true})
|
||||
org-default-team (th/create-team* 97 {:profile-id (:id profile-user)})
|
||||
project (th/create-project* 97 {:profile-id (:id profile-user)
|
||||
:team-id (:id org-default-team)})
|
||||
_ (th/create-file* 97 {:profile-id (:id profile-user)
|
||||
:project-id (:id project)})
|
||||
|
||||
organization-id (uuid/random)
|
||||
your-penpot-id (:id org-default-team)
|
||||
|
||||
org-summary (make-org-summary
|
||||
:organization-id organization-id
|
||||
:organization-name "Test Org"
|
||||
:owner-id (:id profile-owner)
|
||||
:your-penpot-teams [your-penpot-id]
|
||||
:org-teams [])]
|
||||
|
||||
(with-redefs [nitrate/call (nitrate-call-mock org-summary)]
|
||||
(let [data {::th/type :leave-org
|
||||
::rpc/profile-id (:id profile-user)
|
||||
:id organization-id
|
||||
:name "Test Org"
|
||||
:default-team-id your-penpot-id
|
||||
:teams-to-delete []
|
||||
:teams-to-leave []}
|
||||
out (th/command! data)]
|
||||
|
||||
(t/is (th/success? out))
|
||||
|
||||
;; Non-empty org default team should remain and be renamed.
|
||||
(let [team (th/db-get :team {:id your-penpot-id})]
|
||||
(t/is (str/starts-with? (:name team) "[Test Org] "))
|
||||
(t/is (false? (:is-default team)))
|
||||
(t/is (nil? (:deleted-at team))))))))
|
||||
|
||||
(t/deftest leave-org-with-teams-to-delete
|
||||
(let [profile-owner (th/create-profile* 1 {:is-active true})
|
||||
profile-user (th/create-profile* 2 {:is-active true})
|
||||
;; profile-user is the sole owner/member of team1
|
||||
team1 (th/create-team* 1 {:profile-id (:id profile-user)})
|
||||
org-default-team (th/create-team* 99 {:profile-id (:id profile-user)})
|
||||
|
||||
organization-id (uuid/random)
|
||||
your-penpot-id (:id org-default-team)
|
||||
|
||||
org-summary (make-org-summary
|
||||
:organization-id organization-id
|
||||
:organization-name "Test Org"
|
||||
:owner-id (:id profile-owner)
|
||||
:your-penpot-teams [your-penpot-id]
|
||||
:org-teams [(:id team1)])]
|
||||
|
||||
(with-redefs [nitrate/call (nitrate-call-mock org-summary)]
|
||||
(let [data {::th/type :leave-org
|
||||
::rpc/profile-id (:id profile-user)
|
||||
:id organization-id
|
||||
:name "Test Org"
|
||||
:default-team-id your-penpot-id
|
||||
:teams-to-delete [(:id team1)]
|
||||
:teams-to-leave []}
|
||||
out (th/command! data)]
|
||||
|
||||
;; (th/print-result! out)
|
||||
(t/is (th/success? out))
|
||||
|
||||
;; team1 should be scheduled for deletion (deleted-at set)
|
||||
(let [team (th/db-get :team {:id (:id team1)} {::db/remove-deleted false})]
|
||||
(t/is (some? (:deleted-at team))))))))
|
||||
|
||||
(t/deftest leave-org-with-ownership-transfer
|
||||
(let [profile-owner (th/create-profile* 1 {:is-active true})
|
||||
profile-user (th/create-profile* 2 {:is-active true})
|
||||
;; profile-user owns team1; profile-owner is also a member
|
||||
team1 (th/create-team* 1 {:profile-id (:id profile-user)})
|
||||
_ (th/create-team-role* {:team-id (:id team1)
|
||||
:profile-id (:id profile-owner)
|
||||
:role :editor})
|
||||
org-default-team (th/create-team* 99 {:profile-id (:id profile-user)})
|
||||
|
||||
organization-id (uuid/random)
|
||||
your-penpot-id (:id org-default-team)
|
||||
|
||||
org-summary (make-org-summary
|
||||
:organization-id organization-id
|
||||
:organization-name "Test Org"
|
||||
:owner-id (:id profile-owner)
|
||||
:your-penpot-teams [your-penpot-id]
|
||||
:org-teams [(:id team1)])]
|
||||
|
||||
(with-redefs [nitrate/call (nitrate-call-mock org-summary)]
|
||||
(let [data {::th/type :leave-org
|
||||
::rpc/profile-id (:id profile-user)
|
||||
:id organization-id
|
||||
:name "Test Org"
|
||||
:default-team-id your-penpot-id
|
||||
:teams-to-delete []
|
||||
:teams-to-leave [{:id (:id team1) :reassign-to (:id profile-owner)}]}
|
||||
out (th/command! data)]
|
||||
|
||||
;; (th/print-result! out)
|
||||
(t/is (th/success? out))
|
||||
|
||||
;; profile-user should no longer be a member of team1
|
||||
(let [rel (th/db-get :team-profile-rel
|
||||
{:team-id (:id team1)
|
||||
:profile-id (:id profile-user)})]
|
||||
(t/is (nil? rel)))
|
||||
|
||||
;; profile-owner should have been promoted to owner
|
||||
(let [rel (th/db-get :team-profile-rel
|
||||
{:team-id (:id team1)
|
||||
:profile-id (:id profile-owner)})]
|
||||
(t/is (true? (:is-owner rel))))))))
|
||||
|
||||
(t/deftest leave-org-exit-as-non-owner
|
||||
(let [profile-owner (th/create-profile* 1 {:is-active true})
|
||||
profile-user (th/create-profile* 2 {:is-active true})
|
||||
;; profile-owner owns team1; profile-user is a non-owner member
|
||||
team1 (th/create-team* 1 {:profile-id (:id profile-owner)})
|
||||
_ (th/create-team-role* {:team-id (:id team1)
|
||||
:profile-id (:id profile-user)
|
||||
:role :editor})
|
||||
org-default-team (th/create-team* 99 {:profile-id (:id profile-user)})
|
||||
|
||||
organization-id (uuid/random)
|
||||
your-penpot-id (:id org-default-team)
|
||||
|
||||
org-summary (make-org-summary
|
||||
:organization-id organization-id
|
||||
:organization-name "Test Org"
|
||||
:owner-id (:id profile-owner)
|
||||
:your-penpot-teams [your-penpot-id]
|
||||
:org-teams [(:id team1)])]
|
||||
|
||||
(with-redefs [nitrate/call (nitrate-call-mock org-summary)]
|
||||
(let [data {::th/type :leave-org
|
||||
::rpc/profile-id (:id profile-user)
|
||||
:id organization-id
|
||||
:name "Test Org"
|
||||
:default-team-id your-penpot-id
|
||||
:teams-to-delete []
|
||||
:teams-to-leave [{:id (:id team1)}]}
|
||||
out (th/command! data)]
|
||||
|
||||
;; (th/print-result! out)
|
||||
(t/is (th/success? out))
|
||||
|
||||
;; profile-user should no longer be a member of team1
|
||||
(let [rel (th/db-get :team-profile-rel
|
||||
{:team-id (:id team1)
|
||||
:profile-id (:id profile-user)})]
|
||||
(t/is (nil? rel)))
|
||||
|
||||
;; The team itself should still exist
|
||||
(let [team (th/db-get :team {:id (:id team1)})]
|
||||
(t/is (nil? (:deleted-at team))))))))
|
||||
|
||||
(t/deftest leave-org-error-org-owner-cannot-leave
|
||||
(let [profile-owner (th/create-profile* 1 {:is-active true})
|
||||
org-default-team (th/create-team* 99 {:profile-id (:id profile-owner)})
|
||||
organization-id (uuid/random)
|
||||
your-penpot-id (:id org-default-team)
|
||||
|
||||
;; profile-owner IS the org owner in the org-summary
|
||||
org-summary (make-org-summary
|
||||
:organization-id organization-id
|
||||
:organization-name "Test Org"
|
||||
:owner-id (:id profile-owner)
|
||||
:your-penpot-teams [your-penpot-id]
|
||||
:org-teams [])]
|
||||
|
||||
(with-redefs [nitrate/call (nitrate-call-mock org-summary)]
|
||||
(let [data {::th/type :leave-org
|
||||
::rpc/profile-id (:id profile-owner)
|
||||
:id organization-id
|
||||
:name "Test Org"
|
||||
:default-team-id your-penpot-id
|
||||
:teams-to-delete []
|
||||
:teams-to-leave []}
|
||||
out (th/command! data)]
|
||||
|
||||
(t/is (not (th/success? out)))
|
||||
(t/is (= :validation (th/ex-type (:error out))))
|
||||
(t/is (= :org-owner-cannot-leave (th/ex-code (:error out))))))))
|
||||
|
||||
(t/deftest leave-org-error-invalid-default-team-id
|
||||
(let [profile-owner (th/create-profile* 1 {:is-active true})
|
||||
profile-user (th/create-profile* 2 {:is-active true})
|
||||
org-default-team (th/create-team* 99 {:profile-id (:id profile-user)})
|
||||
organization-id (uuid/random)
|
||||
your-penpot-id (:id org-default-team)
|
||||
|
||||
org-summary (make-org-summary
|
||||
:organization-id organization-id
|
||||
:organization-name "Test Org"
|
||||
:owner-id (:id profile-owner)
|
||||
:your-penpot-teams [your-penpot-id]
|
||||
:org-teams [])]
|
||||
|
||||
(with-redefs [nitrate/call (nitrate-call-mock org-summary)]
|
||||
;; Pass a random UUID that is not in the your-penpot-teams list
|
||||
(let [data {::th/type :leave-org
|
||||
::rpc/profile-id (:id profile-user)
|
||||
:id organization-id
|
||||
:name "Test Org"
|
||||
:default-team-id (uuid/random)
|
||||
:teams-to-delete []
|
||||
:teams-to-leave []}
|
||||
out (th/command! data)]
|
||||
|
||||
(t/is (not (th/success? out)))
|
||||
(t/is (= :validation (th/ex-type (:error out))))
|
||||
(t/is (= :not-valid-teams (th/ex-code (:error out))))))))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Unit Tests for calculate-valid-teams
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(def ^:private calculate-valid-teams
|
||||
(or (ns-resolve 'app.rpc.commands.nitrate 'calculate-valid-teams)
|
||||
(throw (ex-info "Unable to resolve calculate-valid-teams"
|
||||
{:ns 'app.rpc.commands.nitrate
|
||||
:symbol 'calculate-valid-teams}))))
|
||||
|
||||
(defn- make-team [id & {:keys [is-owner num-members member-ids]
|
||||
:or {is-owner false num-members 1 member-ids []}}]
|
||||
{:id id :is-owner is-owner :num-members num-members :member-ids member-ids})
|
||||
|
||||
(t/deftest calculate-valid-teams-no-org-teams
|
||||
(let [default-id (uuid/random)
|
||||
default-team (make-team default-id)
|
||||
result (calculate-valid-teams [default-team] default-id)]
|
||||
(t/is (= default-team (:valid-default-team result)))
|
||||
(t/is (empty? (:valid-teams-to-delete-ids result)))
|
||||
(t/is (empty? (:valid-teams-to-transfer result)))
|
||||
(t/is (empty? (:valid-teams-to-exit result)))))
|
||||
|
||||
(t/deftest calculate-valid-teams-default-not-found
|
||||
(let [default-id (uuid/random)
|
||||
other-id (uuid/random)
|
||||
other-team (make-team other-id)
|
||||
;; default-id is not in org-teams at all
|
||||
result (calculate-valid-teams [other-team] default-id)]
|
||||
(t/is (nil? (:valid-default-team result)))))
|
||||
|
||||
(t/deftest calculate-valid-teams-sole-owner-team
|
||||
(let [default-id (uuid/random)
|
||||
team-id (uuid/random)
|
||||
default (make-team default-id)
|
||||
solo-team (make-team team-id :is-owner true :num-members 1)
|
||||
result (calculate-valid-teams [default solo-team] default-id)]
|
||||
(t/is (contains? (:valid-teams-to-delete-ids result) team-id))
|
||||
(t/is (empty? (:valid-teams-to-transfer result)))
|
||||
(t/is (empty? (:valid-teams-to-exit result)))))
|
||||
|
||||
(t/deftest calculate-valid-teams-owned-multi-member-team
|
||||
(let [default-id (uuid/random)
|
||||
team-id (uuid/random)
|
||||
default (make-team default-id)
|
||||
;; owner of a team with 3 members — must be transferred
|
||||
multi-team (make-team team-id :is-owner true :num-members 3)
|
||||
result (calculate-valid-teams [default multi-team] default-id)]
|
||||
(t/is (empty? (:valid-teams-to-delete-ids result)))
|
||||
(t/is (= [team-id] (map :id (:valid-teams-to-transfer result))))
|
||||
(t/is (empty? (:valid-teams-to-exit result)))))
|
||||
|
||||
(t/deftest calculate-valid-teams-non-owner-multi-member-team
|
||||
(let [default-id (uuid/random)
|
||||
team-id (uuid/random)
|
||||
default (make-team default-id)
|
||||
;; non-owner member of a team with 2 members — can just exit
|
||||
exit-team (make-team team-id :is-owner false :num-members 2)
|
||||
result (calculate-valid-teams [default exit-team] default-id)]
|
||||
(t/is (empty? (:valid-teams-to-delete-ids result)))
|
||||
(t/is (empty? (:valid-teams-to-transfer result)))
|
||||
(t/is (= [team-id] (map :id (:valid-teams-to-exit result))))))
|
||||
|
||||
(t/deftest calculate-valid-teams-mixed
|
||||
(let [default-id (uuid/random)
|
||||
solo-id (uuid/random)
|
||||
transfer-id (uuid/random)
|
||||
exit-id (uuid/random)
|
||||
default (make-team default-id)
|
||||
solo-team (make-team solo-id :is-owner true :num-members 1)
|
||||
transfer-team (make-team transfer-id :is-owner true :num-members 2)
|
||||
exit-team (make-team exit-id :is-owner false :num-members 3)
|
||||
result (calculate-valid-teams [default solo-team transfer-team exit-team] default-id)]
|
||||
(t/is (= #{solo-id} (:valid-teams-to-delete-ids result)))
|
||||
(t/is (= [transfer-id] (map :id (:valid-teams-to-transfer result))))
|
||||
(t/is (= [exit-id] (map :id (:valid-teams-to-exit result))))
|
||||
(t/is (= default-id (:id (:valid-default-team result))))))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Integration: combined delete + leave
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(t/deftest leave-org-combined-delete-and-leave
|
||||
(let [profile-owner (th/create-profile* 1 {:is-active true})
|
||||
profile-user (th/create-profile* 2 {:is-active true})
|
||||
;; team1: profile-user is sole owner — must delete
|
||||
team1 (th/create-team* 1 {:profile-id (:id profile-user)})
|
||||
;; team2: profile-user owns it, profile-owner is also member — must transfer
|
||||
team2 (th/create-team* 2 {:profile-id (:id profile-user)})
|
||||
_ (th/create-team-role* {:team-id (:id team2)
|
||||
:profile-id (:id profile-owner)
|
||||
:role :editor})
|
||||
;; team3: profile-owner owns it, profile-user is non-owner member — can exit
|
||||
team3 (th/create-team* 3 {:profile-id (:id profile-owner)})
|
||||
_ (th/create-team-role* {:team-id (:id team3)
|
||||
:profile-id (:id profile-user)
|
||||
:role :editor})
|
||||
org-default-team (th/create-team* 99 {:profile-id (:id profile-user)})
|
||||
|
||||
organization-id (uuid/random)
|
||||
your-penpot-id (:id org-default-team)
|
||||
|
||||
org-summary (make-org-summary
|
||||
:organization-id organization-id
|
||||
:organization-name "Test Org"
|
||||
:owner-id (:id profile-owner)
|
||||
:your-penpot-teams [your-penpot-id]
|
||||
:org-teams [(:id team1) (:id team2) (:id team3)])]
|
||||
|
||||
(with-redefs [nitrate/call (nitrate-call-mock org-summary)]
|
||||
(let [data {::th/type :leave-org
|
||||
::rpc/profile-id (:id profile-user)
|
||||
:id organization-id
|
||||
:name "Test Org"
|
||||
:default-team-id your-penpot-id
|
||||
:teams-to-delete [(:id team1)]
|
||||
:teams-to-leave [{:id (:id team2) :reassign-to (:id profile-owner)}
|
||||
{:id (:id team3)}]}
|
||||
out (th/command! data)]
|
||||
|
||||
(t/is (th/success? out))
|
||||
|
||||
;; team1 should be soft-deleted
|
||||
(let [team (th/db-get :team {:id (:id team1)} {::db/remove-deleted false})]
|
||||
(t/is (some? (:deleted-at team))))
|
||||
|
||||
;; profile-user should no longer be a member of team2
|
||||
(let [rel (th/db-get :team-profile-rel {:team-id (:id team2) :profile-id (:id profile-user)})]
|
||||
(t/is (nil? rel)))
|
||||
|
||||
;; profile-owner should now own team2
|
||||
(let [rel (th/db-get :team-profile-rel {:team-id (:id team2) :profile-id (:id profile-owner)})]
|
||||
(t/is (true? (:is-owner rel))))
|
||||
|
||||
;; profile-user should no longer be a member of team3
|
||||
(let [rel (th/db-get :team-profile-rel {:team-id (:id team3) :profile-id (:id profile-user)})]
|
||||
(t/is (nil? rel)))
|
||||
|
||||
;; team3 itself should still exist (profile-owner is still there)
|
||||
(let [team (th/db-get :team {:id (:id team3)})]
|
||||
(t/is (some? team)))))))
|
||||
(t/deftest leave-org-error-teams-to-delete-incomplete
|
||||
(let [profile-owner (th/create-profile* 1 {:is-active true})
|
||||
profile-user (th/create-profile* 2 {:is-active true})
|
||||
;; profile-user is the sole owner/member of both team1 and team2
|
||||
team1 (th/create-team* 1 {:profile-id (:id profile-user)})
|
||||
team2 (th/create-team* 2 {:profile-id (:id profile-user)})
|
||||
org-default-team (th/create-team* 99 {:profile-id (:id profile-user)})
|
||||
|
||||
organization-id (uuid/random)
|
||||
your-penpot-id (:id org-default-team)
|
||||
|
||||
org-summary (make-org-summary
|
||||
:organization-id organization-id
|
||||
:organization-name "Test Org"
|
||||
:owner-id (:id profile-owner)
|
||||
:your-penpot-teams [your-penpot-id]
|
||||
:org-teams [(:id team1) (:id team2)])]
|
||||
|
||||
(with-redefs [nitrate/call (nitrate-call-mock org-summary)]
|
||||
;; Only team1 is listed; team2 is also a sole-owner team and must be included
|
||||
(let [data {::th/type :leave-org
|
||||
::rpc/profile-id (:id profile-user)
|
||||
:id organization-id
|
||||
:name "Test Org"
|
||||
:default-team-id your-penpot-id
|
||||
:teams-to-delete [(:id team1)]
|
||||
:teams-to-leave []}
|
||||
out (th/command! data)]
|
||||
|
||||
(t/is (not (th/success? out)))
|
||||
(t/is (= :validation (th/ex-type (:error out))))
|
||||
(t/is (= :not-valid-teams (th/ex-code (:error out))))))))
|
||||
|
||||
(t/deftest leave-org-error-cannot-delete-multi-member-team
|
||||
(let [profile-owner (th/create-profile* 1 {:is-active true})
|
||||
profile-user (th/create-profile* 2 {:is-active true})
|
||||
;; team1 has two members: profile-user (owner) and profile-owner (editor)
|
||||
team1 (th/create-team* 1 {:profile-id (:id profile-user)})
|
||||
_ (th/create-team-role* {:team-id (:id team1)
|
||||
:profile-id (:id profile-owner)
|
||||
:role :editor})
|
||||
org-default-team (th/create-team* 99 {:profile-id (:id profile-user)})
|
||||
|
||||
organization-id (uuid/random)
|
||||
your-penpot-id (:id org-default-team)
|
||||
|
||||
org-summary (make-org-summary
|
||||
:organization-id organization-id
|
||||
:organization-name "Test Org"
|
||||
:owner-id (:id profile-owner)
|
||||
:your-penpot-teams [your-penpot-id]
|
||||
:org-teams [(:id team1)])]
|
||||
|
||||
(with-redefs [nitrate/call (nitrate-call-mock org-summary)]
|
||||
;; team1 has 2 members so it is not a valid deletion candidate
|
||||
(let [data {::th/type :leave-org
|
||||
::rpc/profile-id (:id profile-user)
|
||||
:id organization-id
|
||||
:name "Test Org"
|
||||
:default-team-id your-penpot-id
|
||||
:teams-to-delete [(:id team1)]
|
||||
:teams-to-leave []}
|
||||
out (th/command! data)]
|
||||
|
||||
(t/is (not (th/success? out)))
|
||||
(t/is (= :validation (th/ex-type (:error out))))
|
||||
(t/is (= :not-valid-teams (th/ex-code (:error out))))))))
|
||||
|
||||
(t/deftest leave-org-error-teams-to-leave-incomplete
|
||||
(let [profile-owner (th/create-profile* 1 {:is-active true})
|
||||
profile-user (th/create-profile* 2 {:is-active true})
|
||||
;; profile-user owns team1, which also has profile-owner as editor
|
||||
team1 (th/create-team* 1 {:profile-id (:id profile-user)})
|
||||
_ (th/create-team-role* {:team-id (:id team1)
|
||||
:profile-id (:id profile-owner)
|
||||
:role :editor})
|
||||
org-default-team (th/create-team* 99 {:profile-id (:id profile-user)})
|
||||
|
||||
organization-id (uuid/random)
|
||||
your-penpot-id (:id org-default-team)
|
||||
|
||||
org-summary (make-org-summary
|
||||
:organization-id organization-id
|
||||
:organization-name "Test Org"
|
||||
:owner-id (:id profile-owner)
|
||||
:your-penpot-teams [your-penpot-id]
|
||||
:org-teams [(:id team1)])]
|
||||
|
||||
(with-redefs [nitrate/call (nitrate-call-mock org-summary)]
|
||||
;; team1 must be transferred (owner + multiple members) but is absent
|
||||
(let [data {::th/type :leave-org
|
||||
::rpc/profile-id (:id profile-user)
|
||||
:id organization-id
|
||||
:name "Test Org"
|
||||
:default-team-id your-penpot-id
|
||||
:teams-to-delete []
|
||||
:teams-to-leave []}
|
||||
out (th/command! data)]
|
||||
|
||||
(t/is (not (th/success? out)))
|
||||
(t/is (= :validation (th/ex-type (:error out))))
|
||||
(t/is (= :not-valid-teams (th/ex-code (:error out))))))))
|
||||
|
||||
(t/deftest leave-org-error-reassign-to-self
|
||||
(let [profile-owner (th/create-profile* 1 {:is-active true})
|
||||
profile-user (th/create-profile* 2 {:is-active true})
|
||||
team1 (th/create-team* 1 {:profile-id (:id profile-user)})
|
||||
_ (th/create-team-role* {:team-id (:id team1)
|
||||
:profile-id (:id profile-owner)
|
||||
:role :editor})
|
||||
org-default-team (th/create-team* 99 {:profile-id (:id profile-user)})
|
||||
|
||||
organization-id (uuid/random)
|
||||
your-penpot-id (:id org-default-team)
|
||||
|
||||
org-summary (make-org-summary
|
||||
:organization-id organization-id
|
||||
:organization-name "Test Org"
|
||||
:owner-id (:id profile-owner)
|
||||
:your-penpot-teams [your-penpot-id]
|
||||
:org-teams [(:id team1)])]
|
||||
|
||||
(with-redefs [nitrate/call (nitrate-call-mock org-summary)]
|
||||
;; reassign-to points to the profile that is leaving — not allowed
|
||||
(let [data {::th/type :leave-org
|
||||
::rpc/profile-id (:id profile-user)
|
||||
:id organization-id
|
||||
:name "Test Org"
|
||||
:default-team-id your-penpot-id
|
||||
:teams-to-delete []
|
||||
:teams-to-leave [{:id (:id team1) :reassign-to (:id profile-user)}]}
|
||||
out (th/command! data)]
|
||||
|
||||
(t/is (not (th/success? out)))
|
||||
(t/is (= :validation (th/ex-type (:error out))))
|
||||
(t/is (= :not-valid-teams (th/ex-code (:error out))))))))
|
||||
|
||||
(t/deftest leave-org-error-reassign-to-non-member
|
||||
(let [profile-owner (th/create-profile* 1 {:is-active true})
|
||||
profile-user (th/create-profile* 2 {:is-active true})
|
||||
profile-other (th/create-profile* 3 {:is-active true})
|
||||
;; team1 has profile-user (owner) and profile-owner (editor) — NOT profile-other
|
||||
team1 (th/create-team* 1 {:profile-id (:id profile-user)})
|
||||
_ (th/create-team-role* {:team-id (:id team1)
|
||||
:profile-id (:id profile-owner)
|
||||
:role :editor})
|
||||
org-default-team (th/create-team* 99 {:profile-id (:id profile-user)})
|
||||
|
||||
organization-id (uuid/random)
|
||||
your-penpot-id (:id org-default-team)
|
||||
|
||||
org-summary (make-org-summary
|
||||
:organization-id organization-id
|
||||
:organization-name "Test Org"
|
||||
:owner-id (:id profile-owner)
|
||||
:your-penpot-teams [your-penpot-id]
|
||||
:org-teams [(:id team1)])]
|
||||
|
||||
(with-redefs [nitrate/call (nitrate-call-mock org-summary)]
|
||||
;; profile-other is not a member of team1
|
||||
(let [data {::th/type :leave-org
|
||||
::rpc/profile-id (:id profile-user)
|
||||
:id organization-id
|
||||
:name "Test Org"
|
||||
:default-team-id your-penpot-id
|
||||
:teams-to-delete []
|
||||
:teams-to-leave [{:id (:id team1) :reassign-to (:id profile-other)}]}
|
||||
out (th/command! data)]
|
||||
|
||||
(t/is (not (th/success? out)))
|
||||
(t/is (= :validation (th/ex-type (:error out))))
|
||||
(t/is (= :not-valid-teams (th/ex-code (:error out))))))))
|
||||
|
||||
(t/deftest leave-org-error-reassign-on-non-owned-team
|
||||
(let [profile-owner (th/create-profile* 1 {:is-active true})
|
||||
profile-user (th/create-profile* 2 {:is-active true})
|
||||
;; profile-owner owns team1; profile-user is just a non-owner member
|
||||
team1 (th/create-team* 1 {:profile-id (:id profile-owner)})
|
||||
_ (th/create-team-role* {:team-id (:id team1)
|
||||
:profile-id (:id profile-user)
|
||||
:role :editor})
|
||||
org-default-team (th/create-team* 99 {:profile-id (:id profile-user)})
|
||||
|
||||
organization-id (uuid/random)
|
||||
your-penpot-id (:id org-default-team)
|
||||
|
||||
org-summary (make-org-summary
|
||||
:organization-id organization-id
|
||||
:organization-name "Test Org"
|
||||
:owner-id (:id profile-owner)
|
||||
:your-penpot-teams [your-penpot-id]
|
||||
:org-teams [(:id team1)])]
|
||||
|
||||
(with-redefs [nitrate/call (nitrate-call-mock org-summary)]
|
||||
;; profile-user is not the owner so providing reassign-to is invalid
|
||||
(let [data {::th/type :leave-org
|
||||
::rpc/profile-id (:id profile-user)
|
||||
:id organization-id
|
||||
:name "Test Org"
|
||||
:default-team-id your-penpot-id
|
||||
:teams-to-delete []
|
||||
:teams-to-leave [{:id (:id team1) :reassign-to (:id profile-owner)}]}
|
||||
out (th/command! data)]
|
||||
|
||||
(t/is (not (th/success? out)))
|
||||
(t/is (= :validation (th/ex-type (:error out))))
|
||||
(t/is (= :not-valid-teams (th/ex-code (:error out))))))))
|
||||
@ -125,7 +125,20 @@
|
||||
out (th/command! data)]
|
||||
|
||||
;; (th/print-result! out)
|
||||
(t/is (nil? (:error out)))))))
|
||||
(t/is (nil? (:error out)))))
|
||||
|
||||
(t/testing "delete photo clears photo-id"
|
||||
(let [data {::th/type :delete-profile-photo
|
||||
::rpc/profile-id (:id profile)}
|
||||
out (th/command! data)]
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (nil? (:result out))))
|
||||
|
||||
(let [data {::th/type :get-profile
|
||||
::rpc/profile-id (:id profile)}
|
||||
out (th/command! data)]
|
||||
(t/is (nil? (:error out)))
|
||||
(t/is (nil? (:photo-id (:result out))))))))
|
||||
|
||||
(t/deftest profile-deletion-1
|
||||
(let [prof (th/create-profile* 1)
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
[app.common.uuid :as uuid]
|
||||
[app.db :as db]
|
||||
[app.rpc :as-alias rpc]
|
||||
[app.rpc.commands.viewer :as viewer]
|
||||
[backend-tests.helpers :as th]
|
||||
[clojure.test :as t]
|
||||
[datoteka.fs :as fs]))
|
||||
@ -16,6 +17,28 @@
|
||||
(t/use-fixtures :once th/state-init)
|
||||
(t/use-fixtures :each th/database-reset)
|
||||
|
||||
(t/deftest obfuscate-email-happy-path
|
||||
(t/is (= "a****@****.com" (viewer/obfuscate-email "alice@example.com")))
|
||||
(t/is (= "a****@****.example.com" (viewer/obfuscate-email "alice@sub.example.com")))
|
||||
(t/is (= "****@****.com" (viewer/obfuscate-email "bob@bar.com"))))
|
||||
|
||||
(t/deftest obfuscate-email-handles-domain-without-dot
|
||||
;; `localhost`-style domains have no `.`; the previous implementation produced
|
||||
;; a dangling-dot output like "a****@****." — now the trailing `.` is only
|
||||
;; emitted when there actually is a TLD segment to append.
|
||||
(t/is (= "a****@****" (viewer/obfuscate-email "alice@localhost")))
|
||||
(t/is (= "****@****" (viewer/obfuscate-email "x@y"))))
|
||||
|
||||
(t/deftest obfuscate-email-handles-malformed-input
|
||||
;; These shapes must not throw — `obfuscate-email` runs while building the
|
||||
;; view-only bundle for share-link viewers and an NPE here aborts the whole
|
||||
;; RPC response. The previous implementation called `clojure.string/split`
|
||||
;; on `nil` for the `no-@` case, raising NullPointerException.
|
||||
(t/is (= "****@****" (viewer/obfuscate-email nil)))
|
||||
(t/is (= "****@****" (viewer/obfuscate-email "")))
|
||||
(t/is (= "r***@****" (viewer/obfuscate-email "root"))) ; no `@`, count > 3
|
||||
(t/is (= "****@****" (viewer/obfuscate-email "bob")))) ; no `@`, count <= 3
|
||||
|
||||
(t/deftest retrieve-bundle
|
||||
(let [prof (th/create-profile* 1 {:is-active true})
|
||||
prof2 (th/create-profile* 2 {:is-active true})
|
||||
|
||||
@ -1120,6 +1120,71 @@
|
||||
(when (num? value)
|
||||
(format-precision value precision)))))
|
||||
|
||||
(defn- natural-sort-key
|
||||
"Splits a string into a sequence of alternating string and number segments,
|
||||
converting numeric segments to longs/ints so they compare by value rather
|
||||
than lexicographically. e.g. \"size10b\" => (\"size\" 10 \"b\")"
|
||||
[s]
|
||||
(map (fn [part]
|
||||
(if (re-matches #"\d+" part)
|
||||
#?(:clj (Long/parseLong part)
|
||||
:cljs (js/parseInt part))
|
||||
part))
|
||||
(re-seq #"\d+|\D+" s)))
|
||||
|
||||
(defn- natural-compare
|
||||
"Comparator that orders strings naturally, sorting numeric segments by value
|
||||
rather than lexicographically. Returns a negative number, zero, or positive
|
||||
number when a is before, equal to, or after b respectively.
|
||||
e.g. \"size2\" < \"size10\" instead of \"size10\" < \"size2\"."
|
||||
[a b]
|
||||
(loop [ka (natural-sort-key a)
|
||||
kb (natural-sort-key b)]
|
||||
(cond
|
||||
(and (empty? ka) (empty? kb)) 0
|
||||
(empty? ka) -1
|
||||
(empty? kb) 1
|
||||
:else
|
||||
(let [pa (first ka)
|
||||
pb (first kb)
|
||||
result (cond
|
||||
(and (number? pa) (number? pb)) (compare pa pb)
|
||||
(and (string? pa) (string? pb)) (compare pa pb)
|
||||
(number? pa) -1
|
||||
:else 1)]
|
||||
(if (zero? result)
|
||||
(recur (rest ka) (rest kb))
|
||||
result)))))
|
||||
|
||||
(defn natural-sort-by
|
||||
"Sorts coll by extracting a string key with keyfn and ordering elements
|
||||
using natural sort order, where embedded numbers are compared by value
|
||||
rather than lexicographically.
|
||||
e.g. (natural-sort-by :name [{:name \"size10\"} {:name \"size2\"}])
|
||||
=> [{:name \"size2\"} {:name \"size10\"}]"
|
||||
[key coll]
|
||||
(sort-by key natural-compare coll))
|
||||
|
||||
(defn sanitize-string [s]
|
||||
(if s
|
||||
(-> s
|
||||
str
|
||||
str/trim
|
||||
(str/replace #"[^\w\s\-_()]+" "")
|
||||
(str/replace #"\s+" " ")
|
||||
str/trim)
|
||||
""))
|
||||
|
||||
(defn get-initials
|
||||
"Returns up to two uppercase initials extracted from a string.
|
||||
Non-letter prefixes in each token are ignored."
|
||||
[name]
|
||||
(->> (str/split (str/trim (or name "")) #"\s+")
|
||||
(keep #(first (re-seq #"[a-zA-Z]" %)))
|
||||
(take 2)
|
||||
(map str/upper)
|
||||
(apply str)))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Util protocols
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
@ -68,6 +68,7 @@
|
||||
"components/v2"
|
||||
"plugins/runtime"
|
||||
"design-tokens/v1"
|
||||
"tokens/numeric-input"
|
||||
"variants/v1"})
|
||||
|
||||
;; A set of features which only affects on frontend and can be enabled
|
||||
|
||||
@ -261,7 +261,11 @@
|
||||
;; All props are optional, background can be nil because is the
|
||||
;; way to remove already set background
|
||||
[:background {:optional true} [:maybe ctc/schema:hex-color]]
|
||||
[:name {:optional true} :string]]]
|
||||
[:name {:optional true} :string]
|
||||
;; Pixel grid display controls — nil removes the per-page override
|
||||
;; and falls back to the default hardcoded grid color/opacity.
|
||||
[:pixel-grid-color {:optional true} [:maybe ctc/schema:hex-color]]
|
||||
[:pixel-grid-opacity {:optional true} [:maybe ::sm/safe-number]]]]
|
||||
|
||||
[:set-plugin-data schema:set-plugin-data-change]
|
||||
|
||||
@ -853,8 +857,10 @@
|
||||
[data {:keys [id] :as params}]
|
||||
(d/update-in-when data [:pages-index id]
|
||||
(fn [page]
|
||||
(let [name (get params :name)
|
||||
bg (get params :background :not-found)]
|
||||
(let [name (get params :name)
|
||||
bg (get params :background :not-found)
|
||||
grid-color (get params :pixel-grid-color :not-found)
|
||||
grid-op (get params :pixel-grid-opacity :not-found)]
|
||||
(cond-> page
|
||||
(string? name)
|
||||
(assoc :name name)
|
||||
@ -863,7 +869,19 @@
|
||||
(assoc :background bg)
|
||||
|
||||
(nil? bg)
|
||||
(dissoc :background))))))
|
||||
(dissoc :background)
|
||||
|
||||
(string? grid-color)
|
||||
(assoc :pixel-grid-color grid-color)
|
||||
|
||||
(and (not= grid-color :not-found) (nil? grid-color))
|
||||
(dissoc :pixel-grid-color)
|
||||
|
||||
(number? grid-op)
|
||||
(assoc :pixel-grid-opacity grid-op)
|
||||
|
||||
(and (not= grid-op :not-found) (nil? grid-op))
|
||||
(dissoc :pixel-grid-opacity))))))
|
||||
|
||||
(defmethod process-change :set-plugin-data
|
||||
[data {:keys [object-type object-id page-id namespace key value]}]
|
||||
|
||||
@ -219,21 +219,33 @@
|
||||
(let [page (::page (meta changes))]
|
||||
(mod-page changes page options)))
|
||||
|
||||
([changes page {:keys [name background]}]
|
||||
([changes page {:keys [name background pixel-grid-color pixel-grid-opacity]}]
|
||||
(let [change {:type :mod-page :id (:id page)}
|
||||
redo (cond-> change
|
||||
(some? name)
|
||||
(assoc :name name)
|
||||
|
||||
(some? background)
|
||||
(assoc :background background))
|
||||
(assoc :background background)
|
||||
|
||||
(some? pixel-grid-color)
|
||||
(assoc :pixel-grid-color pixel-grid-color)
|
||||
|
||||
(some? pixel-grid-opacity)
|
||||
(assoc :pixel-grid-opacity pixel-grid-opacity))
|
||||
|
||||
undo (cond-> change
|
||||
(some? name)
|
||||
(assoc :name (:name page))
|
||||
|
||||
(some? background)
|
||||
(assoc :background (:background page)))]
|
||||
(assoc :background (:background page))
|
||||
|
||||
(some? pixel-grid-color)
|
||||
(assoc :pixel-grid-color (:pixel-grid-color page))
|
||||
|
||||
(some? pixel-grid-opacity)
|
||||
(assoc :pixel-grid-opacity (:pixel-grid-opacity page)))]
|
||||
|
||||
(-> changes
|
||||
(update :redo-changes conj redo)
|
||||
|
||||
115
common/src/app/common/files/comp_processors.cljc
Normal file
115
common/src/app/common/files/comp_processors.cljc
Normal file
@ -0,0 +1,115 @@
|
||||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;;
|
||||
;; Copyright (c) KALEIDOS INC
|
||||
|
||||
(ns app.common.files.comp-processors
|
||||
"Repair, migration or transformation utilities for components."
|
||||
(:require
|
||||
[app.common.logging :as log]
|
||||
[app.common.types.component :as ctk]
|
||||
[app.common.types.file :as ctf]))
|
||||
|
||||
(log/set-level! :warn)
|
||||
|
||||
(defn remove-unneeded-objects-in-components
|
||||
"Some components have an :objects attribute, despite not being deleted. This removes it.
|
||||
It also adds an empty :objects if it's deleted and does not have it."
|
||||
[file-data]
|
||||
(ctf/update-components
|
||||
file-data
|
||||
(fn [component]
|
||||
(if (:deleted component)
|
||||
(if (nil? (:objects component))
|
||||
(do
|
||||
(log/warn :msg "Adding empty :objects to deleted component"
|
||||
:component-id (:id component)
|
||||
:component-name (:name component)
|
||||
:file-id (:id file-data))
|
||||
(assoc component :objects {}))
|
||||
component)
|
||||
(if (contains? component :objects)
|
||||
(do
|
||||
(log/warn :msg "Removing :objects from non-deleted component"
|
||||
:component-id (:id component)
|
||||
:component-name (:name component)
|
||||
:file-id (:id file-data))
|
||||
(dissoc component :objects))
|
||||
component)))))
|
||||
|
||||
(defn fix-missing-swap-slots
|
||||
"Locate shapes that have been swapped (i.e. their shape-ref does not point to the near match) but
|
||||
they don't have a swap slot. In this case, add one pointing to the near match."
|
||||
[file-data libraries]
|
||||
(ctf/update-all-shapes
|
||||
file-data
|
||||
(fn [shape]
|
||||
(if (ctk/subcopy-head? shape)
|
||||
(let [container (:container (meta shape))
|
||||
file {:id (:id file-data) :data file-data}
|
||||
near-match (ctf/find-near-match file container libraries shape :include-deleted? true :with-context? false)]
|
||||
(if (and (some? near-match)
|
||||
(not= (:shape-ref shape) (:id near-match))
|
||||
(nil? (ctk/get-swap-slot shape)))
|
||||
(let [updated-shape (ctk/set-swap-slot shape (:id near-match))]
|
||||
(log/warn :msg "Adding missing swap slot to shape"
|
||||
:shape-id (:id shape)
|
||||
:shape-name (:name shape)
|
||||
:swap-slot (:id near-match)
|
||||
:file-id (:id file)
|
||||
:container-id (:id container)
|
||||
:container-type (:type container))
|
||||
{:result :update :updated-shape updated-shape})
|
||||
{:result :keep}))
|
||||
{:result :keep}))))
|
||||
|
||||
(defn sync-component-id-with-ref-shape
|
||||
"Ensure that all copies heads have the same component id and file as the referenced shape.
|
||||
There may be bugs that cause them to get out of sync."
|
||||
[file-data libraries]
|
||||
(letfn [(sync-one-iteration
|
||||
[file-data libraries]
|
||||
(ctf/update-all-shapes
|
||||
file-data
|
||||
(fn [shape]
|
||||
(if (and (ctk/subcopy-head? shape) (nil? (ctk/get-swap-slot shape)))
|
||||
(let [container (:container (meta shape))
|
||||
file {:id (:id file-data) :data file-data}
|
||||
ref-shape (ctf/find-ref-shape file container libraries shape {:include-deleted? true :with-context? true})]
|
||||
(if (and (some? ref-shape)
|
||||
(or (not= (:component-id shape) (:component-id ref-shape))
|
||||
(not= (:component-file shape) (:component-file ref-shape))))
|
||||
(let [shape' (cond-> shape
|
||||
(some? (:component-id ref-shape))
|
||||
(assoc :component-id (:component-id ref-shape))
|
||||
|
||||
(nil? (:component-id ref-shape))
|
||||
(dissoc :component-id)
|
||||
|
||||
(some? (:component-file ref-shape))
|
||||
(assoc :component-file (:component-file ref-shape))
|
||||
|
||||
(nil? (:component-file ref-shape))
|
||||
(dissoc :component-file))]
|
||||
(log/warn :msg "Syncing component id and file with ref shape"
|
||||
:shape-id (:id shape)
|
||||
:shape-name (:name shape)
|
||||
:component-id (:component-id shape')
|
||||
:component-file (:component-file shape')
|
||||
:ref-shape-id (:id ref-shape)
|
||||
:file-id (:id file)
|
||||
:container-id (:id container)
|
||||
:container-type (:type container))
|
||||
{:result :update :updated-shape shape'})
|
||||
{:result :keep}))
|
||||
{:result :keep}))))]
|
||||
;; If a copy inside a main is updated, we need to repeat the process for the change to be
|
||||
;; propagated to all copies.
|
||||
(loop [current-data file-data
|
||||
iteration 0]
|
||||
(let [next-data (sync-one-iteration current-data libraries)]
|
||||
(if (or (= current-data next-data)
|
||||
(> iteration 20)) ;; safety bound
|
||||
next-data
|
||||
(recur next-data (inc iteration)))))))
|
||||
@ -10,6 +10,7 @@
|
||||
[app.common.data.macros :as dm]
|
||||
[app.common.features :as cfeat]
|
||||
[app.common.files.changes :as cpc]
|
||||
[app.common.files.comp-processors :as cfcp]
|
||||
[app.common.files.defaults :as cfd]
|
||||
[app.common.files.helpers :as cfh]
|
||||
[app.common.geom.matrix :as gmt]
|
||||
@ -1786,6 +1787,24 @@
|
||||
(update :pages-index d/update-vals update-container)
|
||||
(d/update-when :components d/update-vals update-container))))
|
||||
|
||||
(defmethod migrate-data "0018-remove-unneeded-objects-from-components"
|
||||
[data _]
|
||||
(cfcp/remove-unneeded-objects-in-components data))
|
||||
|
||||
(defmethod migrate-data "0019-fix-missing-swap-slots"
|
||||
[data _]
|
||||
(let [libraries (if (:libs data)
|
||||
(deref (:libs data))
|
||||
{})]
|
||||
(cfcp/fix-missing-swap-slots data libraries)))
|
||||
|
||||
(defmethod migrate-data "0020-sync-component-id-with-near-main"
|
||||
[data _]
|
||||
(let [libraries (if (:libs data)
|
||||
(deref (:libs data))
|
||||
{})]
|
||||
(cfcp/sync-component-id-with-ref-shape data libraries)))
|
||||
|
||||
(def available-migrations
|
||||
(into (d/ordered-set)
|
||||
["legacy-2"
|
||||
@ -1860,4 +1879,7 @@
|
||||
"0015-fix-text-attrs-blank-strings"
|
||||
"0015-clean-shadow-color"
|
||||
"0016-copy-fills-from-position-data-to-text-node"
|
||||
"0017-fix-layout-flex-dir"]))
|
||||
"0017-fix-layout-flex-dir"
|
||||
"0018-remove-unneeded-objects-from-components"
|
||||
"0019-fix-missing-swap-slots"
|
||||
"0020-sync-component-id-with-near-main"]))
|
||||
|
||||
@ -334,6 +334,31 @@
|
||||
(pcb/with-file-data file-data)
|
||||
(pcb/update-shapes [(:id shape)] repair-shape))))
|
||||
|
||||
(defmethod repair-error :component-id-mismatch
|
||||
[_ {:keys [shape page-id args] :as error} file-data _]
|
||||
(let [repair-shape
|
||||
(fn [shape]
|
||||
; Set the component-id and component-file to the ones of the near main
|
||||
(log/debug :hint (str " -> set component-id to " (:component-id args)))
|
||||
(log/debug :hint (str " -> set component-file to " (:component-file args)))
|
||||
(cond-> shape
|
||||
(some? (:component-id args))
|
||||
(assoc :component-id (:component-id args))
|
||||
|
||||
(nil? (:component-id args))
|
||||
(dissoc :component-id)
|
||||
|
||||
(some? (:component-file args))
|
||||
(assoc :component-file (:component-file args))
|
||||
|
||||
(nil? (:component-file args))
|
||||
(dissoc :component-file)))]
|
||||
|
||||
(log/dbg :hint "repairing shape :component-id-mismatch" :id (:id shape) :name (:name shape) :page-id page-id)
|
||||
(-> (pcb/empty-changes nil page-id)
|
||||
(pcb/with-file-data file-data)
|
||||
(pcb/update-shapes [(:id shape)] repair-shape))))
|
||||
|
||||
(defmethod repair-error :ref-shape-is-head
|
||||
[_ {:keys [shape page-id args] :as error} file-data _]
|
||||
(let [repair-shape
|
||||
@ -501,7 +526,7 @@
|
||||
(pcb/update-shapes [(:id shape)] repair-shape))))
|
||||
|
||||
(defmethod repair-error :component-nil-objects-not-allowed
|
||||
[_ {:keys [shape] :as error} file-data _]
|
||||
[_ {component :shape} file-data _] ; in this error the :shape argument is the component
|
||||
(let [repair-component
|
||||
(fn [component]
|
||||
;; Remove the objects key, or set it to {} if the component is deleted
|
||||
@ -513,10 +538,26 @@
|
||||
(log/debug :hint " -> remove :objects")
|
||||
(dissoc component :objects))))]
|
||||
|
||||
(log/dbg :hint "repairing component :component-nil-objects-not-allowed" :id (:id shape) :name (:name shape))
|
||||
(log/dbg :hint "repairing component :component-nil-objects-not-allowed" :id (:id component) :name (:name component))
|
||||
(-> (pcb/empty-changes nil)
|
||||
(pcb/with-library-data file-data)
|
||||
(pcb/update-component (:id shape) repair-component))))
|
||||
(pcb/update-component (:id component) repair-component))))
|
||||
|
||||
(defmethod repair-error :non-deleted-component-cannot-have-objects
|
||||
[_ {component :shape} file-data _] ; in this error the :shape argument is the component
|
||||
(let [repair-component
|
||||
(fn [component]
|
||||
; Remove the :objects field
|
||||
(if-not (:deleted component)
|
||||
(do
|
||||
(log/debug :hint " -> remove :objects")
|
||||
(dissoc component :objects))
|
||||
component))]
|
||||
|
||||
(log/dbg :hint "repairing component :non-deleted-component-cannot-have-objects" :id (:id component) :name (:name component))
|
||||
(-> (pcb/empty-changes nil)
|
||||
(pcb/with-library-data file-data)
|
||||
(pcb/update-component (:id component) repair-component))))
|
||||
|
||||
(defmethod repair-error :invalid-text-touched
|
||||
[_ {:keys [shape page-id] :as error} file-data _]
|
||||
|
||||
@ -340,12 +340,26 @@
|
||||
:svg-viewbox vbox
|
||||
:svg-defs defs})))
|
||||
|
||||
(defn- stroke-only-svg-path?
|
||||
"Returns true when the SVG element renders only a stroke (fill=none).
|
||||
Stroke-only paths can have their consecutive touching subpaths safely
|
||||
merged into a continuous polyline so that `stroke-linejoin` applies at
|
||||
shared endpoints, without affecting any fill-rule semantics."
|
||||
[attrs]
|
||||
(let [attr-fill (some-> (:fill attrs) str/trim)
|
||||
style-fill (some-> (get-in attrs [:style :fill]) str/trim)]
|
||||
(= "none" (or attr-fill style-fill))))
|
||||
|
||||
(defn create-path-shape [name frame-id svg-data {:keys [attrs] :as data}]
|
||||
(when (and (contains? attrs :d) (seq (:d attrs)))
|
||||
(let [transform (csvg/parse-transform (:transform attrs))
|
||||
content (cond-> (path/from-string (:d attrs))
|
||||
(some? transform)
|
||||
(path.segm/transform-content transform))
|
||||
(let [transform (csvg/parse-transform (:transform attrs))
|
||||
stroke-only? (stroke-only-svg-path? attrs)
|
||||
content (cond-> (path/from-string (:d attrs))
|
||||
stroke-only?
|
||||
(path/merge-touching-subpaths)
|
||||
|
||||
(some? transform)
|
||||
(path.segm/transform-content transform))
|
||||
|
||||
selrect (path.segm/content->selrect content)
|
||||
points (grc/rect->points selrect)
|
||||
@ -663,6 +677,22 @@
|
||||
(remove is-style-fragment?) ;; Filter style fragments and hex colors
|
||||
(filter #(contains? defs %))))) ;; Only existing defs
|
||||
|
||||
(defn resolve-element-name
|
||||
"Pick the most user-meaningful name for an SVG element.
|
||||
|
||||
Inkscape (and editors following the same convention) write the
|
||||
operator-given label to ``inkscape:label``/``sodipodi:label`` while
|
||||
``id`` holds an auto-generated technical id like ``path1234``.
|
||||
Preferring the namespaced label keeps the layer/group/element names
|
||||
the operator sees in their source editor across a paste/import
|
||||
(#7869); the existing ``id`` and ``(tag->name tag)`` fallbacks keep
|
||||
legacy SVGs that don't carry a label working unchanged."
|
||||
[tag attrs]
|
||||
(or (:inkscape:label attrs)
|
||||
(:sodipodi:label attrs)
|
||||
(:id attrs)
|
||||
(tag->name tag)))
|
||||
|
||||
(defn parse-svg-element
|
||||
[frame-id svg-data {:keys [tag attrs hidden] :as element} unames]
|
||||
|
||||
@ -670,7 +700,7 @@
|
||||
;; think we should handle this case early and avoid some code
|
||||
;; execution
|
||||
|
||||
(let [name (or (:id attrs) (tag->name tag))
|
||||
(let [name (resolve-element-name tag attrs)
|
||||
att-refs (csvg/find-attr-references attrs)
|
||||
defs (get svg-data :defs)
|
||||
valid-refs (filter-valid-def-references att-refs defs)
|
||||
|
||||
74
common/src/app/common/files/stats.cljc
Normal file
74
common/src/app/common/files/stats.cljc
Normal file
@ -0,0 +1,74 @@
|
||||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;;
|
||||
;; Copyright (c) KALEIDOS INC
|
||||
|
||||
(ns app.common.files.stats
|
||||
"Pure helpers that compute aggregate statistics for a file data map.
|
||||
|
||||
Given a decoded file data structure (the value stored under `:data`
|
||||
on a file row), produces a small map with page/shape/library counts.
|
||||
Intended to be cheap — a single pass over each page's `:objects`
|
||||
map, no database access, no side effects."
|
||||
(:require
|
||||
[app.common.uuid :as uuid]))
|
||||
|
||||
(def empty-shape-counts
|
||||
{:total 0 :by-type {}})
|
||||
|
||||
(defn- inc-type
|
||||
[by-type shape-type]
|
||||
(if (nil? shape-type)
|
||||
by-type
|
||||
(update by-type shape-type (fnil inc 0))))
|
||||
|
||||
(defn count-shapes-by-type
|
||||
"Walk an `:objects` map of a single page and return
|
||||
`{:total N :by-type {:rect N :frame N ...}}`. The synthetic root
|
||||
shape at `uuid/zero` is skipped so it never contributes to totals."
|
||||
[objects]
|
||||
(if (empty? objects)
|
||||
empty-shape-counts
|
||||
(reduce-kv
|
||||
(fn [acc id shape]
|
||||
(if (= id uuid/zero)
|
||||
acc
|
||||
(-> acc
|
||||
(update :total inc)
|
||||
(update :by-type inc-type (:type shape)))))
|
||||
empty-shape-counts
|
||||
objects)))
|
||||
|
||||
(defn- merge-shape-counts
|
||||
[a b]
|
||||
{:total (+ (:total a) (:total b))
|
||||
:by-type (merge-with + (:by-type a) (:by-type b))})
|
||||
|
||||
(defn- aggregate-shape-counts
|
||||
[pages-index]
|
||||
(transduce
|
||||
(map (comp count-shapes-by-type :objects))
|
||||
(completing merge-shape-counts)
|
||||
empty-shape-counts
|
||||
(vals pages-index)))
|
||||
|
||||
(defn calc-file-stats
|
||||
"Given a decoded file data map with the standard keys
|
||||
`:pages-index`, `:components`, `:deleted-components`, `:colors`
|
||||
and `:typographies`, return per-file aggregates.
|
||||
|
||||
The result is a plain map suitable for serialization; it never
|
||||
contains any pointer-map or objects-map instances."
|
||||
[fdata]
|
||||
(let [pages-index (get fdata :pages-index)
|
||||
components (get fdata :components)
|
||||
deleted-components (get fdata :deleted-components)
|
||||
colors (get fdata :colors)
|
||||
typographies (get fdata :typographies)]
|
||||
{:page-count (count pages-index)
|
||||
:shape-counts (aggregate-shape-counts pages-index)
|
||||
:component-count (count components)
|
||||
:deleted-component-count (count deleted-components)
|
||||
:color-count (count colors)
|
||||
:typography-count (count typographies)}))
|
||||
@ -26,7 +26,7 @@
|
||||
[{:keys [value]}]
|
||||
(when (or (str/empty? value)
|
||||
(str/blank? value))
|
||||
(tr "workspace.tokens.empty-input")))
|
||||
(tr "errors.tokens.empty-input")))
|
||||
|
||||
(def schema:token-value-generic
|
||||
[::sm/text {:error/fn token-value-empty-fn}])
|
||||
@ -34,7 +34,7 @@
|
||||
(def schema:token-value-numeric
|
||||
[:and
|
||||
[::sm/text {:error/fn token-value-empty-fn}]
|
||||
[:fn {:error/fn #(tr "workspace.tokens.invalid-value" (:value %))}
|
||||
[:fn {:error/fn #(tr "errors.tokens.invalid-value" (:value %))}
|
||||
(fn [value]
|
||||
(if (str/numeric? value)
|
||||
(let [n (d/parse-double value)]
|
||||
@ -44,7 +44,7 @@
|
||||
(def schema:token-value-percent
|
||||
[:and
|
||||
[::sm/text {:error/fn token-value-empty-fn}]
|
||||
[:fn {:error/fn #(tr "workspace.tokens.value-with-percent" (:value %))}
|
||||
[:fn {:error/fn #(tr "errors.tokens.value-with-percent" (:value %))}
|
||||
(fn [value]
|
||||
(if (d/percent? value)
|
||||
(let [v (d/parse-percent value)]
|
||||
@ -57,7 +57,7 @@
|
||||
(def schema:token-value-opacity
|
||||
[:and
|
||||
[::sm/text {:error/fn token-value-empty-fn}]
|
||||
[:fn {:error/fn #(tr "workspace.tokens.opacity-range")}
|
||||
[:fn {:error/fn #(tr "errors.tokens.opacity-range")}
|
||||
(fn [opacity]
|
||||
(if (str/numeric? opacity)
|
||||
(let [n (d/parse-percent opacity)]
|
||||
@ -71,7 +71,7 @@
|
||||
|
||||
(def schema:token-value-font-weight
|
||||
[:or
|
||||
[:fn {:error/fn #(tr "workspace.tokens.invalid-font-weight-token-value")}
|
||||
[:fn {:error/fn #(tr "errors.tokens.invalid-font-weight-token-value")}
|
||||
cto/valid-font-weight-variant]
|
||||
::sm/text]) ;; Leave references or formulas to be checked by the resolver
|
||||
|
||||
@ -147,6 +147,27 @@
|
||||
#(and (some? tokens-tree)
|
||||
(not (ctob/token-name-path-exists? % tokens-tree)))]])
|
||||
|
||||
(defn make-node-token-name-schema
|
||||
"Dynamically generates a schema to check a token node name, adding translated error messages
|
||||
and two additional validations:
|
||||
- Min and max length.
|
||||
- Checks if other token with a path derived from the name already exists at `tokens-tree`.
|
||||
e.g. it's not allowed to create a token `foo.bar` if a token `foo` already exists."
|
||||
[active-tokens tokens-tree node]
|
||||
[:and
|
||||
[:string {:min 1 :max 255 :error/fn #(str (:value %) (tr "workspace.tokens.token-name-length-validation-error"))}]
|
||||
(-> cto/schema:token-node-name
|
||||
(sm/update-properties assoc :error/fn #(str (:value %) (tr "workspace.tokens.token-name-validation-error"))))
|
||||
[:fn {:error/fn #(tr "workspace.tokens.token-name-duplication-validation-error" (:value %))}
|
||||
(fn [name]
|
||||
(let [current-path (:path node)
|
||||
current-name (:name node)
|
||||
new-tokens (ctob/update-tokens-group active-tokens current-path current-name name)]
|
||||
(and (some? new-tokens)
|
||||
(some (fn [[token-name _]]
|
||||
(not (ctob/token-name-path-exists? token-name tokens-tree)))
|
||||
new-tokens))))]])
|
||||
|
||||
(def schema:token-description
|
||||
[:string {:max 2048 :error/fn #(tr "errors.field-max-length" 2048)}])
|
||||
|
||||
@ -160,11 +181,16 @@
|
||||
[:value (make-token-value-schema token-type)]
|
||||
[:description {:optional true} schema:token-description]])
|
||||
[:fn {:error/field :value
|
||||
:error/fn #(tr "workspace.tokens.self-reference")}
|
||||
:error/fn #(tr "errors.tokens.self-reference")}
|
||||
(fn [{:keys [name value]}]
|
||||
(when (and name value)
|
||||
(not (cto/token-value-self-reference? name value))))]])
|
||||
|
||||
(defn make-node-token-schema
|
||||
[active-tokens tokens-tree node]
|
||||
[:map
|
||||
[:name (make-node-token-name-schema active-tokens tokens-tree node)]])
|
||||
|
||||
(defn convert-dtcg-token
|
||||
"Convert token attributes as they come from a decoded json, with DTCG types, to internal types.
|
||||
Eg. From this:
|
||||
@ -288,16 +314,12 @@
|
||||
{:value parsed-value
|
||||
:unit unit}))))
|
||||
|
||||
;; FIXME: looks very redundant function
|
||||
(defn token-identifier
|
||||
[{:keys [name] :as _token}]
|
||||
name)
|
||||
|
||||
(defn attributes-map
|
||||
"Creats an attributes map using collection of `attributes` for `id`."
|
||||
"Creates an attributes map using collection of `attributes` for `id`."
|
||||
[attributes token]
|
||||
(->> (map (fn [attr] [attr (token-identifier token)]) attributes)
|
||||
(into {})))
|
||||
(into {}
|
||||
(map (fn [attr] [attr (:name token)]))
|
||||
attributes))
|
||||
|
||||
(defn remove-attributes-for-token
|
||||
"Removes applied tokens with `token-name` for the given `attributes` set from `applied-tokens`."
|
||||
@ -313,7 +335,7 @@
|
||||
"Test if `token` is applied to a `shape` on single `token-attribute`."
|
||||
[token shape token-attribute]
|
||||
(when-let [id (dm/get-in shape [:applied-tokens token-attribute])]
|
||||
(= (token-identifier token) id)))
|
||||
(= (:name token) id)))
|
||||
|
||||
(defn token-applied?
|
||||
"Test if `token` is applied to a `shape` with at least one of the given `token-attributes`."
|
||||
|
||||
@ -51,6 +51,7 @@
|
||||
:ref-shape-is-head
|
||||
:ref-shape-is-not-head
|
||||
:shape-ref-in-main
|
||||
:component-id-mismatch
|
||||
:root-main-not-allowed
|
||||
:nested-main-not-allowed
|
||||
:root-copy-not-allowed
|
||||
@ -59,6 +60,7 @@
|
||||
:not-head-copy-not-allowed
|
||||
:not-component-not-allowed
|
||||
:component-nil-objects-not-allowed
|
||||
:non-deleted-component-cannot-have-objects
|
||||
:instance-head-not-frame
|
||||
:invalid-text-touched
|
||||
:misplaced-slot
|
||||
@ -326,6 +328,20 @@
|
||||
:component-file (:component-file ref-shape)
|
||||
:component-id (:component-id ref-shape)))))
|
||||
|
||||
(defn- check-ref-component-id
|
||||
"Validate that if the copy has not been swapped, the component-id and component-file are
|
||||
the same as in the referenced shape in the near main."
|
||||
[shape file page libraries]
|
||||
(when (nil? (ctk/get-swap-slot shape))
|
||||
(when-let [ref-shape (ctf/find-ref-shape file page libraries shape :include-deleted? true)]
|
||||
(when (or (not= (:component-id shape) (:component-id ref-shape))
|
||||
(not= (:component-file shape) (:component-file ref-shape)))
|
||||
(report-error :component-id-mismatch
|
||||
"Nested copy component-id and component-file must be the same as the near main"
|
||||
shape file page
|
||||
:component-id (:component-id ref-shape)
|
||||
:component-file (:component-file ref-shape))))))
|
||||
|
||||
(defn- check-empty-swap-slot
|
||||
"Validate that this shape does not have any swap slot."
|
||||
[shape file page]
|
||||
@ -350,6 +366,19 @@
|
||||
"This shape has children with the same swap slot"
|
||||
shape file page)))
|
||||
|
||||
(defn- check-required-swap-slot
|
||||
"Validate that the shape has swap-slot if it's a subinstance head and the ref shape is not the
|
||||
matching shape by position in the near main."
|
||||
[shape file page libraries]
|
||||
(let [near-match (ctf/find-near-match file page libraries shape :include-deleted? true :with-context? false)]
|
||||
(when (and (some? near-match)
|
||||
(not= (:shape-ref shape) (:id near-match))
|
||||
(nil? (ctk/get-swap-slot shape)))
|
||||
(report-error :missing-slot
|
||||
"Shape has been swapped, should have swap slot"
|
||||
shape file page
|
||||
:swap-slot (or (ctk/get-swap-slot near-match) (:id near-match))))))
|
||||
|
||||
(defn- check-valid-touched
|
||||
"Validate that the text touched flags are coherent."
|
||||
[shape file page]
|
||||
@ -418,6 +447,8 @@
|
||||
(check-component-not-main-head shape file page libraries)
|
||||
(check-component-not-root shape file page)
|
||||
(check-valid-touched shape file page)
|
||||
(check-ref-component-id shape file page libraries)
|
||||
(check-required-swap-slot shape file page libraries)
|
||||
;; We can have situations where the nested copy and the ancestor copy come from different libraries and some of them have been dettached
|
||||
;; so we only validate the shape-ref if the ancestor is from a valid library
|
||||
(when library-exists
|
||||
@ -458,8 +489,7 @@
|
||||
(defn- check-variant-container
|
||||
"Shape is a variant container, so:
|
||||
-all its children should be variants with variant-id equals to the shape-id
|
||||
-all the components should have the same properties
|
||||
"
|
||||
-all the components should have the same properties"
|
||||
[shape file page]
|
||||
(let [shape-id (:id shape)
|
||||
shapes (:shapes shape)
|
||||
@ -648,6 +678,13 @@
|
||||
"Component main not allowed inside other component"
|
||||
main-instance file component-page))))
|
||||
|
||||
(defn- check-not-objects
|
||||
[component file]
|
||||
(when (d/not-empty? (:objects component))
|
||||
(report-error :non-deleted-component-cannot-have-objects
|
||||
"A non-deleted component cannot have shapes inside"
|
||||
component file nil)))
|
||||
|
||||
(defn- check-component
|
||||
"Validate semantic coherence of a component. Report all errors found."
|
||||
[component file]
|
||||
@ -656,7 +693,8 @@
|
||||
"Objects list cannot be nil"
|
||||
component file nil))
|
||||
(when-not (:deleted component)
|
||||
(check-main-inside-main component file))
|
||||
(check-main-inside-main component file)
|
||||
(check-not-objects component file))
|
||||
(when (:deleted component)
|
||||
(check-component-duplicate-swap-slot component file)
|
||||
(check-ref-cycles component file))
|
||||
@ -674,8 +712,6 @@
|
||||
;; PUBLIC API: VALIDATION FUNCTIONS
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(declare check-swap-slots)
|
||||
|
||||
(defn validate-file
|
||||
"Validate full referential integrity and semantic coherence on file data.
|
||||
|
||||
@ -686,8 +722,6 @@
|
||||
|
||||
(doseq [page (filter :id (ctpl/pages-seq data))]
|
||||
(check-shape uuid/zero file page libraries)
|
||||
(when (str/includes? (:name file) "check-swap-slot")
|
||||
(check-swap-slots uuid/zero file page libraries))
|
||||
(->> (get-orphan-shapes page)
|
||||
(run! #(check-shape % file page libraries))))
|
||||
|
||||
@ -728,40 +762,3 @@
|
||||
:hint "error on validating file referential integrity"
|
||||
:file-id (:id file)
|
||||
:details errors)))
|
||||
|
||||
(declare compare-slots)
|
||||
|
||||
;; Optional check to look for missing swap slots.
|
||||
;; Search for copies that do not point the shape-ref to the near component but don't have swap slot
|
||||
;; (looking for position relative to the parent, in the copy and the main).
|
||||
;;
|
||||
;; This check cannot be generally enabled, because files that have been migrated from components v1
|
||||
;; may have copies with shapes that do not match by position, but have not been swapped. So we enable
|
||||
;; it for specific files only. To activate the check, you need to add the string "check-swap-slot" to
|
||||
;; the name of the file.
|
||||
(defn- check-swap-slots
|
||||
[shape-id file page libraries]
|
||||
(let [shape (ctst/get-shape page shape-id)]
|
||||
(if (and (ctk/instance-root? shape) (ctk/in-component-copy? shape))
|
||||
(let [ref-shape (ctf/find-ref-shape file page libraries shape :include-deleted? true :with-context? true)
|
||||
container (:container (meta ref-shape))]
|
||||
(when (some? ref-shape)
|
||||
(compare-slots shape ref-shape file page container)))
|
||||
(doall (for [child-id (:shapes shape)]
|
||||
(check-swap-slots child-id file page libraries))))))
|
||||
|
||||
(defn- compare-slots
|
||||
[shape-copy shape-main file container-copy container-main]
|
||||
(if (and (not= (:shape-ref shape-copy) (:id shape-main))
|
||||
(nil? (ctk/get-swap-slot shape-copy)))
|
||||
(report-error :missing-slot
|
||||
"Shape has been swapped, should have swap slot"
|
||||
shape-copy file container-copy
|
||||
:swap-slot (or (ctk/get-swap-slot shape-main) (:id shape-main)))
|
||||
(when (nil? (ctk/get-swap-slot shape-copy))
|
||||
(let [children-id-pairs (d/zip-all (:shapes shape-copy) (:shapes shape-main))]
|
||||
(doall (for [[child-copy-id child-main-id] children-id-pairs]
|
||||
(let [child-copy (ctst/get-shape container-copy child-copy-id)
|
||||
child-main (ctst/get-shape container-main child-main-id)]
|
||||
(when (and (some? child-copy) (some? child-main))
|
||||
(compare-slots child-copy child-main file container-copy container-main)))))))))
|
||||
|
||||
@ -128,6 +128,8 @@
|
||||
:token-shadow
|
||||
:token-tokenscript
|
||||
:token-import-from-library
|
||||
:token-typography-row
|
||||
|
||||
;; Only for developtment.
|
||||
:transit-readable-response
|
||||
:user-feedback
|
||||
@ -195,8 +197,7 @@
|
||||
:enable-inspect-styles
|
||||
:enable-feature-fdata-objects-map
|
||||
:enable-feature-render-wasm
|
||||
;; Temporary deactivated
|
||||
#_:enable-token-import-from-library])
|
||||
:enable-token-import-from-library])
|
||||
|
||||
(defn parse
|
||||
[& flags]
|
||||
|
||||
@ -118,8 +118,9 @@
|
||||
|
||||
(defn- duplicate-component
|
||||
"Clone the root shape of the component and all children. Generate new
|
||||
ids from all of them."
|
||||
[component new-component-id library-data force-id delta variant-id]
|
||||
ids from all of them. Optionally set the component-file if the file where the
|
||||
new component will reside is different than the origin one."
|
||||
[component new-component-id new-component-file library-data force-id delta variant-id]
|
||||
(let [main-instance-page (ctf/get-component-page library-data component)
|
||||
main-instance-shape (ctf/get-component-root library-data component)
|
||||
delta (or delta (gpt/point (+ (:width main-instance-shape) 50) 0))
|
||||
@ -141,10 +142,18 @@
|
||||
update-new-shape
|
||||
(fn [new-shape _]
|
||||
(cond-> new-shape
|
||||
; Link the new main to the new component
|
||||
;; Link the new main to the new component, and re-root it
|
||||
;; to the destination file when duplicating across files.
|
||||
;; Only the outer main matches `(:id component)`, so
|
||||
;; nested main-instances are not touched here.
|
||||
(= (:component-id new-shape) (:id component))
|
||||
(assoc :component-id new-component-id)
|
||||
|
||||
(and (= (:component-id new-shape) (:id component))
|
||||
(some? new-component-file)
|
||||
(not= new-component-file (:component-file new-shape)))
|
||||
(assoc :component-file new-component-file)
|
||||
|
||||
; If it is the instance root, add it the variant-id
|
||||
(and (ctk/instance-root? new-shape) (some? variant-id))
|
||||
(assoc :variant-id variant-id)
|
||||
@ -188,7 +197,7 @@
|
||||
|
||||
(defn generate-duplicate-component
|
||||
"Create a new component copied from the one with the given id."
|
||||
[changes library component-id new-component-id & {:keys [new-shape-id apply-changes-local-library? delta new-variant-id page-id]}]
|
||||
[changes library component-id new-component-id & {:keys [new-component-file new-shape-id apply-changes-local-library? delta new-variant-id page-id]}]
|
||||
(let [component (ctkl/get-component (:data library) component-id)
|
||||
new-name (:name component)
|
||||
|
||||
@ -197,7 +206,7 @@
|
||||
target-page-id (or page-id (:id main-instance-page))
|
||||
|
||||
[new-main-instance-shape new-main-instance-shapes]
|
||||
(duplicate-component component new-component-id (:data library) new-shape-id delta new-variant-id)]
|
||||
(duplicate-component component new-component-id new-component-file (:data library) new-shape-id delta new-variant-id)]
|
||||
|
||||
[new-main-instance-shape
|
||||
(-> changes
|
||||
@ -333,7 +342,7 @@
|
||||
(pcb/update-shapes [shape-id] #(do (log/trace :msg " -> promote to root")
|
||||
(assoc % :component-root true)))
|
||||
|
||||
:always
|
||||
(some? (ctk/get-swap-slot shape))
|
||||
; First level subinstances of a detached component can't have swap-slot
|
||||
(pcb/update-shapes [shape-id] #(do (log/trace :msg " -> remove swap-slot")
|
||||
(ctk/remove-swap-slot %)))
|
||||
@ -364,7 +373,7 @@
|
||||
(let [ref-shape (ctf/find-ref-shape file container libraries shape {:include-deleted? true})]
|
||||
(cond-> changes
|
||||
(some? (:shape-ref ref-shape))
|
||||
(pcb/update-shapes [(:id shape)] #(do (log/trace :msg " (advanced)")
|
||||
(pcb/update-shapes [(:id shape)] #(do (log/trace :msg (str " (advanced to " (:shape-ref ref-shape) ")"))
|
||||
(assoc % :shape-ref (:shape-ref ref-shape))))
|
||||
|
||||
;; When advancing level, the normal touched groups (not swap slots) of the
|
||||
@ -374,16 +383,18 @@
|
||||
(pcb/update-shapes
|
||||
[(:id shape)]
|
||||
#(do (log/trace :msg " (merge touched)")
|
||||
(log/trace :msg (str " (ref-shape: " (:id ref-shape) ")"))
|
||||
(log/trace :msg (str " (ref touched: " (:touched ref-shape) ")"))
|
||||
(assoc % :touched
|
||||
(clojure.set/union (:touched shape)
|
||||
(ctk/normal-touched-groups ref-shape)))))
|
||||
(set/union (:touched shape)
|
||||
(ctk/normal-touched-groups ref-shape)))))
|
||||
|
||||
;; Swap slot must also be copied if the current shape has not any,
|
||||
;; except if this is the first level subcopy.
|
||||
(and (some? (ctk/get-swap-slot ref-shape))
|
||||
(nil? (ctk/get-swap-slot shape))
|
||||
(not= (:id shape) shape-id))
|
||||
(pcb/update-shapes [(:id shape)] #(do (log/trace :msg " (got swap-slot)")
|
||||
(pcb/update-shapes [(:id shape)] #(do (log/trace :msg (str " (got swap-slot " (ctk/get-swap-slot ref-shape) ")"))
|
||||
(ctk/set-swap-slot % (ctk/get-swap-slot ref-shape))))
|
||||
|
||||
;; If we can't get the ref-shape (e.g. it's in an external library not linked),
|
||||
@ -771,14 +782,6 @@
|
||||
;; is different than the one in the near component (Shape-2-2-1)
|
||||
;; but it's not touched.
|
||||
|
||||
(defn- redirect-shaperef ;;Set the :shape-ref of a shape pointing to the :id of its remote-shape
|
||||
([container libraries shape]
|
||||
(redirect-shaperef nil nil shape (ctf/find-remote-shape container libraries shape)))
|
||||
([_ _ shape remote-shape]
|
||||
(if (some? (:shape-ref shape))
|
||||
(assoc shape :shape-ref (:id remote-shape))
|
||||
shape)))
|
||||
|
||||
(defn generate-sync-shape-direct
|
||||
"Generate changes to synchronize one shape that is the root of a component
|
||||
instance, and all its children, from the given component."
|
||||
@ -790,18 +793,12 @@
|
||||
component (ctkl/get-component library (:component-id shape-inst) true)]
|
||||
(if (and (ctk/in-component-copy? shape-inst)
|
||||
(or (ctf/direct-copy? shape-inst component container nil libraries) reset?)) ; In a normal sync, we don't want to sync remote mains, only direct/near
|
||||
(let [redirect-shaperef (partial redirect-shaperef container libraries)
|
||||
|
||||
shape-main (when component
|
||||
(let [shape-main (when component
|
||||
(if reset?
|
||||
;; the reset is against the ref-shape, not against the original shape of the component
|
||||
(ctf/find-ref-shape file container libraries shape-inst)
|
||||
(ctf/get-ref-shape library component shape-inst)))
|
||||
|
||||
shape-inst (if reset?
|
||||
(redirect-shaperef shape-inst shape-main)
|
||||
shape-inst)
|
||||
|
||||
initial-root? (:component-root shape-inst)
|
||||
|
||||
root-inst shape-inst
|
||||
@ -819,8 +816,8 @@
|
||||
root-inst
|
||||
root-main
|
||||
reset?
|
||||
initial-root?
|
||||
redirect-shaperef)
|
||||
initial-root?)
|
||||
|
||||
;; If the component is not found, because the master component has been
|
||||
;; deleted or the library unlinked, do nothing.
|
||||
changes))
|
||||
@ -844,7 +841,7 @@
|
||||
nil))))))
|
||||
|
||||
(defn- generate-sync-shape-direct-recursive
|
||||
[changes container shape-inst component library file libraries shape-main root-inst root-main reset? initial-root? redirect-shaperef]
|
||||
[changes container shape-inst component library file libraries shape-main root-inst root-main reset? initial-root?]
|
||||
(shape-log :debug (:id shape-inst) container
|
||||
:msg "Sync shape direct recursive"
|
||||
:shape-inst (str (:name shape-inst) " " (pretty-uuid (:id shape-inst)))
|
||||
@ -891,9 +888,6 @@
|
||||
children-inst (vec (ctn/get-direct-children container shape-inst))
|
||||
children-main (vec (ctn/get-direct-children component-container shape-main))
|
||||
|
||||
children-inst (if reset?
|
||||
(map #(redirect-shaperef %) children-inst) children-inst)
|
||||
|
||||
only-inst (fn [changes child-inst]
|
||||
(shape-log :trace (:id child-inst) container
|
||||
:msg "Only inst"
|
||||
@ -942,8 +936,7 @@
|
||||
root-inst
|
||||
root-main
|
||||
reset?
|
||||
initial-root?
|
||||
redirect-shaperef))
|
||||
initial-root?))
|
||||
|
||||
swapped (fn [changes child-inst child-main]
|
||||
(shape-log :trace (:id child-inst) container
|
||||
@ -1008,16 +1001,13 @@
|
||||
the values in the shape and all its children."
|
||||
[changes file libraries container shape-id]
|
||||
(shape-log :debug shape-id container :msg "Sync shape inverse" :shape (str shape-id))
|
||||
(let [redirect-shaperef (partial redirect-shaperef container libraries)
|
||||
shape-inst (ctn/get-shape container shape-id)
|
||||
(let [shape-inst (ctn/get-shape container shape-id)
|
||||
library (dm/get-in libraries [(:component-file shape-inst) :data])
|
||||
component (ctkl/get-component library (:component-id shape-inst))
|
||||
|
||||
shape-main (when component
|
||||
(ctf/find-remote-shape container libraries shape-inst))
|
||||
|
||||
shape-inst (redirect-shaperef shape-inst shape-main)
|
||||
|
||||
initial-root? (:component-root shape-inst)
|
||||
|
||||
root-inst shape-inst
|
||||
@ -1038,12 +1028,11 @@
|
||||
shape-main
|
||||
root-inst
|
||||
root-main
|
||||
initial-root?
|
||||
redirect-shaperef)
|
||||
initial-root?)
|
||||
changes)))
|
||||
|
||||
(defn- generate-sync-shape-inverse-recursive
|
||||
[changes container shape-inst component library file libraries shape-main root-inst root-main initial-root? redirect-shaperef]
|
||||
[changes container shape-inst component library file libraries shape-main root-inst root-main initial-root?]
|
||||
(shape-log :trace (:id shape-inst) container
|
||||
:msg "Sync shape inverse recursive"
|
||||
:shape (str (:name shape-inst))
|
||||
@ -1100,8 +1089,6 @@
|
||||
children-main (mapv #(ctn/get-shape component-container %)
|
||||
(:shapes shape-main))
|
||||
|
||||
children-inst (map #(redirect-shaperef %) children-inst)
|
||||
|
||||
only-inst (fn [changes child-inst]
|
||||
(add-shape-to-main changes
|
||||
child-inst
|
||||
@ -1130,8 +1117,7 @@
|
||||
child-main
|
||||
root-inst
|
||||
root-main
|
||||
initial-root?
|
||||
redirect-shaperef))
|
||||
initial-root?))
|
||||
|
||||
swapped (fn [changes child-inst child-main]
|
||||
(shape-log :trace (:id child-inst) container
|
||||
@ -1773,6 +1759,23 @@
|
||||
(pcb/update-shapes changes [(:id dest-shape)] ctk/unhead-shape {:ignore-touched true})
|
||||
changes))
|
||||
|
||||
(defn- check-swapped-main
|
||||
[changes dest-shape origin-shape]
|
||||
;; Only for direct updates (from main to copy). Check if the main shape
|
||||
;; has been swapped. If so, the new component-id and component-file must
|
||||
;; be put into the copy.
|
||||
(if (and (= (:shape-ref dest-shape) (:id origin-shape))
|
||||
(ctk/instance-head? dest-shape)
|
||||
(ctk/instance-head? origin-shape)
|
||||
(or (not= (:component-id dest-shape) (:component-id origin-shape))
|
||||
(not= (:component-file dest-shape) (:component-file origin-shape))))
|
||||
(pcb/update-shapes changes [(:id dest-shape)]
|
||||
#(assoc %
|
||||
:component-id (:component-id origin-shape)
|
||||
:component-file (:component-file origin-shape))
|
||||
{:ignore-touched true})
|
||||
changes))
|
||||
|
||||
(defn- update-attrs
|
||||
"The main function that implements the attribute sync algorithm. Copy
|
||||
attributes that have changed in the origin shape to the dest shape.
|
||||
@ -1816,6 +1819,8 @@
|
||||
:always
|
||||
(check-detached-main dest-shape origin-shape)
|
||||
:always
|
||||
(check-swapped-main dest-shape origin-shape)
|
||||
:always
|
||||
(generate-update-tokens container dest-shape origin-shape touched omit-touched? nil))
|
||||
|
||||
(let [sync-group
|
||||
@ -2731,7 +2736,7 @@
|
||||
frames)))
|
||||
|
||||
(defn- duplicate-variant
|
||||
[changes library component base-pos parent page-id into-new-variant?]
|
||||
[changes library component base-pos parent page-id into-new-variant? new-component-file]
|
||||
(let [component-page (ctpl/get-page (:data library) (:main-instance-page component))
|
||||
objects (:objects component-page)
|
||||
component-shape (get objects (:main-instance-id component))
|
||||
@ -2745,7 +2750,8 @@
|
||||
{:apply-changes-local-library? true
|
||||
:delta delta
|
||||
:new-variant-id (if into-new-variant? nil (:id parent))
|
||||
:page-id page-id})
|
||||
:page-id page-id
|
||||
:new-component-file new-component-file})
|
||||
value (when into-new-variant?
|
||||
(str ctv/value-prefix
|
||||
(-> (cfv/extract-properties-values (:data library) objects (:id parent))
|
||||
@ -2768,15 +2774,18 @@
|
||||
|
||||
|
||||
(defn generate-duplicate-component-change
|
||||
[changes objects page main parent-id frame-id delta libraries library-data ids-map]
|
||||
(let [main-id (:id main)
|
||||
component-id (:component-id main)
|
||||
file-id (:component-file main)
|
||||
component (ctf/get-component libraries file-id component-id)
|
||||
pos (as-> (gsh/move main delta) $
|
||||
(gpt/point (:x $) (:y $)))
|
||||
[changes objects page main parent-id frame-id delta libraries library-data ids-map & {:keys [new-component-file]}]
|
||||
(let [main-id (:id main)
|
||||
component-id (:component-id main)
|
||||
;; Source library file id (where the component was originally
|
||||
;; defined). Renamed from `file-id` to make the contrast with
|
||||
;; `new-component-file` explicit when duplicating across files.
|
||||
source-file-id (:component-file main)
|
||||
component (ctf/get-component libraries source-file-id component-id)
|
||||
pos (as-> (gsh/move main delta) $
|
||||
(gpt/point (:x $) (:y $)))
|
||||
|
||||
parent (get objects parent-id)
|
||||
parent (get objects parent-id)
|
||||
|
||||
|
||||
;; When we duplicate a variant alone, we will instanciate it
|
||||
@ -2803,25 +2812,27 @@
|
||||
|
||||
(and (ctk/is-variant? main) in-variant-container?)
|
||||
(duplicate-variant changes
|
||||
(get libraries file-id)
|
||||
(get libraries source-file-id)
|
||||
component
|
||||
pos
|
||||
parent
|
||||
(:id page)
|
||||
false)
|
||||
false
|
||||
new-component-file)
|
||||
|
||||
(ctk/is-variant-container? parent)
|
||||
(duplicate-variant changes
|
||||
(get libraries file-id)
|
||||
(get libraries source-file-id)
|
||||
component
|
||||
pos
|
||||
parent
|
||||
(:id page)
|
||||
true)
|
||||
true
|
||||
new-component-file)
|
||||
:else
|
||||
(generate-instantiate-component changes
|
||||
objects
|
||||
file-id
|
||||
source-file-id
|
||||
component-id
|
||||
pos
|
||||
page
|
||||
@ -2845,7 +2856,7 @@
|
||||
changes
|
||||
|
||||
(ctf/is-main-of-known-component? obj libraries)
|
||||
(generate-duplicate-component-change changes objects page obj parent-id frame-id delta libraries library-data ids-map)
|
||||
(generate-duplicate-component-change changes objects page obj parent-id frame-id delta libraries library-data ids-map {:new-component-file file-id})
|
||||
|
||||
:else
|
||||
(let [frame? (cfh/frame-shape? obj)
|
||||
|
||||
@ -114,3 +114,15 @@
|
||||
800 "Extra Bold"
|
||||
900 "Black"
|
||||
950 "Extra Black"))
|
||||
|
||||
(defn font-display-variant
|
||||
[variant-name weight style]
|
||||
(cond
|
||||
(and (string? variant-name) (not (str/blank? variant-name)))
|
||||
(str/trim variant-name)
|
||||
|
||||
:else
|
||||
(let [base (font-weight->name weight)
|
||||
italic? (= "italic" style)]
|
||||
(cond-> base
|
||||
italic? (str " Italic")))))
|
||||
|
||||
@ -148,16 +148,16 @@ Some naming conventions:
|
||||
:path 'one'
|
||||
:depth 0
|
||||
:leaf nil
|
||||
:children-fn (fn [] [{:name 'two'
|
||||
:path 'one.two'
|
||||
:depth 1
|
||||
:leaf nil
|
||||
:children-fn (fn [] [{... :name 'three'} {... :name 'four'}])}
|
||||
{:name 'five'
|
||||
:path 'one.five'
|
||||
:depth 1
|
||||
:leaf {... :name 'five'}
|
||||
...}])}]"
|
||||
:children [{:name 'two'
|
||||
:path 'one.two'
|
||||
:depth 1
|
||||
:leaf nil
|
||||
:children [{... :name 'three'} {... :name 'four'}]}
|
||||
{:name 'five'
|
||||
:path 'one.five'
|
||||
:depth 1
|
||||
:leaf {... :name 'five'}
|
||||
:children nil}]}]"
|
||||
|
||||
(defn- sort-by-children
|
||||
"Sorts segments so that those with children come first."
|
||||
@ -191,7 +191,7 @@ Some naming conventions:
|
||||
(into (sorted-map) grouped)))
|
||||
|
||||
(defn- build-tree-node
|
||||
"Builds a single tree node with lazy children."
|
||||
"Builds a single tree node with computed children."
|
||||
[segment-name remaining-segments separator parent-path depth]
|
||||
(let [current-path (if parent-path
|
||||
(str parent-path "." segment-name)
|
||||
@ -208,12 +208,11 @@ Some naming conventions:
|
||||
:path current-path
|
||||
:depth depth
|
||||
:leaf leaf-segment
|
||||
:children-fn (when-not is-leaf?
|
||||
(fn []
|
||||
(let [grouped-elements (sort-and-group-segments remaining-segments separator)]
|
||||
(mapv (fn [[child-segment-name remaining-child-segments]]
|
||||
(build-tree-node child-segment-name remaining-child-segments separator current-path (inc depth)))
|
||||
grouped-elements))))}]
|
||||
:children (when-not is-leaf?
|
||||
(let [grouped-elements (sort-and-group-segments remaining-segments separator)]
|
||||
(mapv (fn [[child-segment-name remaining-child-segments]]
|
||||
(build-tree-node child-segment-name remaining-child-segments separator current-path (inc depth)))
|
||||
grouped-elements)))}]
|
||||
node))
|
||||
|
||||
(defn build-tree-root
|
||||
|
||||
@ -177,8 +177,11 @@
|
||||
(thc/instantiate-component component-label copy-root-label copy-root-params)))
|
||||
|
||||
(defn add-nested-component
|
||||
[file component1-label main1-root-label main1-child-label component2-label main2-root-label nested-head-label
|
||||
& {:keys [component1-params root1-params main1-child-params component2-params main2-root-params nested-head-params]}]
|
||||
[file
|
||||
component1-label main1-root-label main1-child-label
|
||||
component2-label main2-root-label nested-head-label
|
||||
& {:keys [component1-params root1-params main1-child-params
|
||||
component2-params main2-root-params nested-head-params]}]
|
||||
;; Generated shape tree:
|
||||
;; {:main1-root-label} [:name Frame1] # [Component :component1-label]
|
||||
;; :main1-child-label [:name Rect1]
|
||||
@ -204,8 +207,13 @@
|
||||
component2-params)))
|
||||
|
||||
(defn add-nested-component-with-copy
|
||||
[file component1-label main1-root-label main1-child-label component2-label main2-root-label nested-head-label copy2-root-label
|
||||
& {:keys [component1-params root1-params main1-child-params component2-params main2-root-params nested-head-params copy2-root-params]}]
|
||||
[file
|
||||
component1-label main1-root-label main1-child-label
|
||||
component2-label main2-root-label nested-head-label
|
||||
copy2-root-label
|
||||
& {:keys [component1-params root1-params main1-child-params
|
||||
component2-params main2-root-params nested-head-params
|
||||
copy2-root-params]}]
|
||||
;; Generated shape tree:
|
||||
;; {:main1-root-label} [:name Frame1] # [Component :component1-label]
|
||||
;; :main1-child-label [:name Rect1]
|
||||
@ -232,6 +240,102 @@
|
||||
:nested-head-params nested-head-params)
|
||||
(thc/instantiate-component component2-label copy2-root-label copy2-root-params)))
|
||||
|
||||
(defn add-two-levels-nested-component
|
||||
[file
|
||||
component1-label main1-root-label main1-child-label
|
||||
component2-label main2-root-label nested-head1-label
|
||||
component3-label main3-root-label nested-head2-label nested-subhead2-label
|
||||
& {:keys [component1-params root1-params main1-child-params
|
||||
component2-params main2-root-params nested-head1-params
|
||||
component3-params main3-root-params nested-head2-params]}]
|
||||
;; Generated shape tree:
|
||||
;; {:main1-root-label} [:name Frame1] # [Component :component1-label]
|
||||
;; :main1-child-label [:name Rect1]
|
||||
;;
|
||||
;; {:main2-root-label} [:name Frame2] # [Component :component2-label]
|
||||
;; :nested-head1-label [:name Frame1] @--> [Component :component1-label] :main1-root-label
|
||||
;; <no-label> [:name Rect1] ---> :main1-child-label
|
||||
;;
|
||||
;; {:main3-root-label} [:name Frame3] # [Component :component3-label]
|
||||
;; :nested-head2-label [:name Frame2] @--> [Component :component2-label] :main2-root-label
|
||||
;; :nested-subhead2-label [:name Frame1] @--> [Component :component1-label] :main1-root-label
|
||||
;; <no-label> [:name Rect1] ---> :main1-child-label
|
||||
(-> file
|
||||
(add-simple-component component1-label
|
||||
main1-root-label
|
||||
main1-child-label
|
||||
:component-params component1-params
|
||||
:root-params root1-params
|
||||
:child-params main1-child-params)
|
||||
(add-frame main2-root-label (merge {:name "Frame2"}
|
||||
main2-root-params))
|
||||
(thc/instantiate-component component1-label
|
||||
nested-head1-label
|
||||
(assoc nested-head1-params
|
||||
:parent-label main2-root-label))
|
||||
(thc/make-component component2-label
|
||||
main2-root-label
|
||||
component2-params)
|
||||
(add-frame main3-root-label (merge {:name "Frame3"}
|
||||
main3-root-params))
|
||||
(thc/instantiate-component component2-label
|
||||
nested-head2-label
|
||||
(assoc nested-head2-params
|
||||
:parent-label main3-root-label
|
||||
:children-labels [nested-subhead2-label]))
|
||||
(thc/make-component component3-label
|
||||
main3-root-label
|
||||
component3-params)))
|
||||
|
||||
(defn add-two-levels-nested-component-with-copy
|
||||
[file
|
||||
component1-label main1-root-label main1-child-label
|
||||
component2-label main2-root-label nested-head1-label
|
||||
component3-label main3-root-label nested-head2-label nested-subhead2-label
|
||||
copy2-root-label
|
||||
& {:keys [component1-params root1-params main1-child-params
|
||||
component2-params main2-root-params nested-head1-params
|
||||
component3-params main3-root-params nested-head2-params
|
||||
copy2-root-params]}]
|
||||
;; Generated shape tree:
|
||||
;; {:main1-root-label} [:name Frame1] # [Component :component1-label]
|
||||
;; :main1-child-label [:name Rect1]
|
||||
;;
|
||||
;; {:main2-root-label} [:name Frame2] # [Component :component2-label]
|
||||
;; :nested-head1-label [:name Frame1] @--> [Component :component1-label] :main1-root-label
|
||||
;; <no-label> [:name Rect1] ---> :main1-child-label
|
||||
;;
|
||||
;; {:main3-root-label} [:name Frame3] # [Component :component3-label]
|
||||
;; :nested-head2-label [:name Frame2] @--> [Component :component2-label] :main2-root-label
|
||||
;; :nested-subhead2-label [:name Frame1] @--> [Component :component1-label] :main1-root-label
|
||||
;; <no-label> [:name Rect1] ---> :main1-child-label
|
||||
;;
|
||||
;; :copy2-label [:name Frame3] #--> [Component :component3-label] :main3-root-label
|
||||
;; <no-label> [:name Frame2] @--> [Component :component2-label] :nested-head2-label
|
||||
;; <no-label> [:name Frame1] @--> [Component :component1-label] :nested-subhead2-label
|
||||
;; <no-label> [:name Rect1] ---> <no-label>
|
||||
(-> file
|
||||
(add-two-levels-nested-component component1-label
|
||||
main1-root-label
|
||||
main1-child-label
|
||||
component2-label
|
||||
main2-root-label
|
||||
nested-head1-label
|
||||
component3-label
|
||||
main3-root-label
|
||||
nested-head2-label
|
||||
nested-subhead2-label
|
||||
:component1-params component1-params
|
||||
:root1-params root1-params
|
||||
:main1-child-params main1-child-params
|
||||
:component2-params component2-params
|
||||
:main2-root-params main2-root-params
|
||||
:nested-head1-params nested-head1-params
|
||||
:component3-params component3-params
|
||||
:main3-root-params main3-root-params
|
||||
:nested-head2-params nested-head2-params)
|
||||
(thc/instantiate-component component3-label copy2-root-label copy2-root-params)))
|
||||
|
||||
;; ----- Getters
|
||||
|
||||
(defn bottom-shape-by-id
|
||||
@ -274,15 +378,18 @@
|
||||
file-id
|
||||
{file-id file}
|
||||
file-id))]
|
||||
(thf/apply-changes file changes)))
|
||||
(thf/apply-changes file changes :validate? false)))
|
||||
|
||||
(defn swap-component
|
||||
(defn swap-component-
|
||||
"Swap the specified shape by the component specified by component-tag"
|
||||
[file shape component-tag & {:keys [page-label propagate-fn keep-touched? new-shape-label]}]
|
||||
[file shape component-tag & {:keys [page-label propagate-fn keep-touched? new-shape-label library]}]
|
||||
(let [page (if page-label
|
||||
(thf/get-page file page-label)
|
||||
(thf/current-page file))
|
||||
libraries {(:id file) file}
|
||||
libraries (cond-> {(:id file) file}
|
||||
(some? library)
|
||||
(assoc (:id library) library))
|
||||
library (or library file)
|
||||
|
||||
orig-shapes (when keep-touched? (cfh/get-children-with-self (:objects page) (:id shape)))
|
||||
|
||||
@ -290,10 +397,10 @@
|
||||
(cll/generate-component-swap (pcb/empty-changes)
|
||||
(:objects page)
|
||||
shape
|
||||
(:data file)
|
||||
(:data library)
|
||||
page
|
||||
libraries
|
||||
(-> (thc/get-component file component-tag)
|
||||
(-> (thc/get-component library component-tag)
|
||||
:id)
|
||||
0
|
||||
nil
|
||||
@ -305,26 +412,36 @@
|
||||
[changes nil])
|
||||
|
||||
|
||||
file' (thf/apply-changes file changes)]
|
||||
file' (thf/apply-changes file changes :validate? (not propagate-fn))]
|
||||
(when new-shape-label
|
||||
(thi/rm-id! (:id new-shape))
|
||||
(thi/set-id! new-shape-label (:id new-shape)))
|
||||
(if propagate-fn
|
||||
(propagate-fn file')
|
||||
(-> (propagate-fn file')
|
||||
(thf/validate-file!))
|
||||
file')))
|
||||
|
||||
(defn swap-component-in-shape [file shape-tag component-tag & {:keys [page-label propagate-fn]}]
|
||||
(swap-component file (ths/get-shape file shape-tag :page-label page-label) component-tag :page-label page-label :propagate-fn propagate-fn))
|
||||
(defn swap-component-in-shape
|
||||
[file shape-tag component-tag & {:keys [page-label propagate-fn keep-touched? new-shape-label library]}]
|
||||
(swap-component- file (ths/get-shape file shape-tag :page-label page-label)
|
||||
component-tag
|
||||
:page-label page-label
|
||||
:propagate-fn propagate-fn
|
||||
:keep-touched? keep-touched?
|
||||
:new-shape-label new-shape-label
|
||||
:library library))
|
||||
|
||||
(defn swap-component-in-first-child [file shape-tag component-tag & {:keys [page-label propagate-fn]}]
|
||||
(defn swap-component-in-first-child
|
||||
[file shape-tag component-tag & {:keys [page-label propagate-fn library]}]
|
||||
(let [first-child-id (->> (ths/get-shape file shape-tag :page-label page-label)
|
||||
:shapes
|
||||
first)]
|
||||
(swap-component file
|
||||
(ths/get-shape-by-id file first-child-id :page-label page-label)
|
||||
component-tag
|
||||
:page-label page-label
|
||||
:propagate-fn propagate-fn)))
|
||||
(swap-component- file
|
||||
(ths/get-shape-by-id file first-child-id :page-label page-label)
|
||||
component-tag
|
||||
:page-label page-label
|
||||
:propagate-fn propagate-fn
|
||||
:library library)))
|
||||
|
||||
(defn update-color
|
||||
"Update the first fill color for the shape identified by shape-tag"
|
||||
@ -339,9 +456,10 @@
|
||||
(assoc shape :fills (ths/sample-fills-color :fill-color color)))
|
||||
(:objects page)
|
||||
{})
|
||||
file' (thf/apply-changes file changes)]
|
||||
file' (thf/apply-changes file changes :validate? (not propagate-fn))]
|
||||
(if propagate-fn
|
||||
(propagate-fn file')
|
||||
(-> (propagate-fn file')
|
||||
(thf/validate-file!))
|
||||
file')))
|
||||
|
||||
(defn update-bottom-color
|
||||
@ -357,9 +475,10 @@
|
||||
(assoc shape :fills (ths/sample-fills-color :fill-color color)))
|
||||
(:objects page)
|
||||
{})
|
||||
file' (thf/apply-changes file changes)]
|
||||
file' (thf/apply-changes file changes :validate? (not propagate-fn))]
|
||||
(if propagate-fn
|
||||
(propagate-fn file')
|
||||
(-> (propagate-fn file')
|
||||
(thf/validate-file!))
|
||||
file')))
|
||||
|
||||
(defn reset-overrides [file shape & {:keys [page-label propagate-fn]}]
|
||||
@ -374,9 +493,10 @@
|
||||
{file-id file}
|
||||
(ctn/make-container container :page)
|
||||
(:id shape)))
|
||||
file' (thf/apply-changes file changes)]
|
||||
file' (thf/apply-changes file changes :validate? (not propagate-fn))]
|
||||
(if propagate-fn
|
||||
(propagate-fn file')
|
||||
(-> (propagate-fn file')
|
||||
(thf/validate-file!))
|
||||
file')))
|
||||
|
||||
(defn reset-overrides-in-first-child [file shape-tag & {:keys [page-label propagate-fn]}]
|
||||
@ -398,9 +518,10 @@
|
||||
#{(-> (ths/get-shape file shape-tag :page-label page-label)
|
||||
:id)}
|
||||
{})
|
||||
file' (thf/apply-changes file changes)]
|
||||
file' (thf/apply-changes file changes :validate? (not propagate-fn))]
|
||||
(if propagate-fn
|
||||
(propagate-fn file')
|
||||
(-> (propagate-fn file')
|
||||
(thf/validate-file!))
|
||||
file')))
|
||||
|
||||
(defn duplicate-shape [file shape-tag & {:keys [page-label propagate-fn]}]
|
||||
@ -419,8 +540,9 @@
|
||||
(:id file)) ;; file-id
|
||||
(cll/generate-duplicate-changes-update-indices (:objects page) ;; objects
|
||||
#{(:id shape)}))
|
||||
file' (thf/apply-changes file changes)]
|
||||
file' (thf/apply-changes file changes :validate? (not propagate-fn))]
|
||||
(if propagate-fn
|
||||
(propagate-fn file')
|
||||
(-> (propagate-fn file')
|
||||
(thf/validate-file!))
|
||||
file')))
|
||||
|
||||
|
||||
@ -54,12 +54,14 @@
|
||||
([file] (validate-file! file {}))
|
||||
([file libraries]
|
||||
(cfv/validate-file-schema! file)
|
||||
(cfv/validate-file! file libraries)))
|
||||
(cfv/validate-file! file libraries)
|
||||
file))
|
||||
|
||||
(defn apply-changes
|
||||
[file changes]
|
||||
[file changes & {:keys [validate?] :or {validate? true}}]
|
||||
(let [file' (ctf/update-file-data file #(cfc/process-changes % (:redo-changes changes) true))]
|
||||
(validate-file! file')
|
||||
(when validate?
|
||||
(validate-file! file'))
|
||||
file'))
|
||||
|
||||
(defn apply-undo-changes
|
||||
|
||||
@ -82,6 +82,18 @@
|
||||
(:id page)
|
||||
#(ctst/set-shape % (ctn/set-shape-attr shape attr val)))))))
|
||||
|
||||
(defn update-shape-by-id
|
||||
[file shape-id attr val & {:keys [page-label]}]
|
||||
(let [page (if page-label
|
||||
(thf/get-page file page-label)
|
||||
(thf/current-page file))
|
||||
shape (ctst/get-shape page shape-id)]
|
||||
(update file :data
|
||||
(fn [file-data]
|
||||
(ctpl/update-page file-data
|
||||
(:id page)
|
||||
#(ctst/set-shape % (ctn/set-shape-attr shape attr val)))))))
|
||||
|
||||
(defn update-shape-text
|
||||
[file shape-label attr val & {:keys [page-label]}]
|
||||
(let [page (if page-label
|
||||
|
||||
@ -610,6 +610,36 @@
|
||||
[hsv]
|
||||
(-> hsv hsv->hex hex->hsl))
|
||||
|
||||
;; HSB (Hue, Saturation, Brightness) — same color model as HSV but with
|
||||
;; the brightness component normalized to a 0-100 range, matching Figma,
|
||||
;; Sketch, and Adobe XD conventions. Internally we reuse the HSV math and
|
||||
;; only rescale the brightness axis.
|
||||
|
||||
(defn rgb->hsb
|
||||
[rgb]
|
||||
(let [[h s v] (rgb->hsv rgb)]
|
||||
[h s (* (/ v 255.0) 100.0)]))
|
||||
|
||||
(defn hsb->rgb
|
||||
[[h s b]]
|
||||
(hsv->rgb [h s (int (* (/ b 100.0) 255.0))]))
|
||||
|
||||
(defn hex->hsb
|
||||
[v]
|
||||
(-> v hex->rgb rgb->hsb))
|
||||
|
||||
(defn hsb->hex
|
||||
[hsb]
|
||||
(-> hsb hsb->rgb rgb->hex))
|
||||
|
||||
(defn hsv->hsb
|
||||
[[h s v]]
|
||||
[h s (* (/ v 255.0) 100.0)])
|
||||
|
||||
(defn hsb->hsv
|
||||
[[h s b]]
|
||||
[h s (int (* (/ b 100.0) 255.0))])
|
||||
|
||||
(defn expand-hex
|
||||
[v]
|
||||
(cond
|
||||
|
||||
@ -163,11 +163,15 @@
|
||||
Note that design tokens also are involved, although they go by an alternate
|
||||
route and thus they are not part of :sync-attrs.
|
||||
Also when detaching a nested copy it also needs to trigger a synchronization,
|
||||
even though :shape-ref is not a synced attribute per se"
|
||||
even though :shape-ref, :component-id or :component-file are not synced
|
||||
attributes per se."
|
||||
[attr]
|
||||
(or (contains? sync-attrs attr)
|
||||
(= :shape-ref attr)
|
||||
(= :applied-tokens attr)))
|
||||
(= :applied-tokens attr)
|
||||
(= :component-id attr)
|
||||
(= :component-file attr)
|
||||
(= :component-root attr)))
|
||||
|
||||
(defn instance-root?
|
||||
"Check if this shape is the head of a top instance."
|
||||
|
||||
@ -60,6 +60,9 @@
|
||||
(some? objects)
|
||||
(assoc :objects objects)
|
||||
|
||||
(nil? objects)
|
||||
(dissoc :objects)
|
||||
|
||||
(some? modified-at)
|
||||
(assoc :modified-at modified-at)
|
||||
|
||||
|
||||
@ -55,6 +55,10 @@
|
||||
[page-or-component type]
|
||||
(assoc page-or-component :type type))
|
||||
|
||||
(defn unmake-container
|
||||
[container]
|
||||
(dissoc container :type))
|
||||
|
||||
(defn page?
|
||||
[container]
|
||||
(= (:type container) :page))
|
||||
|
||||
@ -204,7 +204,8 @@
|
||||
|
||||
(defn update-file-data
|
||||
[file f]
|
||||
(update file :data f))
|
||||
(when file
|
||||
(update file :data f)))
|
||||
|
||||
(defn containers-seq
|
||||
"Generate a sequence of all pages and all components, wrapped as containers"
|
||||
@ -225,6 +226,85 @@
|
||||
(ctpl/update-page file-data (:id container) f)
|
||||
(ctkl/update-component file-data (:id container) f)))
|
||||
|
||||
(defn update-pages
|
||||
"Update all pages inside the file"
|
||||
[file-data f]
|
||||
(update file-data :pages-index d/update-vals
|
||||
(fn [page]
|
||||
(-> page
|
||||
(ctn/make-container :page)
|
||||
(f)
|
||||
(ctn/unmake-container)))))
|
||||
|
||||
(defn update-components
|
||||
"Update all components inside the file"
|
||||
[file-data f]
|
||||
(d/update-when file-data :components d/update-vals
|
||||
(fn [component]
|
||||
(-> component
|
||||
(ctn/make-container :component)
|
||||
(f)
|
||||
(ctn/unmake-container)))))
|
||||
|
||||
(defn update-containers
|
||||
"Update all pages and components inside the file"
|
||||
[file-data f]
|
||||
(-> file-data
|
||||
(update-pages f)
|
||||
(update-components f)))
|
||||
|
||||
(defn update-objects-tree
|
||||
"Do a depth-first traversal of the shapes in a container, doing different kinds of updates.
|
||||
The function f receives a shape with a context metadata with the container.
|
||||
It must return a map with the following keys:
|
||||
- :result -> :keep, :update or :remove
|
||||
- :updated-shape -> the updated shape if result is :update"
|
||||
[container f]
|
||||
(letfn [(update-shape-recursive
|
||||
[container shape-id]
|
||||
(let [shape (ctst/get-shape container shape-id)]
|
||||
(when (not shape)
|
||||
(throw (ex-info "Shape not found" {:shape-id shape-id})))
|
||||
(let [shape (with-meta shape {:container container})
|
||||
|
||||
{:keys [result updated-shape]} (f shape)
|
||||
|
||||
container'
|
||||
(case result
|
||||
:keep
|
||||
container
|
||||
|
||||
:update
|
||||
(ctst/set-shape container updated-shape)
|
||||
|
||||
:remove
|
||||
(ctst/delete-shape container shape-id true)
|
||||
|
||||
(throw (ex-info "Invalid result from update function" {:result result})))]
|
||||
|
||||
(if (= result :remove)
|
||||
container'
|
||||
(reduce update-shape-recursive
|
||||
container'
|
||||
(:shapes shape))))))]
|
||||
|
||||
(let [root-id (if (ctn/page? container)
|
||||
uuid/zero
|
||||
(:main-instance-id container))]
|
||||
|
||||
(if-not (empty? (:objects container))
|
||||
(update-shape-recursive container root-id)
|
||||
container))))
|
||||
|
||||
(defn update-all-shapes
|
||||
"Update all shapes in the file data, using the update-objects-tree function for each container"
|
||||
[file-data f]
|
||||
(when file-data
|
||||
(update-containers
|
||||
file-data
|
||||
(fn [container]
|
||||
(update-objects-tree container f)))))
|
||||
|
||||
;; Asset helpers
|
||||
(defn find-component-file
|
||||
[file libraries component-file]
|
||||
@ -328,6 +408,27 @@
|
||||
(get-ref-shape (:data component-file) component shape :with-context? with-context?))))]
|
||||
(some find-ref-shape-in-head (ctn/get-parent-heads (:objects container) shape))))
|
||||
|
||||
(defn find-near-match
|
||||
"Locate the shape that occupies the same position in the near main component.
|
||||
This will be the ref-shape except if the shape is a copy subhead that has been
|
||||
swapped. In this case, the near match will be the ref-shape that was before
|
||||
the swap."
|
||||
[file container libraries shape & {:keys [include-deleted? with-context?] :or {include-deleted? false with-context? false}}]
|
||||
(let [parent-shape (ctst/get-shape container (:parent-id shape))
|
||||
parent-ref-shape (when parent-shape
|
||||
(find-ref-shape file container libraries parent-shape :include-deleted? include-deleted? :with-context? true))
|
||||
ref-container (when parent-ref-shape
|
||||
(:container (meta parent-ref-shape)))
|
||||
shape-index (when parent-shape
|
||||
(d/index-of (:shapes parent-shape) (:id shape)))
|
||||
near-match-id (when (and parent-ref-shape shape-index)
|
||||
(get (:shapes parent-ref-shape) shape-index))
|
||||
near-match (when near-match-id
|
||||
(cond-> (ctst/get-shape ref-container near-match-id)
|
||||
with-context?
|
||||
(with-meta (meta parent-ref-shape))))]
|
||||
near-match))
|
||||
|
||||
(defn advance-shape-ref
|
||||
"Get the shape-ref of the near main of the shape, recursively repeated as many times
|
||||
as the given levels."
|
||||
|
||||
50
common/src/app/common/types/organization.cljc
Normal file
50
common/src/app/common/types/organization.cljc
Normal file
@ -0,0 +1,50 @@
|
||||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;;
|
||||
;; Copyright (c) KALEIDOS INC
|
||||
|
||||
(ns app.common.types.organization
|
||||
(:require
|
||||
[app.common.schema :as sm]))
|
||||
|
||||
(def schema:organization
|
||||
[:map
|
||||
[:id ::sm/uuid]
|
||||
[:name ::sm/text]
|
||||
[:slug ::sm/text]
|
||||
[:owner-id ::sm/uuid]
|
||||
[:avatar-bg-url ::sm/uri]
|
||||
[:logo-id {:optional true} [:maybe ::sm/uuid]]])
|
||||
|
||||
|
||||
(def schema:team-with-organization
|
||||
[:map
|
||||
[:id ::sm/uuid]
|
||||
[:is-your-penpot :boolean]
|
||||
[:organization schema:organization]])
|
||||
|
||||
(def organization->team-keys
|
||||
"Mapping from organization field keys to their corresponding :organization-* team keys."
|
||||
[[:id :organization-id]
|
||||
[:name :organization-name]
|
||||
[:custom-photo :organization-custom-photo]
|
||||
[:slug :organization-slug]
|
||||
[:avatar-bg-url :organization-avatar-bg-url]
|
||||
[:owner-id :organization-owner-id]])
|
||||
|
||||
(defn apply-organization
|
||||
"Updates a team map with organization fields sourced from org.
|
||||
Associates each org field to the corresponding :organization-* team key when
|
||||
the value is non-nil; dissociates the key otherwise. This correctly handles
|
||||
both attaching an org (all values present) and detaching one (org is nil or
|
||||
all fields absent)."
|
||||
[team organization]
|
||||
(let [id (:id organization)]
|
||||
(reduce (fn [acc [org-k team-k]]
|
||||
(let [v (get organization org-k)]
|
||||
(if (and id (some? v))
|
||||
(assoc acc team-k v)
|
||||
(dissoc acc team-k))))
|
||||
team
|
||||
organization->team-keys)))
|
||||
@ -34,7 +34,8 @@
|
||||
[:id ::sm/uuid]
|
||||
[:axis [::sm/one-of #{:x :y}]]
|
||||
[:position ::sm/safe-number]
|
||||
[:frame-id {:optional true} [:maybe ::sm/uuid]]])
|
||||
[:frame-id {:optional true} [:maybe ::sm/uuid]]
|
||||
[:color {:optional true} [:maybe ctc/schema:hex-color]]])
|
||||
|
||||
(def schema:guides
|
||||
[:map-of {:gen/max 2} ::sm/uuid schema:guide])
|
||||
@ -58,6 +59,10 @@
|
||||
[:guides {:optional true} schema:guides]
|
||||
[:plugin-data {:optional true} ctpg/schema:plugin-data]
|
||||
[:background {:optional true} ctc/schema:hex-color]
|
||||
;; Per-page pixel grid color. Falls back to a hardcoded default when
|
||||
;; unset so existing files render identically to before.
|
||||
[:pixel-grid-color {:optional true} ctc/schema:hex-color]
|
||||
[:pixel-grid-opacity {:optional true} ::sm/safe-number]
|
||||
|
||||
[:comment-thread-positions {:optional true}
|
||||
[:map-of ::sm/uuid schema:comment-thread-position]]])
|
||||
|
||||
@ -84,6 +84,19 @@
|
||||
(-> (subpath/close-subpaths content)
|
||||
(impl/from-plain)))
|
||||
|
||||
(defn merge-touching-subpaths
|
||||
"Given a content, fold consecutive subpaths whose endpoints coincide
|
||||
into a single continuous subpath, returning a PathData instance.
|
||||
|
||||
Conservative counterpart of `close-subpaths`: only adjacent subpaths
|
||||
are merged and none are reversed, so fill rules and stroke-dasharray
|
||||
semantics are preserved. Used at SVG-import time on stroke-only paths
|
||||
to recover the `stroke-linejoin` rendering when authoring tools split
|
||||
a continuous polyline into adjacent `M..L M..L` subpaths."
|
||||
[content]
|
||||
(-> (subpath/merge-touching-subpaths content)
|
||||
(impl/from-plain)))
|
||||
|
||||
(defn apply-content-modifiers
|
||||
"Apply delta modifiers over the path content"
|
||||
[content modifiers]
|
||||
|
||||
@ -128,6 +128,36 @@
|
||||
(def ^:private xf-mapcat-data
|
||||
(mapcat :data))
|
||||
|
||||
(defn- join-adjacent
|
||||
"Fold neighbouring subpaths into the accumulator only when the
|
||||
current accumulator's end-point matches the next subpath's start-point.
|
||||
Unlike `merge-paths` this does not reverse subpaths nor reorder them;
|
||||
the original draw order is preserved so stroke-dasharray and animation
|
||||
semantics stay intact."
|
||||
[acc subpath]
|
||||
(if-let [prev (peek acc)]
|
||||
(if (and (not (is-closed? prev))
|
||||
(not (is-closed? subpath))
|
||||
(pt= (:to prev) (:from subpath)))
|
||||
(conj (pop acc) (subpaths-join prev subpath))
|
||||
(conj acc subpath))
|
||||
(conj acc subpath)))
|
||||
|
||||
(defn merge-touching-subpaths
|
||||
"Merge consecutive subpaths whose endpoints coincide into a single
|
||||
continuous subpath, preserving the original drawing order.
|
||||
|
||||
This is a conservative variant of `close-subpaths`: it never reverses
|
||||
a subpath and only merges immediate neighbours, so closed regions and
|
||||
fill semantics are left untouched. The intent is to recover the
|
||||
`stroke-linejoin` rendering for SVG paths whose authoring tools split
|
||||
a continuous polyline into adjacent `M..L M..L` subpaths (e.g. the
|
||||
`m0 0` markers Figma emits when exporting Heroicons-like icons)."
|
||||
[content]
|
||||
(let [subpaths (get-subpaths content)
|
||||
merged (reduce join-adjacent [] subpaths)]
|
||||
(into [] xf-mapcat-data merged)))
|
||||
|
||||
(defn close-subpaths
|
||||
"Searches a path for possible subpaths that can create closed loops and merge them"
|
||||
[content]
|
||||
|
||||
@ -145,7 +145,8 @@
|
||||
[::sm/one-of stroke-caps]]
|
||||
[:stroke-color {:optional true} clr/schema:hex-color]
|
||||
[:stroke-color-gradient {:optional true} clr/schema:gradient]
|
||||
[:stroke-image {:optional true} clr/schema:image]])
|
||||
[:stroke-image {:optional true} clr/schema:image]
|
||||
[:hidden {:optional true} :boolean]])
|
||||
|
||||
(def stroke-attrs
|
||||
"A set of attrs that corresponds to stroke data type"
|
||||
|
||||
@ -874,6 +874,42 @@
|
||||
(duplicate-cells :column index (inc index) ids-map)
|
||||
(assign-cells objects))))
|
||||
|
||||
(defn duplicate-row-at
|
||||
"Duplicate source row and insert the copy at target-index (0-indexed).
|
||||
Like `duplicate-row` but inserts at an arbitrary position.
|
||||
Note: after add-grid-row, if target <= source the source cells shift
|
||||
by +1, so we must adjust the from-index for duplicate-cells."
|
||||
[shape objects source-index target-index ids-map]
|
||||
(let [value (dm/get-in shape [:layout-grid-rows source-index])
|
||||
;; After inserting at target-index, cells at rows >= (inc target-index)
|
||||
;; get shifted +1. If target <= source, the source row shifts.
|
||||
adjusted-source (if (<= target-index source-index)
|
||||
(inc source-index)
|
||||
source-index)]
|
||||
(-> shape
|
||||
(remove-cell-areas-after :row source-index)
|
||||
(add-grid-row value target-index)
|
||||
(duplicate-cells :row adjusted-source target-index ids-map)
|
||||
(assign-cells objects))))
|
||||
|
||||
(defn duplicate-column-at
|
||||
"Duplicate source column and insert the copy at target-index (0-indexed).
|
||||
Like `duplicate-column` but inserts at an arbitrary position.
|
||||
Note: after add-grid-column, if target <= source the source cells shift
|
||||
by +1, so we must adjust the from-index for duplicate-cells."
|
||||
[shape objects source-index target-index ids-map]
|
||||
(let [value (dm/get-in shape [:layout-grid-columns source-index])
|
||||
;; After inserting at target-index, cells at columns >= (inc target-index)
|
||||
;; get shifted +1. If target <= source, the source column shifts.
|
||||
adjusted-source (if (<= target-index source-index)
|
||||
(inc source-index)
|
||||
source-index)]
|
||||
(-> shape
|
||||
(remove-cell-areas-after :column source-index)
|
||||
(add-grid-column value target-index)
|
||||
(duplicate-cells :column adjusted-source target-index ids-map)
|
||||
(assign-cells objects))))
|
||||
|
||||
(defn make-remove-cell
|
||||
[attr span-attr track-num]
|
||||
(fn [[_ cell]]
|
||||
|
||||
@ -16,8 +16,6 @@
|
||||
[app.common.types.shape.layout :as ctl]
|
||||
[app.common.uuid :as uuid]))
|
||||
|
||||
|
||||
;; FIXME: the order of arguments seems arbitrary, container should be a first artgument
|
||||
(defn add-shape
|
||||
"Insert a shape in the tree, at the given index below the given parent or frame.
|
||||
Update the parent as needed."
|
||||
|
||||
@ -32,3 +32,4 @@
|
||||
[:id ::sm/uuid]
|
||||
[:name :string]])
|
||||
|
||||
|
||||
|
||||
@ -356,6 +356,32 @@
|
||||
[k (get attrs k v)]))))
|
||||
|
||||
|
||||
(defn content-has-text?
|
||||
[content search]
|
||||
(let [search-lower (str/lower search)]
|
||||
(->> (node-seq is-text-node? content)
|
||||
(some #(str/includes? (str/lower (:text %)) search-lower))
|
||||
(boolean))))
|
||||
|
||||
(defn replace-all-case-insensitive
|
||||
[text search replacement]
|
||||
(let [text-lower (str/lower text)
|
||||
search-lower (str/lower search)
|
||||
search-len (count search)]
|
||||
(loop [result "" idx 0]
|
||||
(let [found (str/index-of text-lower search-lower idx)]
|
||||
(if (nil? found)
|
||||
(str result (subs text idx))
|
||||
(recur (str result (subs text idx found) replacement)
|
||||
(+ found search-len)))))))
|
||||
|
||||
(defn replace-text-in-content
|
||||
[content search replacement]
|
||||
(transform-nodes
|
||||
is-text-node?
|
||||
(fn [node] (update node :text replace-all-case-insensitive search replacement))
|
||||
content))
|
||||
|
||||
(defn content->text
|
||||
"Given a root node of a text content extracts the texts with its associated styles"
|
||||
[content]
|
||||
|
||||
@ -136,6 +136,9 @@
|
||||
(def token-name-validation-regex
|
||||
#"^[a-zA-Z0-9_-][a-zA-Z0-9$_-]*(\.[a-zA-Z0-9$_-]+)*$")
|
||||
|
||||
(def token-node-name-validation-regex
|
||||
#"^[a-zA-Z0-9_-][a-zA-Z0-9$_-]*(\.[a-zA-Z0-9$_-]+)*$")
|
||||
|
||||
(def schema:token-name
|
||||
"A token name can contains letters, numbers, underscores the character $ and dots, but
|
||||
not start with $ or end with a dot. The $ character does not have any special meaning,
|
||||
@ -153,6 +156,14 @@
|
||||
:gen/gen sg/text}
|
||||
token-ref-validation-regex])
|
||||
|
||||
(def schema:token-node-name
|
||||
"A token node name can contains letters, numbers, underscores and the character $, but
|
||||
not start with $ or a dot, or end with a dot. The $ character does not have any special meaning,
|
||||
but dots separate token groups (e.g. color.primary.background)."
|
||||
[:re {:title "TokenNodeName"
|
||||
:gen/gen sg/text}
|
||||
token-node-name-validation-regex])
|
||||
|
||||
(def schema:token-type
|
||||
[::sm/one-of {:decode/json (fn [type]
|
||||
(if (string? type)
|
||||
@ -521,31 +532,32 @@
|
||||
|
||||
(def tokens-by-input
|
||||
"A map from input name to applicable token for that input."
|
||||
{:width #{:sizing :dimensions}
|
||||
:height #{:sizing :dimensions}
|
||||
:max-width #{:sizing :dimensions}
|
||||
:max-height #{:sizing :dimensions}
|
||||
:min-width #{:sizing :dimensions}
|
||||
:min-height #{:sizing :dimensions}
|
||||
:x #{:dimensions}
|
||||
:y #{:dimensions}
|
||||
:rotation #{:number :rotation}
|
||||
:border-radius #{:border-radius :dimensions}
|
||||
:row-gap #{:spacing :dimensions}
|
||||
:column-gap #{:spacing :dimensions}
|
||||
:horizontal-padding #{:spacing :dimensions}
|
||||
:vertical-padding #{:spacing :dimensions}
|
||||
:sided-paddings #{:spacing :dimensions}
|
||||
:horizontal-margin #{:spacing :dimensions}
|
||||
:vertical-margin #{:spacing :dimensions}
|
||||
:sided-margins #{:spacing :dimensions}
|
||||
:line-height #{:line-height :number}
|
||||
:opacity #{:opacity}
|
||||
:stroke-width #{:stroke-width :dimensions}
|
||||
:font-size #{:font-size}
|
||||
:letter-spacing #{:letter-spacing}
|
||||
:fill #{:color}
|
||||
:stroke-color #{:color}})
|
||||
{:width [:sizing :dimensions]
|
||||
:height [:sizing :dimensions]
|
||||
:max-width [:sizing :dimensions]
|
||||
:max-height [:sizing :dimensions]
|
||||
:min-width [:sizing :dimensions]
|
||||
:min-height [:sizing :dimensions]
|
||||
:x [:dimensions]
|
||||
:y [:dimensions]
|
||||
:rotation [:rotation :number]
|
||||
:border-radius [:border-radius :dimensions]
|
||||
:row-gap [:spacing :dimensions]
|
||||
:column-gap [:spacing :dimensions]
|
||||
:horizontal-padding [:spacing :dimensions]
|
||||
:vertical-padding [:spacing :dimensions]
|
||||
:sided-paddings [:spacing :dimensions]
|
||||
:horizontal-margin [:spacing :dimensions]
|
||||
:vertical-margin [:spacing :dimensions]
|
||||
:sided-margins [:spacing :dimensions]
|
||||
:line-height [:line-height :number]
|
||||
:opacity [:opacity]
|
||||
:stroke-width [:stroke-width :dimensions]
|
||||
:font-size [:font-size]
|
||||
:letter-spacing [:letter-spacing]
|
||||
:fill [:color]
|
||||
:stroke-color [:color]
|
||||
:typography [:typography]})
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; HELPERS for tokens application
|
||||
|
||||
@ -153,6 +153,18 @@
|
||||
tokens)]
|
||||
(group-by :type tokens')))
|
||||
|
||||
(defn rename-path
|
||||
"Renames a node or token path segment with a new name.
|
||||
If token is provided, it renames a token path, otherwise it renames a node path."
|
||||
([node new-name]
|
||||
(rename-path node nil new-name))
|
||||
([node token new-name]
|
||||
(let [element (if token (:name token) (:path node))
|
||||
split-path (cpn/split-path element :separator ".")
|
||||
updated-split-element-name (assoc split-path (:depth node) new-name)
|
||||
new-element-path (cpn/join-path updated-split-element-name :separator "." :with-spaces? false)]
|
||||
new-element-path)))
|
||||
|
||||
;; === Token Set
|
||||
|
||||
(defprotocol ITokenSet
|
||||
@ -920,6 +932,7 @@ Will return a value that matches this schema:
|
||||
`:all` All of the nested sets are active
|
||||
`:partial` Mixed active state of nested sets")
|
||||
(get-tokens-in-active-sets [_] "set of set names that are active in the the active themes")
|
||||
(get-tokens-in-active-sets-force [_ force-set-id] "same as above but forcing a set to be active, even if it's not in the active themes")
|
||||
(get-all-tokens [_] "all tokens in the lib, as a sequence")
|
||||
(get-all-tokens-map [_] "all tokens in the lib, as a map name -> token")
|
||||
(get-tokens [_ set-id] "return a map of tokens in the set, indexed by token-name"))
|
||||
@ -1317,6 +1330,21 @@ Will return a value that matches this schema:
|
||||
active-set-names)]
|
||||
tokens))
|
||||
|
||||
(get-tokens-in-active-sets-force [this force-set-id]
|
||||
(let [theme-set-names (get-active-themes-set-names this)
|
||||
all-set-names (get-set-names this)
|
||||
force-set (get-set this force-set-id)
|
||||
active-set-names (cond-> (filter theme-set-names all-set-names)
|
||||
(some? force-set)
|
||||
(conj (get-name force-set)))
|
||||
|
||||
tokens (reduce (fn [tokens set-name]
|
||||
(let [set (get-set-by-name this set-name)]
|
||||
(merge tokens (get-tokens- set))))
|
||||
(d/ordered-map)
|
||||
active-set-names)]
|
||||
tokens))
|
||||
|
||||
(get-all-tokens [this]
|
||||
(mapcat #(vals (get-tokens- %))
|
||||
(get-sets this)))
|
||||
@ -1493,6 +1521,30 @@ Will return a value that matches this schema:
|
||||
(seq)
|
||||
(boolean)))))
|
||||
|
||||
(defn update-tokens-group
|
||||
"Updates the active tokens path when renaming a group node.
|
||||
- Filters tokens whose path matches the current path prefix
|
||||
- Replaces the token name with the new name
|
||||
- Updates the :path value in the token object
|
||||
|
||||
active-tokens: map of token-name to token-object for all active tokens in the set
|
||||
current-path: the path of the group being renamed, e.g. \"foo.bar\"
|
||||
current-name: the current name of the group being renamed, e.g. \"bar\"
|
||||
new-name: the new name for the group being renamed, e.g. \"baz\""
|
||||
|
||||
[active-tokens current-path current-name new-name]
|
||||
(let [path-prefix (str/replace current-path current-name "")]
|
||||
(mapv (fn [[token-path token-obj]]
|
||||
(if (str/starts-with? token-path path-prefix)
|
||||
(let [new-token-path (str/replace token-path current-name new-name)
|
||||
new-token-obj (-> token-obj
|
||||
(assoc :name new-token-path)
|
||||
(cond-> (:path token-obj)
|
||||
(assoc :path (str/replace (:path token-obj) current-name new-name))))]
|
||||
[new-token-path new-token-obj])
|
||||
[token-path token-obj]))
|
||||
active-tokens)))
|
||||
|
||||
;; === Import / Export from JSON format
|
||||
|
||||
;; Supported formats:
|
||||
|
||||
@ -60,8 +60,9 @@
|
||||
:cljs (uuid (impl/v4))))
|
||||
|
||||
(defn custom
|
||||
([a] #?(:clj (UUID. 0 a) :cljs (uuid (impl/custom 0 a))))
|
||||
([b a] #?(:clj (UUID. b a) :cljs (uuid (impl/custom b a)))))
|
||||
"Generate a uuid using directly the given number (specified as one or two long integers)"
|
||||
([low] #?(:clj (UUID. 0 low) :cljs (uuid (impl/custom 0 low))))
|
||||
([high low] #?(:clj (UUID. high low) :cljs (uuid (impl/custom high low)))))
|
||||
|
||||
(def zero (uuid "00000000-0000-0000-0000-000000000000"))
|
||||
|
||||
@ -137,6 +138,22 @@
|
||||
(+ (clojure.lang.Murmur3/hashLong a)
|
||||
(clojure.lang.Murmur3/hashLong b)))))
|
||||
|
||||
;; Fake uuids generator
|
||||
(def ^:private fake-ids (atom 0))
|
||||
|
||||
(defn reset-fake!
|
||||
"Reset the fake uuid counter to 0, for reproducible results across tests."
|
||||
[]
|
||||
(reset! fake-ids 0))
|
||||
|
||||
(defn next-fake
|
||||
"When you need predictable uuids, for example when debugging a failing test, wrap the code with
|
||||
(with-redefs [uuid/next uuid/next-fake]
|
||||
...tested code...)"
|
||||
[]
|
||||
(-> (swap! fake-ids inc)
|
||||
(custom)))
|
||||
|
||||
;; Commented code used for debug
|
||||
;; #?(:cljs
|
||||
;; (defn ^:export test-uuid
|
||||
|
||||
@ -28,6 +28,14 @@
|
||||
(t/is (not (d/in-range? 5 -1)))
|
||||
(t/is (not (d/in-range? 0 0))))
|
||||
|
||||
(t/deftest get-initials-test
|
||||
(t/is (= "JD" (d/get-initials "John Doe")))
|
||||
(t/is (= "A" (d/get-initials "acme")))
|
||||
(t/is (= "AB" (d/get-initials "123 Alpha ## beta")))
|
||||
(t/is (= "PD" (d/get-initials " penpot design tool ")))
|
||||
(t/is (= "" (d/get-initials nil)))
|
||||
(t/is (= "" (d/get-initials "!!! ???"))))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Ordered Data Structures
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
@ -276,6 +284,48 @@
|
||||
(t/is (= (d/nth-index-of "abc*def*ghi" "*" 2) 7))
|
||||
(t/is (= (d/nth-index-of "abc*def*ghi" "*" 3) nil)))
|
||||
|
||||
(t/deftest natural-sort-by-test
|
||||
(t/is (= (d/natural-sort-by identity ["10" "2" "1" "11" "3" "30"])
|
||||
["1" "2" "3" "10" "11" "30"]))
|
||||
(t/is (= (d/natural-sort-by identity ["banana" "apple" "cherry"])
|
||||
["apple" "banana" "cherry"]))
|
||||
(t/is (= (d/natural-sort-by identity ["size10" "size2" "size1" "size20" "size3"])
|
||||
["size1" "size2" "size3" "size10" "size20"]))
|
||||
(t/is (= (d/natural-sort-by identity ["b1" "a2" "a10" "a1"])
|
||||
["a1" "a2" "a10" "b1"]))
|
||||
(t/is (= (d/natural-sort-by identity []) []))
|
||||
(t/is (= (d/natural-sort-by identity ["solo"]) ["solo"]))
|
||||
(t/is (= (d/natural-sort-by identity ["b" "a" "a" "c"])
|
||||
["a" "a" "b" "c"]))
|
||||
(t/is (= (d/natural-sort-by :name
|
||||
[{:name "big"} {:name "small"} {:name "medium"}])
|
||||
[{:name "big"} {:name "medium"} {:name "small"}]))
|
||||
(t/is (= (d/natural-sort-by :name
|
||||
[{:name "size10"} {:name "size2"} {:name "size1"}])
|
||||
[{:name "size1"} {:name "size2"} {:name "size10"}]))
|
||||
(t/is (= (d/natural-sort-by :name
|
||||
[{:name "border-radius-10"}
|
||||
{:name "border-radius-2"}
|
||||
{:name "border-radius-1"}])
|
||||
[{:name "border-radius-1"}
|
||||
{:name "border-radius-2"}
|
||||
{:name "border-radius-10"}]))
|
||||
(t/is (= (d/natural-sort-by :name
|
||||
[{:name "border-10-radius"}
|
||||
{:name "border-2-radius"}
|
||||
{:name "border-1-radius"}])
|
||||
[{:name "border-1-radius"}
|
||||
{:name "border-2-radius"}
|
||||
{:name "border-10-radius"}]))
|
||||
(t/is (= (d/natural-sort-by :name
|
||||
[{:name "border-10-radius"}
|
||||
{:name "border-2-extra"}
|
||||
{:name "border-2-radius"}
|
||||
{:name "border-1-radius"}])
|
||||
[{:name "border-1-radius"}
|
||||
{:name "border-2-extra"}
|
||||
{:name "border-2-radius"}
|
||||
{:name "border-10-radius"}])))
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Lazy / sequence helpers
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
787
common/test/common_tests/files/comp_processors_test.cljc
Normal file
787
common/test/common_tests/files/comp_processors_test.cljc
Normal file
@ -0,0 +1,787 @@
|
||||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;;
|
||||
;; Copyright (c) KALEIDOS INC
|
||||
|
||||
(ns common-tests.files.comp-processors-test
|
||||
(:require
|
||||
[app.common.data :as d]
|
||||
[app.common.files.comp-processors :as cfcp]
|
||||
[app.common.test-helpers.components :as thc]
|
||||
[app.common.test-helpers.compositions :as tho]
|
||||
[app.common.test-helpers.files :as thf]
|
||||
[app.common.test-helpers.ids-map :as thi]
|
||||
[app.common.test-helpers.shapes :as ths]
|
||||
[app.common.types.component :as ctk]
|
||||
[app.common.types.components-list :as ctkl]
|
||||
[app.common.types.file :as ctf]
|
||||
[clojure.test :as t]))
|
||||
|
||||
(t/deftest test-remove-unneeded-objects-in-components
|
||||
|
||||
(t/testing "nil file should return nil"
|
||||
(let [file nil
|
||||
file' (ctf/update-file-data file cfcp/remove-unneeded-objects-in-components)]
|
||||
(t/is (nil? file'))))
|
||||
|
||||
(t/testing "empty file should not need any action"
|
||||
(let [file (thf/sample-file :file1)
|
||||
file' (ctf/update-file-data file cfcp/remove-unneeded-objects-in-components)]
|
||||
(t/is (empty? (d/map-diff file file')))))
|
||||
|
||||
(t/testing "file without components should not need any action"
|
||||
(let [file
|
||||
(-> (thf/sample-file :file1)
|
||||
(tho/add-frame-with-child :frame1 :shape1))
|
||||
|
||||
file' (ctf/update-file-data file cfcp/remove-unneeded-objects-in-components)]
|
||||
|
||||
(t/is (empty? (d/map-diff file file')))))
|
||||
|
||||
(t/testing "file with non deleted components should not need any action"
|
||||
(let [file
|
||||
(-> (thf/sample-file :file1)
|
||||
(tho/add-simple-component :component1 :frame1 :shape1))
|
||||
|
||||
file' (ctf/update-file-data file cfcp/remove-unneeded-objects-in-components)]
|
||||
|
||||
(t/is (empty? (d/map-diff file file')))))
|
||||
|
||||
(t/testing "file with deleted components should not need any action"
|
||||
(let [file
|
||||
(-> (thf/sample-file :file1)
|
||||
(tho/add-simple-component :component1 :frame1 :shape1)
|
||||
(tho/delete-shape :frame1))
|
||||
|
||||
file' (ctf/update-file-data file cfcp/remove-unneeded-objects-in-components)]
|
||||
|
||||
(t/is (empty? (d/map-diff file file')))))
|
||||
|
||||
(t/testing "file with non deleted components with :objects nil should remove it"
|
||||
(let [file
|
||||
(-> (thf/sample-file :file1)
|
||||
(tho/add-simple-component :component1 :frame1 :shape1)
|
||||
(thc/update-component :component1 {:objects nil}))
|
||||
|
||||
file' (ctf/update-file-data file cfcp/remove-unneeded-objects-in-components)
|
||||
|
||||
diff (d/map-diff file file')
|
||||
|
||||
expected-diff {:data
|
||||
{:components
|
||||
{(thi/id :component1)
|
||||
{}}}}]
|
||||
|
||||
(t/is (= expected-diff diff))))
|
||||
|
||||
(t/testing "file with non deleted components with :objects should remove it"
|
||||
(let [file
|
||||
(-> (thf/sample-file :file1)
|
||||
(tho/add-simple-component :component1 :frame1 :shape1)
|
||||
(thc/update-component :component1 {:objects {:sample 777}}))
|
||||
|
||||
file' (ctf/update-file-data file cfcp/remove-unneeded-objects-in-components)
|
||||
|
||||
diff (d/map-diff file file')
|
||||
|
||||
expected-diff {:data
|
||||
{:components
|
||||
{(thi/id :component1)
|
||||
{:objects
|
||||
[{:sample 777} nil]}}}}]
|
||||
|
||||
(t/is (= expected-diff diff))))
|
||||
|
||||
(t/testing "file with deleted components without :objects should add an empty one"
|
||||
(let [file
|
||||
(-> (thf/sample-file :file1)
|
||||
(tho/add-simple-component :component1 :frame1 :shape1)
|
||||
(tho/delete-shape :frame1)
|
||||
(ctf/update-file-data
|
||||
(fn [file-data]
|
||||
(ctkl/update-component file-data (thi/id :component1) #(dissoc % :objects)))))
|
||||
|
||||
file' (ctf/update-file-data file cfcp/remove-unneeded-objects-in-components)
|
||||
|
||||
diff (d/map-diff file file')
|
||||
|
||||
expected-diff {:data
|
||||
{:components
|
||||
{(thi/id :component1)
|
||||
{:objects
|
||||
[nil {}]}}}}]
|
||||
|
||||
(t/is (= expected-diff diff)))))
|
||||
|
||||
(t/deftest test-fix-missing-swap-slots
|
||||
|
||||
(t/testing "nil file should return nil"
|
||||
(let [file nil
|
||||
file' (ctf/update-file-data file #(cfcp/fix-missing-swap-slots % {}))]
|
||||
(t/is (nil? file'))))
|
||||
|
||||
(t/testing "empty file should not need any action"
|
||||
(let [file (thf/sample-file :file1)
|
||||
file' (ctf/update-file-data file #(cfcp/fix-missing-swap-slots % {}))]
|
||||
(t/is (empty? (d/map-diff file file')))))
|
||||
|
||||
(t/testing "file without components should not need any action"
|
||||
(let [file
|
||||
;; :frame1 [:name Frame1]
|
||||
;; :child1 [:name Rect1]
|
||||
(-> (thf/sample-file :file1)
|
||||
(tho/add-frame-with-child :frame1 :shape1))
|
||||
|
||||
file' (ctf/update-file-data file #(cfcp/fix-missing-swap-slots % {}))]
|
||||
|
||||
(t/is (empty? (d/map-diff file file')))))
|
||||
|
||||
(t/testing "file with nested not swapped components should not need any action"
|
||||
(let [file
|
||||
;; {:main1-root} [:name Frame1] # [Component :component1]
|
||||
;; :main1-child [:name Rect1]
|
||||
;;
|
||||
;; {:main2-root} [:name Frame2] # [Component :component2]
|
||||
;; :nested-head [:name Frame1] @--> [Component :component1] :main1-root
|
||||
;; <no-label> [:name Rect1] ---> :main1-child
|
||||
;;
|
||||
;; :copy2-root [:name Frame2] #--> [Component :component2] :main2-root
|
||||
;; <no-label> [:name Frame1] @--> [Component :component1] :nested-head
|
||||
;; <no-label> [:name Rect1] ---> <no-label>
|
||||
(-> (thf/sample-file :file1)
|
||||
(tho/add-nested-component-with-copy :component1 :main1-root :main1-child
|
||||
:component2 :main2-root :nested-head
|
||||
:copy2-root))
|
||||
|
||||
file' (ctf/update-file-data file #(cfcp/fix-missing-swap-slots % {}))]
|
||||
|
||||
(t/is (empty? (d/map-diff file file')))))
|
||||
|
||||
(t/testing "file with a normally swapped copy should not need any action"
|
||||
(let [file
|
||||
;; {:main1-root} [:name Frame1] # [Component :component1]
|
||||
;; :main1-child [:name Rect1]
|
||||
;;
|
||||
;; {:main2-root} [:name Frame2] # [Component :component2]
|
||||
;; :nested-head [:name Frame1] @--> [Component :component1] :main1-root
|
||||
;; <no-label> [:name Rect1] ---> :main1-child
|
||||
;;
|
||||
;; {:main3-root} [:name Frame3] # [Component :component3]
|
||||
;; :main3-child [:name Rect3]
|
||||
;;
|
||||
;; :copy2-root [:name Frame2] #--> [Component :component2] :main2-root
|
||||
;; :copy2-nested-head [:name Frame3] @--> [Component :component3] :main3-root
|
||||
;; {swap-slot :nested-head}
|
||||
;; <no-label> [:name Rect3] ---> :main3-child
|
||||
(-> (thf/sample-file :file1)
|
||||
(tho/add-nested-component :component1 :main1-root :main1-child
|
||||
:component2 :main2-root :nested-head)
|
||||
(thc/instantiate-component :component2 :copy2-root :children-labels [:copy2-nested-head])
|
||||
(tho/add-simple-component :component3 :main3-root :main3-child
|
||||
:root-params {:name "Frame3"}
|
||||
:child-params {:name "Rect3"})
|
||||
(tho/swap-component-in-first-child :copy2-root :component3))
|
||||
|
||||
file' (ctf/update-file-data file #(cfcp/fix-missing-swap-slots % {}))]
|
||||
|
||||
(t/is (empty? (d/map-diff file file')))))
|
||||
|
||||
(t/testing "file with a swapped nested copy in a main should not need any action"
|
||||
(let [file
|
||||
;; {:main1-root} [:name Frame1] # [Component :component1]
|
||||
;; :main1-child [:name Rect1]
|
||||
;;
|
||||
;; {:main3-root} [:name Frame3] # [Component :component3]
|
||||
;; :main3-child [:name Rect3]
|
||||
;;
|
||||
;; {:main2-root} [:name Frame2] # [Component :component2]
|
||||
;; :nested-head [:name Frame3] @--> [Component :component3] :main3-root
|
||||
;; {swap-slot :nested-head}
|
||||
;; <no-label> [:name Rect3] ---> :main3-child
|
||||
;;
|
||||
;; :copy2-root [:name Frame2] #--> [Component :component2] :main2-root
|
||||
;; :copy2-nested-head [:name Frame3] @--> [Component :component3] :nested-head
|
||||
;; <no-label> [:name Rect3] ---> <no-label>
|
||||
(-> (thf/sample-file :file1)
|
||||
(tho/add-nested-component :component1 :main1-root :main1-child
|
||||
:component2 :main2-root :nested-head)
|
||||
(thc/instantiate-component :component2 :copy2-root :children-labels [:copy2-nested-head])
|
||||
(tho/add-simple-component :component3 :main3-root :main3-child
|
||||
:root-params {:name "Frame3"}
|
||||
:child-params {:name "Rect3"})
|
||||
(tho/swap-component-in-shape :nested-head :component3
|
||||
:propagate-fn #(tho/propagate-component-changes % :component2)))
|
||||
|
||||
file' (ctf/update-file-data file #(cfcp/fix-missing-swap-slots % {}))]
|
||||
|
||||
(t/is (empty? (d/map-diff file file')))))
|
||||
|
||||
(t/testing "file with a swapped copy with broken slot should have it repaired"
|
||||
(let [file
|
||||
;; {:main1-root} [:name Frame1] # [Component :component1]
|
||||
;; :main1-child [:name Rect1]
|
||||
;;
|
||||
;; {:main2-root} [:name Frame2] # [Component :component2]
|
||||
;; :nested-head [:name Frame1] @--> [Component :component1] :main1-root
|
||||
;; <no-label> [:name Rect1] ---> :main1-child
|
||||
;;
|
||||
;; {:main3-root} [:name Frame3] # [Component :component3]
|
||||
;; :main3-child [:name Rect3]
|
||||
;;
|
||||
;; :copy2-root [:name Frame2] #--> [Component :component2] :main2-root
|
||||
;; :copy2-nested-head [:name Frame3] @--> [Component :component3] :main3-root
|
||||
;; NO SWAP SLOT
|
||||
;; <no-label> [:name Rect3] ---> :main3-child
|
||||
(-> (thf/sample-file :file1)
|
||||
(tho/add-nested-component :component1 :main1-root :main1-child
|
||||
:component2 :main2-root :nested-head)
|
||||
(thc/instantiate-component :component2 :copy2-root :children-labels [:copy2-nested-head])
|
||||
(tho/add-simple-component :component3 :main3-root :main3-child
|
||||
:root-params {:name "Frame3"}
|
||||
:child-params {:name "Rect3"})
|
||||
(tho/swap-component-in-first-child :copy2-root :component3)
|
||||
(ths/update-shape :copy2-nested-head :touched nil))
|
||||
|
||||
file' (ctf/update-file-data file #(cfcp/fix-missing-swap-slots % {}))
|
||||
|
||||
diff (d/map-diff file file')
|
||||
|
||||
expected-diff {:data
|
||||
{:pages-index
|
||||
{(thf/current-page-id file)
|
||||
{:objects
|
||||
{(thi/id :copy2-nested-head)
|
||||
{:touched
|
||||
[nil
|
||||
#{(ctk/build-swap-slot-group (str (thi/id :nested-head)))}]}}}}}}]
|
||||
|
||||
(t/is (= expected-diff diff))))
|
||||
|
||||
(t/testing "file with a swapped copy inside a main with broken slot has no effect since it cannot be distinguished"
|
||||
(let [file
|
||||
;; {:main1-root} [:name Frame1] # [Component :component1]
|
||||
;; :main1-child [:name Rect1]
|
||||
;;
|
||||
;; {:main3-root} [:name Frame3] # [Component :component3]
|
||||
;; :main3-child [:name Rect3]
|
||||
;;
|
||||
;; {:main2-root} [:name Frame2] # [Component :component2]
|
||||
;; :nested-head [:name Frame3] @--> [Component :component3] :main3-root
|
||||
;; NO SWAP SLOT
|
||||
;; <no-label> [:name Rect3] ---> :main3-child
|
||||
;;
|
||||
;; :copy2-root [:name Frame2] #--> [Component :component2] :main2-root
|
||||
;; :copy2-nested-head [:name Frame3] @--> [Component :component3] :nested-head
|
||||
;; <no-label> [:name Rect3] ---> <no-label>
|
||||
(-> (thf/sample-file :file1)
|
||||
(tho/add-nested-component :component1 :main1-root :main1-child
|
||||
:component2 :main2-root :nested-head)
|
||||
(thc/instantiate-component :component2 :copy2-root :children-labels [:copy2-nested-head])
|
||||
(tho/add-simple-component :component3 :main3-root :main3-child
|
||||
:root-params {:name "Frame3"}
|
||||
:child-params {:name "Rect3"})
|
||||
(tho/swap-component-in-shape :nested-head :component3
|
||||
:propagate-fn #(tho/propagate-component-changes % :component2))
|
||||
(ths/update-shape :nested-head :touched nil))
|
||||
|
||||
file' (ctf/update-file-data file #(cfcp/fix-missing-swap-slots % {}))]
|
||||
|
||||
(t/is (empty? (d/map-diff file file')))))
|
||||
|
||||
(t/testing "file with a two levels nested copy in a main swapped with broken slot should have it repaired"
|
||||
(let [file
|
||||
;; {:main1-root} [:name Frame1] # [Component :component1]
|
||||
;; :main1-child [:name Rect1]
|
||||
;;
|
||||
;; {:main2-root} [:name Frame2] # [Component :component2]
|
||||
;; :nested-head1 [:name Frame1] @--> [Component :component1] :main1-root
|
||||
;; <no-label> [:name Rect1] ---> :main1-child
|
||||
;;
|
||||
;; {:main4-root} [:name Frame4] # [Component :component4]
|
||||
;; :main4-child [:name Rect4]
|
||||
;;
|
||||
;; {:main3-root} [:name Frame3] # [Component :component3]
|
||||
;; :nested-head2 [:name Frame2] @--> [Component :component2] :main2-root
|
||||
;; :nested-subhead2 [:name Frame4] @--> [Component :component4] :main4-root
|
||||
;; NO SWAP SLOT
|
||||
;; <no-label> [:name Rect4] ---> :main4-child
|
||||
;;
|
||||
;; :copy2-root [:name Frame3] #--> [Component :component3] :main3-root
|
||||
;; <no-label> [:name Frame2] @--> [Component :component2] :nested-head2
|
||||
;; <no-label> [:name Frame4] @--> [Component :component4] :nested-subhead2
|
||||
;; <no-label> [:name Rect4] ---> <no-label>
|
||||
(-> (thf/sample-file :file1)
|
||||
(tho/add-two-levels-nested-component-with-copy :component1 :main1-root :main1-child
|
||||
:component2 :main2-root :nested-head1
|
||||
:component3 :main3-root :nested-head2 :nested-subhead2
|
||||
:copy2-root)
|
||||
(tho/add-simple-component :component4 :main4-root :main4-child
|
||||
:root-params {:name "Frame4"}
|
||||
:child-params {:name "Rect4"})
|
||||
(tho/swap-component-in-shape :nested-subhead2 :component4
|
||||
:propagate-fn #(tho/propagate-component-changes % :component3))
|
||||
(ths/update-shape :nested-subhead2 :touched nil))
|
||||
|
||||
file' (ctf/update-file-data file #(cfcp/fix-missing-swap-slots % {}))
|
||||
|
||||
diff (d/map-diff file file')
|
||||
|
||||
expected-diff {:data
|
||||
{:pages-index
|
||||
{(thf/current-page-id file)
|
||||
{:objects
|
||||
{(thi/id :nested-subhead2)
|
||||
{:touched
|
||||
[nil
|
||||
#{(ctk/build-swap-slot-group (str (thi/id :nested-head1)))}]}}}}}}]
|
||||
|
||||
(t/is (= expected-diff diff))))
|
||||
|
||||
(t/testing "when components are in external libraries, the fix still works well"
|
||||
(let [library1
|
||||
;; {:main1-root} [:name Frame1] # [Component :component1]
|
||||
;; :main1-child [:name Rect1]
|
||||
;;
|
||||
;; {:main2-root} [:name Frame2] # [Component :component2]
|
||||
;; :nested2-head [:name Frame1] @--> [Component :component1] :main1-root
|
||||
;; :nested2-child [:name Rect1] ---> :main1-child
|
||||
(-> (thf/sample-file :library1)
|
||||
(tho/add-nested-component :component1 :main1-root :main1-child
|
||||
:component2 :main2-root :nested2-head
|
||||
:nested-head-params {:children-labels [:nested2-child]}))
|
||||
library2
|
||||
;; {:main3-root} [:name Frame3] # [Component :component3]
|
||||
;; :main3-child [:name Rect3]
|
||||
;;
|
||||
;; {:main4-root} [:name Frame4] # [Component :component4]
|
||||
;; :nested4-head [:name Frame3] @--> [Component :component1] :main3-root
|
||||
;; :nested4-child [:name Rect3] ---> :main3-child
|
||||
(-> (thf/sample-file :library2)
|
||||
(tho/add-nested-component :component3 :main3-root :main3-child
|
||||
:component4 :main4-root :nested4-head
|
||||
:root1-params {:name "Frame3"}
|
||||
:main1-child-params {:name "Rect3"}
|
||||
:main2-root-params {:name "Frame4"}
|
||||
:nested-head-params {:children-labels [:nested4-child]}))
|
||||
|
||||
file
|
||||
;; :copy2 [:name Frame2] #--> [Component :component2] :main2-root
|
||||
;; :copy2-nested-head [:name Frame4] @--> [Component :component4] :main4-root
|
||||
;; NO SWAP SLOT
|
||||
;; <no-label> [:name Frame3] @--> :nested4-head
|
||||
;; <no-label> [:name Rect3] ---> :nested4-child
|
||||
(-> (thf/sample-file :file1)
|
||||
(thc/instantiate-component :component2 :copy2 :children-labels [:copy2-nested-head]
|
||||
:library library1)
|
||||
(tho/swap-component-in-first-child :copy2 :component4 :library library2)
|
||||
(ths/update-shape :copy2-nested-head :touched nil))
|
||||
|
||||
libraries {(:id library1) library1
|
||||
(:id library2) library2}
|
||||
|
||||
file' (ctf/update-file-data file #(cfcp/fix-missing-swap-slots % libraries))
|
||||
|
||||
diff (d/map-diff file file')
|
||||
|
||||
expected-diff {:data
|
||||
{:pages-index
|
||||
{(thf/current-page-id file)
|
||||
{:objects
|
||||
{(thi/id :copy2-nested-head)
|
||||
{:touched
|
||||
[nil
|
||||
#{(ctk/build-swap-slot-group (str (thi/id :nested2-head)))}]}}}}}}]
|
||||
|
||||
(t/is (= expected-diff diff)))))
|
||||
|
||||
(t/deftest test-sync-component-id-with-ref-shape
|
||||
|
||||
(t/testing "nil file should return nil"
|
||||
(let [file nil
|
||||
file' (ctf/update-file-data file #(cfcp/sync-component-id-with-ref-shape % {}))]
|
||||
(t/is (nil? file'))))
|
||||
|
||||
(t/testing "empty file should not need any action"
|
||||
(let [file (thf/sample-file :file1)
|
||||
file' (ctf/update-file-data file #(cfcp/sync-component-id-with-ref-shape % {}))]
|
||||
(t/is (empty? (d/map-diff file file')))))
|
||||
|
||||
(t/testing "file without components should not need any action"
|
||||
(let [file
|
||||
;; :frame1 [:name Frame1]
|
||||
;; :child1 [:name Rect1]
|
||||
(-> (thf/sample-file :file1)
|
||||
(tho/add-frame-with-child :frame1 :shape1))
|
||||
|
||||
file' (ctf/update-file-data file #(cfcp/sync-component-id-with-ref-shape % {}))]
|
||||
|
||||
(t/is (empty? (d/map-diff file file')))))
|
||||
|
||||
(t/testing "file with valid normal components should not need any action"
|
||||
(let [file
|
||||
;; {:main1-root} [:name Frame1] # [Component :component1]
|
||||
;; :main1-child [:name Rect1]
|
||||
;;
|
||||
;; {:main2-root} [:name Frame2] # [Component :component2]
|
||||
;; :nested-head1 [:name Frame1] @--> [Component :component1] :main1-root
|
||||
;; <no-label> [:name Rect1] ---> :main1-child
|
||||
;;
|
||||
;; {:main3-root} [:name Frame3] # [Component :component3]
|
||||
;; :nested-head2 [:name Frame2] @--> [Component :component2] :main2-root
|
||||
;; :nested-subhead2 [:name Frame1] @--> [Component :component1] :nested-head1
|
||||
;; <no-label> [:name Rect1] ---> <no-label>
|
||||
;;
|
||||
;; :copy2-root [:name Frame3] #--> [Component :component3] :main3-root
|
||||
;; <no-label> [:name Frame2] @--> [Component :component2] :nested-head2
|
||||
;; <no-label> [:name Frame1] @--> [Component :component1] :nested-subhead2
|
||||
;; <no-label> [:name Rect1] ---> <no-label>
|
||||
(-> (thf/sample-file :file1)
|
||||
(tho/add-two-levels-nested-component-with-copy :component1 :main1-root :main1-child
|
||||
:component2 :main2-root :nested-head1
|
||||
:component3 :main3-root :nested-head2 :nested-subhead2
|
||||
:copy2-root))
|
||||
|
||||
file' (ctf/update-file-data file #(cfcp/sync-component-id-with-ref-shape % {}))]
|
||||
|
||||
#_(thf/dump-file file') ;; Uncomment to debug
|
||||
(t/is (empty? (d/map-diff file file')))))
|
||||
|
||||
(t/testing "file with valid swapped components should not need any action"
|
||||
(let [file
|
||||
;; {:main1-root} [:name Frame1] # [Component :component1]
|
||||
;; :main1-child [:name Rect1]
|
||||
;;
|
||||
;; {:main2-root} [:name Frame2] # [Component :component2]
|
||||
;; :nested-head [:name Frame1] @--> [Component :component1] :main1-root
|
||||
;; <no-label> [:name Rect1] ---> :main1-child
|
||||
;;
|
||||
;; {:main3-root} [:name Frame3] # [Component :component3]
|
||||
;; :main3-child [:name Rect3]
|
||||
;;
|
||||
;; :copy2-root [:name Frame2] #--> [Component :component2] :main2-root
|
||||
;; <no-label> [:name Frame1] @--> [Component :component1] :nested-head
|
||||
;; <no-label> [:name Rect1] ---> <no-label>
|
||||
;;
|
||||
;; :copy3-root [:name Frame2] #--> [Component :component2] :main2-root
|
||||
;; :copy3-nested-head [:name Frame3] @--> [Component :component3] :main3-root
|
||||
;; {swap-slot :nested-head}
|
||||
;; <no-label> [:name Rect3] ---> :main3-child
|
||||
(-> (thf/sample-file :file1)
|
||||
(tho/add-nested-component-with-copy :component1 :main1-root :main1-child
|
||||
:component2 :main2-root :nested-head
|
||||
:copy2-root)
|
||||
(tho/add-simple-component :component3 :main3-root :main3-child
|
||||
:root-params {:name "Frame3"}
|
||||
:child-params {:name "Rect3"})
|
||||
(thc/instantiate-component :component2 :copy3-root :children-labels [:copy3-nested-head])
|
||||
(tho/swap-component-in-first-child :copy3-root :component3))
|
||||
|
||||
file' (ctf/update-file-data file #(cfcp/sync-component-id-with-ref-shape % {}))]
|
||||
|
||||
#_(thf/dump-file file') ;; Uncomment to debug
|
||||
(t/is (empty? (d/map-diff file file')))))
|
||||
|
||||
(t/testing "file with a non swapped copy with broken component id/file should have it repaired"
|
||||
(let [file
|
||||
;; {:main1-root} [:name Frame1] # [Component :component1]
|
||||
;; :main1-child [:name Rect1]
|
||||
;;
|
||||
;; {:main2-root} [:name Frame2] # [Component :component2]
|
||||
;; :nested-head [:name Frame1] @--> [Component :component1] :main1-root
|
||||
;; <no-label> [:name Rect1] ---> :main1-child
|
||||
;;
|
||||
;; :copy2-root [:name Frame2] #--> [Component :component2] :main2-root
|
||||
;; :copy2-nested-head [:name Frame1] @--> [Component <bad>] :nested-head ## <- BAD component-id
|
||||
;; <no-label> [:name Rect1] ---> <no-label>
|
||||
;;
|
||||
;; :copy3-root [:name Frame2] #--> [Component :component2] :main2-root
|
||||
;; :copy3-nested-head [:name Frame1] @--> [Component <bad>] :nested-head ## <- BAD component-file
|
||||
;; <no-label> [:name Rect1] ---> <no-label>
|
||||
(-> (thf/sample-file :file1)
|
||||
(tho/add-nested-component :component1 :main1-root :main1-child
|
||||
:component2 :main2-root :nested-head)
|
||||
(thc/instantiate-component :component2 :copy2-root :children-labels [:copy2-nested-head])
|
||||
(thc/instantiate-component :component2 :copy3-root :children-labels [:copy3-nested-head])
|
||||
(ths/update-shape :copy2-nested-head :component-id (thi/new-id! :some-other-id))
|
||||
(ths/update-shape :copy3-nested-head :component-file (thi/new-id! :some-other-file)))
|
||||
|
||||
file' (ctf/update-file-data file #(cfcp/sync-component-id-with-ref-shape % {}))
|
||||
|
||||
diff (d/map-diff file file')
|
||||
|
||||
expected-diff {:data
|
||||
{:pages-index
|
||||
{(thf/current-page-id file)
|
||||
{:objects
|
||||
{(thi/id :copy2-nested-head)
|
||||
{:component-id
|
||||
[(thi/id :some-other-id) (thi/id :component1)]}
|
||||
(thi/id :copy3-nested-head)
|
||||
{:component-file
|
||||
[(thi/id :some-other-file) (thi/id :file1)]}}}}}}]
|
||||
|
||||
#_(ctf/dump-tree file' (thf/current-page-id file') {(:id file') file'} {:show-ids true}) ;; Uncomment to debug
|
||||
(t/is (= expected-diff diff))))
|
||||
|
||||
(t/testing "file with a copy of a swapped main with broken component id/file should have it repaired"
|
||||
(let [file
|
||||
;; {:main1-root} [:name Frame1] # [Component :component1]
|
||||
;; :main1-child [:name Rect1]
|
||||
;;
|
||||
;; {:main3-root} [:name Frame3] # [Component :component3]
|
||||
;; :main3-child [:name Rect3]
|
||||
;;
|
||||
;; {:main2-root} [:name Frame2] # [Component :component2]
|
||||
;; :nested-head [:name Frame3] @--> [Component :component3] :main3-root
|
||||
;; {swap-slot :nested-head}
|
||||
;; <no-label> [:name Rect3] ---> :main3-child
|
||||
;;
|
||||
;; :copy2-root [:name Frame2] #--> [Component :component2] :main2-root
|
||||
;; :copy2-nested-head [:name Frame3] @--> [Component: <bad>] :nested-head ## <- BAD component-id/file
|
||||
;; <no-label> [:name Rect3] ---> <no-label>
|
||||
(-> (thf/sample-file :file1)
|
||||
(tho/add-nested-component :component1 :main1-root :main1-child
|
||||
:component2 :main2-root :nested-head)
|
||||
(thc/instantiate-component :component2 :copy2-root :children-labels [:copy2-nested-head])
|
||||
(tho/add-simple-component :component3 :main3-root :main3-child
|
||||
:root-params {:name "Frame3"}
|
||||
:child-params {:name "Rect3"})
|
||||
(tho/swap-component-in-shape :nested-head :component3
|
||||
:propagate-fn #(tho/propagate-component-changes % :component2))
|
||||
(ths/update-shape :copy2-nested-head :component-id (thi/new-id! :some-other-id))
|
||||
(ths/update-shape :copy2-nested-head :component-file (thi/new-id! :some-other-file)))
|
||||
|
||||
file' (ctf/update-file-data file #(cfcp/sync-component-id-with-ref-shape % {}))
|
||||
|
||||
diff (d/map-diff file file')
|
||||
|
||||
expected-diff {:data
|
||||
{:pages-index
|
||||
{(thf/current-page-id file)
|
||||
{:objects
|
||||
{(thi/id :copy2-nested-head)
|
||||
{:component-id
|
||||
[(thi/id :some-other-id) (thi/id :component3)]
|
||||
:component-file
|
||||
[(thi/id :some-other-file) (thi/id :file1)]}}}}}}]
|
||||
|
||||
#_(ctf/dump-tree file' (thf/current-page-id file') {(:id file') file'} {:show-ids true}) ;; Uncomment to debug
|
||||
(t/is (= expected-diff diff))))
|
||||
|
||||
(t/testing "file with multiple copies of same component should sync all"
|
||||
(let [file
|
||||
(-> (thf/sample-file :file1)
|
||||
(tho/add-simple-component :component1 :frame1 :shape1)
|
||||
(thc/instantiate-component :component1 :copy1-root :children-labels [:copy1-child])
|
||||
(thc/instantiate-component :component1 :copy2-root :children-labels [:copy2-child])
|
||||
(ths/update-shape :copy1-child :component-id (thi/new-id! :wrong-id1))
|
||||
(ths/update-shape :copy2-child :component-id (thi/new-id! :wrong-id2)))
|
||||
|
||||
file' (ctf/update-file-data file #(cfcp/sync-component-id-with-ref-shape % {}))
|
||||
|
||||
diff (d/map-diff file file')]
|
||||
|
||||
;; Both copies should be corrected
|
||||
(t/is (contains? diff :data))
|
||||
(t/is (contains? (get-in diff [:data :pages-index]) (thf/current-page-id file)))))
|
||||
|
||||
(t/testing "file with a copy root with broken component id/file cannot be repaired. But it's propagated to copies."
|
||||
(let [file
|
||||
;; {:main1-root} [:name Frame1] # [Component :component1]
|
||||
;; :main1-child [:name Rect1]
|
||||
;;
|
||||
;; {:main2-root} [:name Frame2] # [Component :component2]
|
||||
;; :nested-head [:name Frame1] @--> [Component <bad>] :main1-root ## <- BAD component-id/file
|
||||
;; <no-label> [:name Rect1] ---> :main1-child
|
||||
;;
|
||||
;; :copy2-root [:name Frame2] #--> [Component :component2] :main2-root
|
||||
;; :copy2-nested-head [:name Frame1] @--> [Component :component1] :nested-head
|
||||
;; <no-label> [:name Rect1] ---> <no-label>
|
||||
(-> (thf/sample-file :file1)
|
||||
(tho/add-nested-component :component1 :main1-root :main1-child
|
||||
:component2 :main2-root :nested-head)
|
||||
(thc/instantiate-component :component2 :copy2-root :children-labels [:copy2-nested-head])
|
||||
(ths/update-shape :nested-head :component-id (thi/new-id! :some-other-id))
|
||||
(ths/update-shape :nested-head :component-file (thi/new-id! :some-other-file)))
|
||||
|
||||
file' (ctf/update-file-data file #(cfcp/sync-component-id-with-ref-shape % {}))
|
||||
|
||||
diff (d/map-diff file file')
|
||||
|
||||
expected-diff {:data
|
||||
{:pages-index
|
||||
{(thf/current-page-id file)
|
||||
{:objects
|
||||
{(thi/id :copy2-nested-head)
|
||||
{:component-id
|
||||
[(thi/id :component1) (thi/id :some-other-id)]
|
||||
:component-file
|
||||
[(thi/id :file1) (thi/id :some-other-file)]}}}}}}]
|
||||
|
||||
(t/is (= expected-diff diff))))
|
||||
|
||||
(t/testing "file with a 2nd nested copy inside a main with broken component/id should have it repaired, and propagated to copies"
|
||||
(let [file
|
||||
;; {:main1-root} [:name Frame1] # [Component :component1]
|
||||
;; :main1-child [:name Rect1]
|
||||
;;
|
||||
;; {:main2-root} [:name Frame2] # [Component :component2]
|
||||
;; :nested-head1 [:name Frame1] @--> [Component :component1] :main1-root
|
||||
;; <no-label> [:name Rect1] ---> :main1-child
|
||||
;;
|
||||
;; {:main3-root} [:name Frame3] # [Component :component3]
|
||||
;; :nested-head2 [:name Frame2] @--> [Component :component2] :main2-root
|
||||
;; :nested-subhead2 [:name Frame1] @--> [Component <bad>] :nested-head1 ## <- BAD component-id/file
|
||||
;; <no-label> [:name Rect1] ---> <no-label>
|
||||
;;
|
||||
;; :copy2-root [:name Frame3] #--> [Component :component3] :main3-root
|
||||
;; <no-label> [:name Frame2] @--> [Component :component2] :nested-head2
|
||||
;; <no-label> [:name Frame1] @--> [Component :component1] :nested-subhead2
|
||||
;; <no-label> [:name Rect1] ---> <no-label>
|
||||
(-> (thf/sample-file :file1)
|
||||
(tho/add-two-levels-nested-component-with-copy :component1 :main1-root :main1-child
|
||||
:component2 :main2-root :nested-head1
|
||||
:component3 :main3-root :nested-head2 :nested-subhead2
|
||||
:copy2-root)
|
||||
(ths/update-shape :nested-subhead2 :component-id (thi/new-id! :some-other-id))
|
||||
(ths/update-shape :nested-subhead2 :component-file (thi/new-id! :some-other-file)))
|
||||
|
||||
copy2-root (ths/get-shape file :copy2-root)
|
||||
copy2-root-child1 (ths/get-shape-by-id file (first (:shapes copy2-root)))
|
||||
copy2-root-child2 (ths/get-shape-by-id file (first (:shapes copy2-root-child1)))
|
||||
file (-> file
|
||||
(ths/update-shape-by-id (:id copy2-root-child2) :component-id (thi/id :some-other-id))
|
||||
(ths/update-shape-by-id (:id copy2-root-child2) :component-file (thi/id :some-other-file)))
|
||||
|
||||
file' (ctf/update-file-data file #(cfcp/sync-component-id-with-ref-shape % {}))
|
||||
|
||||
diff (d/map-diff file file')
|
||||
|
||||
expected-diff {:data
|
||||
{:pages-index
|
||||
{(thf/current-page-id file)
|
||||
{:objects
|
||||
{(thi/id :nested-subhead2)
|
||||
{:component-id
|
||||
[(thi/id :some-other-id) (thi/id :component1)]
|
||||
:component-file
|
||||
[(thi/id :some-other-file) (thi/id :file1)]}
|
||||
(:id copy2-root-child2)
|
||||
{:component-id
|
||||
[(thi/id :some-other-id) (thi/id :component1)]
|
||||
:component-file
|
||||
[(thi/id :some-other-file) (thi/id :file1)]}}}}}}]
|
||||
|
||||
#_(ctf/dump-tree file' (thf/current-page-id file') {(:id file') file'} {:show-ids true}) ;; Uncomment to debug
|
||||
(t/is (= expected-diff diff))))
|
||||
|
||||
(t/testing "when components are in external libraries, the fix still works well"
|
||||
(let [library1
|
||||
;; {:main1-root} [:name Frame1] # [Component :component1]
|
||||
;; :main1-child [:name Rect1]
|
||||
;;
|
||||
;; {:main2-root} [:name Frame2] # [Component :component2]
|
||||
;; :nested2-head [:name Frame4] @--> [Component :component4] :main4-root
|
||||
;; {swap-slot :nested2-head}
|
||||
;; :nested4-head [:name Frame3] @--> [Component: component3] :main3-root
|
||||
;; :nested4-child [:name Rect3] ---> :nested4-child
|
||||
(-> (thf/sample-file :library1)
|
||||
(tho/add-nested-component :component1 :main1-root :main1-child
|
||||
:component2 :main2-root :nested2-head
|
||||
:nested-head-params {:children-labels [:nested2-child]}))
|
||||
library2
|
||||
;; {:main3-root} [:name Frame3] # [Component :component3]
|
||||
;; :main3-child [:name Rect3]
|
||||
;;
|
||||
;; {:main4-root} [:name Frame4] # [Component :component4]
|
||||
;; :nested4-head [:name Frame3] @--> [Component :component1] :main3-root
|
||||
;; :nested4-child [:name Rect3] ---> :main3-child
|
||||
(-> (thf/sample-file :library2)
|
||||
(tho/add-nested-component :component3 :main3-root :main3-child
|
||||
:component4 :main4-root :nested4-head
|
||||
:root1-params {:name "Frame3"}
|
||||
:main1-child-params {:name "Rect3"}
|
||||
:main2-root-params {:name "Frame4"}
|
||||
:nested-head-params {:children-labels [:nested4-child]}))
|
||||
|
||||
library1
|
||||
(tho/swap-component-in-shape library1 :nested2-head :component4 :library library2)
|
||||
|
||||
file
|
||||
;; :copy2 [:name Frame2] #--> [Component :component2] :main2-root
|
||||
;; :copy2-nested-head [:name Frame4] @--> [Component <bad>] :main4-root ## <- BAD component-id/file
|
||||
;; <no-label> [:name Frame3] @--> :nested4-head
|
||||
;; <no-label> [:name Rect3] ---> :nested4-child
|
||||
(-> (thf/sample-file :file1)
|
||||
(thc/instantiate-component :component2 :copy2 :children-labels [:copy2-nested-head]
|
||||
:library library1)
|
||||
(ths/update-shape :copy2-nested-head :component-id (thi/new-id! :some-other-id))
|
||||
(ths/update-shape :copy2-nested-head :component-file (thi/new-id! :some-other-file)))
|
||||
|
||||
libraries {(:id library1) library1
|
||||
(:id library2) library2}
|
||||
|
||||
file' (ctf/update-file-data file #(cfcp/sync-component-id-with-ref-shape % libraries))
|
||||
|
||||
diff (d/map-diff file file')
|
||||
|
||||
expected-diff {:data
|
||||
{:pages-index
|
||||
{(thf/current-page-id file)
|
||||
{:objects
|
||||
{(thi/id :copy2-nested-head)
|
||||
{:component-id
|
||||
[(thi/id :some-other-id) (thi/id :component4)]
|
||||
:component-file
|
||||
[(thi/id :some-other-file) (thi/id :library2)]}}}}}}]
|
||||
|
||||
#_(thf/dump-file library2) ;; Uncomment to debug
|
||||
(t/is (= expected-diff diff))))
|
||||
|
||||
(t/testing "file with several broken ids should propagate to all copies"
|
||||
(let [file
|
||||
;; {:main1-root} [:name Frame1] # [Component :component1]
|
||||
;; :main1-child [:name Rect1]
|
||||
;;
|
||||
;; {:main2-root} [:name Frame2] # [Component :component2]
|
||||
;; :nested-head1 [:name Frame1] @--> [Component :component1] :main1-root
|
||||
;; <no-label> [:name Rect1] ---> :main1-child
|
||||
;;
|
||||
;; {:main3-root} [:name Frame3] # [Component :component3]
|
||||
;; :nested-head2 [:name Frame2] @--> [Component <bad>] :main2-root ## <- BAD component-id
|
||||
;; :nested-subhead2 [:name Frame1] @--> [Component <bad>] :nested-head1 ## <- BAD component-id
|
||||
;; <no-label> [:name Rect1] ---> <no-label>
|
||||
;;
|
||||
;; :copy2-root [:name Frame3] #--> [Component :component3] :main3-root
|
||||
;; <no-label> [:name Frame2] @--> [Component :component2] :nested-head2
|
||||
;; <no-label> [:name Frame1] @--> [Component :component1] :nested-subhead2
|
||||
;; <no-label> [:name Rect1] ---> <no-label>
|
||||
(-> (thf/sample-file :file1)
|
||||
(tho/add-two-levels-nested-component-with-copy :component1 :main1-root :main1-child
|
||||
:component2 :main2-root :nested-head1
|
||||
:component3 :main3-root :nested-head2 :nested-subhead2
|
||||
:copy2-root)
|
||||
;; Corrupt both levels
|
||||
(ths/update-shape :nested-head2 :component-id (thi/new-id! :wrong-comp2))
|
||||
(ths/update-shape :nested-subhead2 :component-id (thi/new-id! :wrong-comp3)))
|
||||
|
||||
file' (ctf/update-file-data file #(cfcp/sync-component-id-with-ref-shape % {}))
|
||||
copy2-root (ths/get-shape file' :copy2-root)
|
||||
copy2-root-child1 (ths/get-shape-by-id file' (first (:shapes copy2-root)))
|
||||
copy2-root-child2 (ths/get-shape-by-id file' (first (:shapes copy2-root-child1)))
|
||||
|
||||
diff (d/map-diff file file')
|
||||
|
||||
expected-diff {:data
|
||||
{:pages-index
|
||||
{(thf/current-page-id file)
|
||||
{:objects
|
||||
{(:id copy2-root-child1)
|
||||
{:component-id [(thi/id :component2) (thi/id :wrong-comp2)]}
|
||||
(:id copy2-root-child2)
|
||||
{:component-id [(thi/id :component1) (thi/id :wrong-comp3)]}}}}}}]
|
||||
|
||||
(thf/dump-file file') ;; Uncomment to debug
|
||||
(t/is (= expected-diff diff)))))
|
||||
|
||||
52
common/test/common_tests/files/shapes_builder_test.cljc
Normal file
52
common/test/common_tests/files/shapes_builder_test.cljc
Normal file
@ -0,0 +1,52 @@
|
||||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;;
|
||||
;; Copyright (c) KALEIDOS INC
|
||||
|
||||
(ns common-tests.files.shapes-builder-test
|
||||
(:require
|
||||
[app.common.files.shapes-builder :as sb]
|
||||
[clojure.test :as t]))
|
||||
|
||||
;; Regression for https://github.com/penpot/penpot/issues/7869.
|
||||
;; ``parse-svg-element`` used to derive the shape name from
|
||||
;; ``(or (:id attrs) (tag->name tag))`` which dropped Inkscape-authored
|
||||
;; labels. ``tubax/xml->clj`` (the SVG parser the rest of the import
|
||||
;; pipeline already feeds these maps to) keeps namespaced attributes as
|
||||
;; ``:prefix:name`` keywords — same shape the codebase already reads
|
||||
;; ``:xlink:href`` from in this file (line 134) and in
|
||||
;; ``app.common.svg``.
|
||||
|
||||
(t/deftest resolve-element-name-prefers-inkscape-label
|
||||
(t/is (= "Layer 1"
|
||||
(sb/resolve-element-name :g {:inkscape:label "Layer 1"
|
||||
:id "g1234"}))))
|
||||
|
||||
(t/deftest resolve-element-name-prefers-sodipodi-label-when-no-inkscape-label
|
||||
(t/is (= "phone-icon"
|
||||
(sb/resolve-element-name :path {:sodipodi:label "phone-icon"
|
||||
:id "path5678"}))))
|
||||
|
||||
(t/deftest resolve-element-name-falls-back-to-id-when-no-label-namespace
|
||||
(t/is (= "manual-id"
|
||||
(sb/resolve-element-name :rect {:id "manual-id"}))))
|
||||
|
||||
(t/deftest resolve-element-name-falls-back-to-tag-name-when-no-id-and-no-label
|
||||
;; The tag->name mapping returns generic names for known SVG element
|
||||
;; tags. Asserting on the call result here (rather than a hardcoded
|
||||
;; string) keeps the test stable if the tag->name mapping is updated.
|
||||
(t/is (some? (sb/resolve-element-name :rect {})))
|
||||
(t/is (string? (sb/resolve-element-name :rect {}))))
|
||||
|
||||
(t/deftest resolve-element-name-inkscape-label-wins-over-sodipodi-and-id
|
||||
;; Both label conventions and an id present together; the priority is
|
||||
;; inkscape > sodipodi > id > tag, matching the order operators expect
|
||||
;; (Inkscape's own UI shows ``inkscape:label`` as the canonical name).
|
||||
(t/is (= "user-name"
|
||||
(sb/resolve-element-name :g {:inkscape:label "user-name"
|
||||
:sodipodi:label "stale-label"
|
||||
:id "g1"}))))
|
||||
|
||||
(t/deftest resolve-element-name-empty-attrs-uses-tag-fallback
|
||||
(t/is (some? (sb/resolve-element-name :path {}))))
|
||||
@ -304,6 +304,62 @@
|
||||
(t/is (= (thi/id :main1-child) (:id child1')))
|
||||
(t/is (not= (thi/id :main1-child) (:id child2')))))
|
||||
|
||||
(t/deftest test-duplicate-component-rewrites-component-file-to-destination
|
||||
;; Regression test for Issue #8144. When a component is duplicated
|
||||
;; into a different file via `:apply-changes-local-library? true`
|
||||
;; and `:new-component-file` is provided, the returned main-instance
|
||||
;; shape must carry `:component-file` equal to the destination file
|
||||
;; id so the referential-integrity validator
|
||||
;; (:component-main-external) is satisfied.
|
||||
(let [;; ==== Setup
|
||||
file (-> (thf/sample-file :file1)
|
||||
(tho/add-simple-component :component1
|
||||
:main1-root
|
||||
:main1-child))
|
||||
|
||||
component (thc/get-component file :component1)
|
||||
new-component-file (uuid/next)
|
||||
|
||||
;; ==== Action
|
||||
[new-shape _]
|
||||
(cll/generate-duplicate-component (pcb/empty-changes)
|
||||
file
|
||||
(:id component)
|
||||
(uuid/next)
|
||||
{:apply-changes-local-library? true
|
||||
:new-component-file new-component-file})]
|
||||
|
||||
;; ==== Check
|
||||
(t/is (some? new-shape))
|
||||
(t/is (ctk/main-instance? new-shape))
|
||||
(t/is (= new-component-file (:component-file new-shape)))))
|
||||
|
||||
(t/deftest test-duplicate-component-keeps-component-file-without-dest
|
||||
;; Baseline: when no `:new-component-file` is passed (same-file
|
||||
;; duplication), the main-instance's `:component-file` is left
|
||||
;; untouched, matching pre-existing behavior.
|
||||
(let [;; ==== Setup
|
||||
file (-> (thf/sample-file :file1)
|
||||
(tho/add-simple-component :component1
|
||||
:main1-root
|
||||
:main1-child))
|
||||
|
||||
component (thc/get-component file :component1)
|
||||
original-source (:component-file
|
||||
(ths/get-shape-by-id file (:main-instance-id component)))
|
||||
|
||||
;; ==== Action
|
||||
[new-shape _]
|
||||
(cll/generate-duplicate-component (pcb/empty-changes)
|
||||
file
|
||||
(:id component)
|
||||
(uuid/next)
|
||||
{:apply-changes-local-library? true})]
|
||||
|
||||
;; ==== Check
|
||||
(t/is (some? new-shape))
|
||||
(t/is (= original-source (:component-file new-shape)))))
|
||||
|
||||
(t/deftest test-delete-component
|
||||
(let [;; ==== Setup
|
||||
file (-> (thf/sample-file :file1)
|
||||
|
||||
@ -465,9 +465,10 @@
|
||||
page
|
||||
{(:id file) file}
|
||||
(thi/id :nested-h-ellipse))
|
||||
file' (-> (thf/apply-changes file changes)
|
||||
file' (-> (thf/apply-changes file changes :validate? false)
|
||||
(tho/propagate-component-changes :c-board-with-ellipse)
|
||||
(tho/propagate-component-changes :c-big-board))
|
||||
(tho/propagate-component-changes :c-big-board)
|
||||
(thf/validate-file!))
|
||||
|
||||
;; ==== Get
|
||||
nested2-h-ellipse (ths/get-shape file' :nested-h-ellipse)
|
||||
|
||||
@ -349,4 +349,73 @@
|
||||
(t/is (= (:fill-color fill') "#FFFFFF"))
|
||||
(t/is (= (:fill-opacity fill') 1))
|
||||
(t/is (= (:touched copy2-root') nil))
|
||||
(t/is (= (:touched copy2-child') nil))))
|
||||
(t/is (= (:touched copy2-child') nil))))
|
||||
|
||||
(t/deftest test-reset-with-propagation-updates-copies
|
||||
;; When a nested copy inside a main component has an override and we
|
||||
;; reset it passing a propagate-fn, the reset must be propagated to
|
||||
;; all copies of that component so they reflect the canonical color.
|
||||
(let [;; ==== Setup
|
||||
file
|
||||
(-> (thf/sample-file :file1)
|
||||
;; component1: main1-root / main1-child (fill "#aabbcc")
|
||||
;; component2: main2-root contains nested-head (instance of component1)
|
||||
;; copy2-root: copy of component2
|
||||
(tho/add-nested-component-with-copy
|
||||
:component1 :main1-root :main1-child
|
||||
:component2 :main2-root :nested-head
|
||||
:copy2-root
|
||||
:main1-child-params {:fills (ths/sample-fills-color :fill-color "#aabbcc")}
|
||||
:copy2-root-params {:children-labels [:copy2-nested-head]}))
|
||||
|
||||
propagate-fn (fn [f]
|
||||
(-> f
|
||||
(tho/propagate-component-changes :component1)
|
||||
(tho/propagate-component-changes :component2)))
|
||||
|
||||
;; ==== Action – override the nested-head color, then reset it with propagation
|
||||
file'
|
||||
(-> file
|
||||
(tho/update-bottom-color :nested-head "#fabada" :propagate-fn propagate-fn)
|
||||
(tho/reset-overrides (ths/get-shape file :nested-head) :propagate-fn propagate-fn))
|
||||
|
||||
;; ==== Get
|
||||
copy2-bottom-color (tho/bottom-fill-color file' :copy2-root)]
|
||||
|
||||
;; ==== Check
|
||||
;; After reset + propagation the copy should mirror the canonical color
|
||||
(t/is (= copy2-bottom-color "#aabbcc"))))
|
||||
|
||||
(t/deftest test-reset-without-propagation-does-not-update-copies
|
||||
;; This is the regression test for the misplaced-parenthesis bug: when
|
||||
;; propagate-fn is NOT passed to reset-overrides the copies of the component
|
||||
;; must still hold the overridden value because the component sync never ran.
|
||||
(let [;; ==== Setup
|
||||
file
|
||||
(-> (thf/sample-file :file1)
|
||||
(tho/add-nested-component-with-copy
|
||||
:component1 :main1-root :main1-child
|
||||
:component2 :main2-root :nested-head
|
||||
:copy2-root
|
||||
:main1-child-params {:fills (ths/sample-fills-color :fill-color "#aabbcc")}
|
||||
:copy2-root-params {:children-labels [:copy2-nested-head]}))
|
||||
|
||||
propagate-fn (fn [f]
|
||||
(-> f
|
||||
(tho/propagate-component-changes :component1)
|
||||
(tho/propagate-component-changes :component2)))
|
||||
|
||||
;; ==== Action – override the nested-head color, then reset WITHOUT propagation
|
||||
file'
|
||||
(-> file
|
||||
(tho/update-bottom-color :nested-head "#fabada" :propagate-fn propagate-fn)
|
||||
;; Reset without propagate-fn: the component definition is updated but
|
||||
;; the change is never pushed to the copy.
|
||||
(tho/reset-overrides (ths/get-shape file :nested-head)))
|
||||
|
||||
;; ==== Get
|
||||
copy2-bottom-color (tho/bottom-fill-color file' :copy2-root)]
|
||||
|
||||
;; ==== Check
|
||||
;; Without propagation the copy still reflects the overridden color
|
||||
(t/is (= copy2-bottom-color "#fabada"))))
|
||||
@ -64,9 +64,8 @@
|
||||
|
||||
(reset-all-overrides [file]
|
||||
(-> file
|
||||
(tho/reset-overrides-in-first-child :frame-board-1 :page-label :page-1)
|
||||
(tho/reset-overrides-in-first-child :copy-board-1 :page-label :page-2)
|
||||
(propagate-all-component-changes)))
|
||||
(tho/reset-overrides-in-first-child :frame-board-1 :page-label :page-1 :propagate-fn propagate-all-component-changes)
|
||||
(tho/reset-overrides-in-first-child :copy-board-1 :page-label :page-2 :propagate-fn propagate-all-component-changes)))
|
||||
|
||||
(fill-colors [file]
|
||||
[(tho/bottom-fill-color file :frame-ellipse-1 :page-label :page-1)
|
||||
|
||||
@ -6,20 +6,11 @@
|
||||
|
||||
(ns common-tests.logic.multiple-nesting-levels-test
|
||||
(:require
|
||||
[app.common.files.changes :as ch]
|
||||
[app.common.files.changes-builder :as pcb]
|
||||
[app.common.logic.libraries :as cll]
|
||||
[app.common.logic.shapes :as cls]
|
||||
[app.common.pprint :as pp]
|
||||
[app.common.test-helpers.components :as thc]
|
||||
[app.common.test-helpers.compositions :as tho]
|
||||
[app.common.test-helpers.files :as thf]
|
||||
[app.common.test-helpers.ids-map :as thi]
|
||||
[app.common.test-helpers.shapes :as ths]
|
||||
[app.common.types.component :as ctk]
|
||||
[app.common.types.container :as ctn]
|
||||
[app.common.types.file :as ctf]
|
||||
[app.common.uuid :as uuid]
|
||||
[clojure.test :as t]))
|
||||
|
||||
(t/use-fixtures :each thi/test-fixture)
|
||||
@ -56,10 +47,9 @@
|
||||
|
||||
(reset-all-overrides [file]
|
||||
(-> file
|
||||
(tho/reset-overrides (ths/get-shape file :copy-simple-1))
|
||||
(tho/reset-overrides (ths/get-shape file :copy-frame-composed-1))
|
||||
(tho/reset-overrides (ths/get-shape file :composed-1-composed-2-copy))
|
||||
(propagate-all-component-changes)))
|
||||
(tho/reset-overrides (ths/get-shape file :copy-simple-1) :propagate-fn propagate-all-component-changes)
|
||||
(tho/reset-overrides (ths/get-shape file :copy-frame-composed-1) :propagate-fn propagate-all-component-changes)
|
||||
(tho/reset-overrides (ths/get-shape file :composed-1-composed-2-copy) :propagate-fn propagate-all-component-changes)))
|
||||
|
||||
(fill-colors [file]
|
||||
[(tho/bottom-fill-color file :frame-simple-1)
|
||||
|
||||
@ -6,20 +6,12 @@
|
||||
|
||||
(ns common-tests.logic.swap-as-override-test
|
||||
(:require
|
||||
[app.common.files.changes :as ch]
|
||||
[app.common.files.changes-builder :as pcb]
|
||||
[app.common.logic.libraries :as cll]
|
||||
[app.common.logic.shapes :as cls]
|
||||
[app.common.pprint :as pp]
|
||||
[app.common.data :as d]
|
||||
[app.common.test-helpers.components :as thc]
|
||||
[app.common.test-helpers.compositions :as tho]
|
||||
[app.common.test-helpers.files :as thf]
|
||||
[app.common.test-helpers.ids-map :as thi]
|
||||
[app.common.test-helpers.shapes :as ths]
|
||||
[app.common.types.component :as ctk]
|
||||
[app.common.types.container :as ctn]
|
||||
[app.common.types.file :as ctf]
|
||||
[app.common.uuid :as uuid]
|
||||
[clojure.test :as t]))
|
||||
|
||||
(t/use-fixtures :each thi/test-fixture)
|
||||
@ -27,23 +19,40 @@
|
||||
(defn- setup []
|
||||
(-> (thf/sample-file :file1)
|
||||
|
||||
(tho/add-simple-component :component-1 :frame-component-1 :child-component-1 :child-params {:name "child-component-1" :type :rect :fills (ths/sample-fills-color :fill-color "#111111")})
|
||||
(tho/add-simple-component :component-2 :frame-component-2 :child-component-2 :child-params {:name "child-component-2" :type :rect :fills (ths/sample-fills-color :fill-color "#222222")})
|
||||
(tho/add-simple-component :component-3 :frame-component-3 :child-component-3 :child-params {:name "child-component-3" :type :rect :fills (ths/sample-fills-color :fill-color "#333333")})
|
||||
(tho/add-simple-component :component-1 :frame-component-1 :child-component-1
|
||||
:root-params {:name "component-1"}
|
||||
:child-params {:name "child-component-1"
|
||||
:type :rect
|
||||
:fills (ths/sample-fills-color :fill-color "#111111")})
|
||||
(tho/add-simple-component :component-2 :frame-component-2 :child-component-2
|
||||
:root-params {:name "component-2"}
|
||||
:child-params {:name "child-component-2"
|
||||
:type :rect
|
||||
:fills (ths/sample-fills-color :fill-color "#222222")})
|
||||
(tho/add-simple-component :component-3 :frame-component-3 :child-component-3
|
||||
:root-params {:name "component-3"}
|
||||
:child-params {:name "child-component-3"
|
||||
:type :rect
|
||||
:fills (ths/sample-fills-color :fill-color "#333333")})
|
||||
|
||||
(tho/add-frame :frame-icon-and-text)
|
||||
(thc/instantiate-component :component-1 :copy-component-1 :parent-label :frame-icon-and-text :children-labels [:component-1-icon-and-text])
|
||||
(tho/add-frame :frame-icon-and-text :name "copy-component-1")
|
||||
(thc/instantiate-component :component-1 :copy-component-1
|
||||
:parent-label :frame-icon-and-text
|
||||
:children-labels [:component-1-icon-and-text])
|
||||
(ths/add-sample-shape :text
|
||||
{:type :text
|
||||
:name "icon+text"
|
||||
:parent-label :frame-icon-and-text})
|
||||
(thc/make-component :icon-and-text :frame-icon-and-text)
|
||||
|
||||
(tho/add-frame :frame-panel)
|
||||
(thc/instantiate-component :icon-and-text :copy-icon-and-text :parent-label :frame-panel :children-labels [:icon-and-text-panel])
|
||||
(tho/add-frame :frame-panel :name "icon-and-text")
|
||||
(thc/instantiate-component :icon-and-text :copy-icon-and-text
|
||||
:parent-label :frame-panel
|
||||
:children-labels [:icon-and-text-panel])
|
||||
(thc/make-component :panel :frame-panel)
|
||||
|
||||
(thc/instantiate-component :panel :copy-panel :children-labels [:copy-icon-and-text-panel])))
|
||||
(thc/instantiate-component :panel :copy-panel
|
||||
:children-labels [:copy-icon-and-text-panel])))
|
||||
|
||||
(defn- propagate-all-component-changes [file]
|
||||
(-> file
|
||||
|
||||
@ -30,7 +30,7 @@
|
||||
copy (ths/get-shape file :copy01)
|
||||
|
||||
;; ==== Action
|
||||
file' (tho/swap-component file copy :circle {:new-shape-label :copy02 :keep-touched? true})
|
||||
file' (tho/swap-component-in-shape file :copy01 :circle {:new-shape-label :copy02 :keep-touched? true})
|
||||
|
||||
copy' (ths/get-shape file' :copy02)]
|
||||
;; Both copies have the same id
|
||||
|
||||
@ -35,7 +35,7 @@
|
||||
copy01 (ths/get-shape file :copy01)
|
||||
|
||||
;; ==== Action
|
||||
file' (tho/swap-component file copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
file' (tho/swap-component-in-shape file :copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
|
||||
copy01' (ths/get-shape file' :copy02)]
|
||||
(thf/dump-file file :keys [:width])
|
||||
@ -61,7 +61,7 @@
|
||||
rect01 (get-in page [:objects (-> copy01 :shapes first)])
|
||||
|
||||
;; ==== Action
|
||||
file' (tho/swap-component file copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
file' (tho/swap-component-in-shape file :copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
|
||||
page' (thf/current-page file')
|
||||
copy02' (ths/get-shape file' :copy02)
|
||||
@ -100,7 +100,7 @@
|
||||
copy01 (ths/get-shape file :copy01)
|
||||
|
||||
;; ==== Action
|
||||
file' (tho/swap-component file copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
file' (tho/swap-component-in-shape file :copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
|
||||
copy01' (ths/get-shape file' :copy02)]
|
||||
(thf/dump-file file :keys [:width])
|
||||
@ -137,7 +137,7 @@
|
||||
rect01 (get-in page [:objects (:id rect01)])
|
||||
|
||||
;; ==== Action
|
||||
file' (tho/swap-component file copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
file' (tho/swap-component-in-shape file :copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
|
||||
page' (thf/current-page file')
|
||||
copy02' (ths/get-shape file' :copy02)
|
||||
@ -180,7 +180,7 @@
|
||||
rect01 (get-in page [:objects (:id rect01)])
|
||||
|
||||
;; ==== Action
|
||||
file' (tho/swap-component file copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
file' (tho/swap-component-in-shape file :copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
|
||||
page' (thf/current-page file')
|
||||
copy02' (ths/get-shape file' :copy02)
|
||||
@ -257,25 +257,19 @@
|
||||
|
||||
|
||||
;; The copy clean has no overrides
|
||||
|
||||
|
||||
copy-clean (ths/get-shape file :copy-clean)
|
||||
copy-clean-t (ths/get-shape file :copy-clean-t)
|
||||
|
||||
;; Override font size on copy-font-size
|
||||
file (update-attr file :copy-font-size-t font-size-path-0 "25")
|
||||
copy-font-size (ths/get-shape file :copy-font-size)
|
||||
copy-font-size-t (ths/get-shape file :copy-font-size-t)
|
||||
|
||||
;; Override text on copy-text
|
||||
file (update-attr file :copy-text-t text-path-0 "text overriden")
|
||||
copy-text (ths/get-shape file :copy-text)
|
||||
copy-text-t (ths/get-shape file :copy-text-t)
|
||||
|
||||
;; Override both on copy-both
|
||||
file (update-attr file :copy-both-t font-size-path-0 "25")
|
||||
file (update-attr file :copy-both-t text-path-0 "text overriden")
|
||||
copy-both (ths/get-shape file :copy-both)
|
||||
copy-both-t (ths/get-shape file :copy-both-t)
|
||||
|
||||
|
||||
@ -283,10 +277,10 @@
|
||||
|
||||
|
||||
file' (-> file
|
||||
(tho/swap-component copy-clean :c02 {:new-shape-label :copy-clean-2 :keep-touched? true})
|
||||
(tho/swap-component copy-font-size :c02 {:new-shape-label :copy-font-size-2 :keep-touched? true})
|
||||
(tho/swap-component copy-text :c02 {:new-shape-label :copy-text-2 :keep-touched? true})
|
||||
(tho/swap-component copy-both :c02 {:new-shape-label :copy-both-2 :keep-touched? true}))
|
||||
(tho/swap-component-in-shape :copy-clean :c02 {:new-shape-label :copy-clean-2 :keep-touched? true})
|
||||
(tho/swap-component-in-shape :copy-font-size :c02 {:new-shape-label :copy-font-size-2 :keep-touched? true})
|
||||
(tho/swap-component-in-shape :copy-text :c02 {:new-shape-label :copy-text-2 :keep-touched? true})
|
||||
(tho/swap-component-in-shape :copy-both :c02 {:new-shape-label :copy-both-2 :keep-touched? true}))
|
||||
page' (thf/current-page file')
|
||||
copy-clean' (ths/get-shape file' :copy-clean-2)
|
||||
copy-clean-t' (get-in page' [:objects (-> copy-clean' :shapes first)])
|
||||
@ -387,25 +381,19 @@
|
||||
|
||||
|
||||
;; The copy clean has no overrides
|
||||
|
||||
|
||||
copy-clean (ths/get-shape file :copy-clean)
|
||||
copy-clean-t (ths/get-shape file :copy-clean-t)
|
||||
|
||||
;; Override font size on copy-font-size
|
||||
file (update-attr file :copy-font-size-t font-size-path-0 "25")
|
||||
copy-font-size (ths/get-shape file :copy-font-size)
|
||||
copy-font-size-t (ths/get-shape file :copy-font-size-t)
|
||||
|
||||
;; Override text on copy-text
|
||||
file (update-attr file :copy-text-t text-path-0 "text overriden")
|
||||
copy-text (ths/get-shape file :copy-text)
|
||||
copy-text-t (ths/get-shape file :copy-text-t)
|
||||
|
||||
;; Override both on copy-both
|
||||
file (update-attr file :copy-both-t font-size-path-0 "25")
|
||||
file (update-attr file :copy-both-t text-path-0 "text overriden")
|
||||
copy-both (ths/get-shape file :copy-both)
|
||||
copy-both-t (ths/get-shape file :copy-both-t)
|
||||
|
||||
|
||||
@ -413,10 +401,10 @@
|
||||
|
||||
|
||||
file' (-> file
|
||||
(tho/swap-component copy-clean :c02 {:new-shape-label :copy-clean-2 :keep-touched? true})
|
||||
(tho/swap-component copy-font-size :c02 {:new-shape-label :copy-font-size-2 :keep-touched? true})
|
||||
(tho/swap-component copy-text :c02 {:new-shape-label :copy-text-2 :keep-touched? true})
|
||||
(tho/swap-component copy-both :c02 {:new-shape-label :copy-both-2 :keep-touched? true}))
|
||||
(tho/swap-component-in-shape :copy-clean :c02 {:new-shape-label :copy-clean-2 :keep-touched? true})
|
||||
(tho/swap-component-in-shape :copy-font-size :c02 {:new-shape-label :copy-font-size-2 :keep-touched? true})
|
||||
(tho/swap-component-in-shape :copy-text :c02 {:new-shape-label :copy-text-2 :keep-touched? true})
|
||||
(tho/swap-component-in-shape :copy-both :c02 {:new-shape-label :copy-both-2 :keep-touched? true}))
|
||||
page' (thf/current-page file')
|
||||
copy-clean' (ths/get-shape file' :copy-clean-2)
|
||||
copy-clean-t' (get-in page' [:objects (-> copy-clean' :shapes first)])
|
||||
@ -515,25 +503,19 @@
|
||||
|
||||
|
||||
;; The copy clean has no overrides
|
||||
|
||||
|
||||
copy-clean (ths/get-shape file :copy-clean)
|
||||
copy-clean-t (ths/get-shape file :copy-clean-t)
|
||||
|
||||
;; Override font size on copy-font-size
|
||||
file (update-attr file :copy-font-size-t font-size-path-0 "25")
|
||||
copy-font-size (ths/get-shape file :copy-font-size)
|
||||
copy-font-size-t (ths/get-shape file :copy-font-size-t)
|
||||
|
||||
;; Override text on copy-text
|
||||
file (update-attr file :copy-text-t text-path-0 "text overriden")
|
||||
copy-text (ths/get-shape file :copy-text)
|
||||
copy-text-t (ths/get-shape file :copy-text-t)
|
||||
|
||||
;; Override both on copy-both
|
||||
file (update-attr file :copy-both-t font-size-path-0 "25")
|
||||
file (update-attr file :copy-both-t text-path-0 "text overriden")
|
||||
copy-both (ths/get-shape file :copy-both)
|
||||
copy-both-t (ths/get-shape file :copy-both-t)
|
||||
|
||||
|
||||
@ -541,10 +523,10 @@
|
||||
|
||||
|
||||
file' (-> file
|
||||
(tho/swap-component copy-clean :c02 {:new-shape-label :copy-clean-2 :keep-touched? true})
|
||||
(tho/swap-component copy-font-size :c02 {:new-shape-label :copy-font-size-2 :keep-touched? true})
|
||||
(tho/swap-component copy-text :c02 {:new-shape-label :copy-text-2 :keep-touched? true})
|
||||
(tho/swap-component copy-both :c02 {:new-shape-label :copy-both-2 :keep-touched? true}))
|
||||
(tho/swap-component-in-shape :copy-clean :c02 {:new-shape-label :copy-clean-2 :keep-touched? true})
|
||||
(tho/swap-component-in-shape :copy-font-size :c02 {:new-shape-label :copy-font-size-2 :keep-touched? true})
|
||||
(tho/swap-component-in-shape :copy-text :c02 {:new-shape-label :copy-text-2 :keep-touched? true})
|
||||
(tho/swap-component-in-shape :copy-both :c02 {:new-shape-label :copy-both-2 :keep-touched? true}))
|
||||
page' (thf/current-page file')
|
||||
copy-clean' (ths/get-shape file' :copy-clean-2)
|
||||
copy-clean-t' (get-in page' [:objects (-> copy-clean' :shapes first)])
|
||||
@ -645,25 +627,19 @@
|
||||
|
||||
|
||||
;; The copy clean has no overrides
|
||||
|
||||
|
||||
copy-clean (ths/get-shape file :copy-clean)
|
||||
copy-clean-t (ths/get-shape file :copy-clean-t)
|
||||
|
||||
;; Override font size on copy-font-size
|
||||
file (update-attr file :copy-font-size-t font-size-path-0 "25")
|
||||
copy-font-size (ths/get-shape file :copy-font-size)
|
||||
copy-font-size-t (ths/get-shape file :copy-font-size-t)
|
||||
|
||||
;; Override text on copy-text
|
||||
file (update-attr file :copy-text-t text-path-0 "text overriden")
|
||||
copy-text (ths/get-shape file :copy-text)
|
||||
copy-text-t (ths/get-shape file :copy-text-t)
|
||||
|
||||
;; Override both on copy-both
|
||||
file (update-attr file :copy-both-t font-size-path-0 "25")
|
||||
file (update-attr file :copy-both-t text-path-0 "text overriden")
|
||||
copy-both (ths/get-shape file :copy-both)
|
||||
copy-both-t (ths/get-shape file :copy-both-t)
|
||||
|
||||
|
||||
@ -671,10 +647,10 @@
|
||||
|
||||
|
||||
file' (-> file
|
||||
(tho/swap-component copy-clean :c02 {:new-shape-label :copy-clean-2 :keep-touched? true})
|
||||
(tho/swap-component copy-font-size :c02 {:new-shape-label :copy-font-size-2 :keep-touched? true})
|
||||
(tho/swap-component copy-text :c02 {:new-shape-label :copy-text-2 :keep-touched? true})
|
||||
(tho/swap-component copy-both :c02 {:new-shape-label :copy-both-2 :keep-touched? true}))
|
||||
(tho/swap-component-in-shape :copy-clean :c02 {:new-shape-label :copy-clean-2 :keep-touched? true})
|
||||
(tho/swap-component-in-shape :copy-font-size :c02 {:new-shape-label :copy-font-size-2 :keep-touched? true})
|
||||
(tho/swap-component-in-shape :copy-text :c02 {:new-shape-label :copy-text-2 :keep-touched? true})
|
||||
(tho/swap-component-in-shape :copy-both :c02 {:new-shape-label :copy-both-2 :keep-touched? true}))
|
||||
page' (thf/current-page file')
|
||||
copy-clean' (ths/get-shape file' :copy-clean-2)
|
||||
copy-clean-t' (get-in page' [:objects (-> copy-clean' :shapes first)])
|
||||
@ -774,14 +750,12 @@
|
||||
|
||||
|
||||
file (change-structure file :copy-structure-clean-t)
|
||||
copy-structure-clean (ths/get-shape file :copy-structure-clean)
|
||||
copy-structure-clean-t (ths/get-shape file :copy-structure-clean-t)
|
||||
|
||||
;; Duplicate a text line in copy-structure-clean, updating
|
||||
;; both lines with the same attrs
|
||||
file (-> (update-attr file :copy-structure-unif-t font-size-path-0 "25")
|
||||
(change-structure :copy-structure-unif-t))
|
||||
copy-structure-unif (ths/get-shape file :copy-structure-unif)
|
||||
copy-structure-unif-t (ths/get-shape file :copy-structure-unif-t)
|
||||
|
||||
;; Duplicate a text line in copy-structure-clean, updating
|
||||
@ -789,7 +763,6 @@
|
||||
file (-> (change-structure file :copy-structure-mixed-t)
|
||||
(update-attr :copy-structure-mixed-t font-size-path-0 "35")
|
||||
(update-attr :copy-structure-mixed-t font-size-path-1 "40"))
|
||||
copy-structure-mixed (ths/get-shape file :copy-structure-mixed)
|
||||
copy-structure-mixed-t (ths/get-shape file :copy-structure-mixed-t)
|
||||
|
||||
|
||||
@ -797,9 +770,9 @@
|
||||
|
||||
|
||||
file' (-> file
|
||||
(tho/swap-component copy-structure-clean :c02 {:new-shape-label :copy-structure-clean-2 :keep-touched? true})
|
||||
(tho/swap-component copy-structure-unif :c02 {:new-shape-label :copy-structure-unif-2 :keep-touched? true})
|
||||
(tho/swap-component copy-structure-mixed :c02 {:new-shape-label :copy-structure-mixed-2 :keep-touched? true}))
|
||||
(tho/swap-component-in-shape :copy-structure-clean :c02 {:new-shape-label :copy-structure-clean-2 :keep-touched? true})
|
||||
(tho/swap-component-in-shape :copy-structure-unif :c02 {:new-shape-label :copy-structure-unif-2 :keep-touched? true})
|
||||
(tho/swap-component-in-shape :copy-structure-mixed :c02 {:new-shape-label :copy-structure-mixed-2 :keep-touched? true}))
|
||||
page' (thf/current-page file')
|
||||
copy-structure-clean' (ths/get-shape file' :copy-structure-clean-2)
|
||||
copy-structure-clean-t' (get-in page' [:objects (-> copy-structure-clean' :shapes first)])
|
||||
@ -908,14 +881,12 @@
|
||||
|
||||
|
||||
file (change-structure file :copy-structure-clean-t)
|
||||
copy-structure-clean (ths/get-shape file :copy-structure-clean)
|
||||
copy-structure-clean-t (ths/get-shape file :copy-structure-clean-t)
|
||||
|
||||
;; Duplicate a text line in copy-structure-clean, updating
|
||||
;; both lines with the same attrs
|
||||
file (-> (update-attr file :copy-structure-unif-t font-size-path-0 "25")
|
||||
(change-structure :copy-structure-unif-t))
|
||||
copy-structure-unif (ths/get-shape file :copy-structure-unif)
|
||||
copy-structure-unif-t (ths/get-shape file :copy-structure-unif-t)
|
||||
|
||||
;; Duplicate a text line in copy-structure-clean, updating
|
||||
@ -923,7 +894,6 @@
|
||||
file (-> (change-structure file :copy-structure-mixed-t)
|
||||
(update-attr :copy-structure-mixed-t font-size-path-0 "35")
|
||||
(update-attr :copy-structure-mixed-t font-size-path-1 "40"))
|
||||
copy-structure-mixed (ths/get-shape file :copy-structure-mixed)
|
||||
copy-structure-mixed-t (ths/get-shape file :copy-structure-mixed-t)
|
||||
|
||||
|
||||
@ -931,9 +901,9 @@
|
||||
|
||||
|
||||
file' (-> file
|
||||
(tho/swap-component copy-structure-clean :c02 {:new-shape-label :copy-structure-clean-2 :keep-touched? true})
|
||||
(tho/swap-component copy-structure-unif :c02 {:new-shape-label :copy-structure-unif-2 :keep-touched? true})
|
||||
(tho/swap-component copy-structure-mixed :c02 {:new-shape-label :copy-structure-mixed-2 :keep-touched? true}))
|
||||
(tho/swap-component-in-shape :copy-structure-clean :c02 {:new-shape-label :copy-structure-clean-2 :keep-touched? true})
|
||||
(tho/swap-component-in-shape :copy-structure-unif :c02 {:new-shape-label :copy-structure-unif-2 :keep-touched? true})
|
||||
(tho/swap-component-in-shape :copy-structure-mixed :c02 {:new-shape-label :copy-structure-mixed-2 :keep-touched? true}))
|
||||
page' (thf/current-page file')
|
||||
copy-structure-clean' (ths/get-shape file' :copy-structure-clean-2)
|
||||
copy-structure-clean-t' (get-in page' [:objects (-> copy-structure-clean' :shapes first)])
|
||||
@ -1038,14 +1008,12 @@
|
||||
|
||||
|
||||
file (change-structure file :copy-structure-clean-t)
|
||||
copy-structure-clean (ths/get-shape file :copy-structure-clean)
|
||||
copy-structure-clean-t (ths/get-shape file :copy-structure-clean-t)
|
||||
|
||||
;; Duplicate a text line in copy-structure-clean, updating
|
||||
;; both lines with the same attrs
|
||||
file (-> (update-attr file :copy-structure-unif-t font-size-path-0 "25")
|
||||
(change-structure :copy-structure-unif-t))
|
||||
copy-structure-unif (ths/get-shape file :copy-structure-unif)
|
||||
copy-structure-unif-t (ths/get-shape file :copy-structure-unif-t)
|
||||
|
||||
;; Duplicate a text line in copy-structure-clean, updating
|
||||
@ -1053,7 +1021,6 @@
|
||||
file (-> (change-structure file :copy-structure-mixed-t)
|
||||
(update-attr :copy-structure-mixed-t font-size-path-0 "35")
|
||||
(update-attr :copy-structure-mixed-t font-size-path-1 "40"))
|
||||
copy-structure-mixed (ths/get-shape file :copy-structure-mixed)
|
||||
copy-structure-mixed-t (ths/get-shape file :copy-structure-mixed-t)
|
||||
|
||||
|
||||
@ -1061,9 +1028,9 @@
|
||||
|
||||
|
||||
file' (-> file
|
||||
(tho/swap-component copy-structure-clean :c02 {:new-shape-label :copy-structure-clean-2 :keep-touched? true})
|
||||
(tho/swap-component copy-structure-unif :c02 {:new-shape-label :copy-structure-unif-2 :keep-touched? true})
|
||||
(tho/swap-component copy-structure-mixed :c02 {:new-shape-label :copy-structure-mixed-2 :keep-touched? true}))
|
||||
(tho/swap-component-in-shape :copy-structure-clean :c02 {:new-shape-label :copy-structure-clean-2 :keep-touched? true})
|
||||
(tho/swap-component-in-shape :copy-structure-unif :c02 {:new-shape-label :copy-structure-unif-2 :keep-touched? true})
|
||||
(tho/swap-component-in-shape :copy-structure-mixed :c02 {:new-shape-label :copy-structure-mixed-2 :keep-touched? true}))
|
||||
page' (thf/current-page file')
|
||||
copy-structure-clean' (ths/get-shape file' :copy-structure-clean-2)
|
||||
copy-structure-clean-t' (get-in page' [:objects (-> copy-structure-clean' :shapes first)])
|
||||
@ -1169,14 +1136,12 @@
|
||||
|
||||
|
||||
file (change-structure file :copy-structure-clean-t)
|
||||
copy-structure-clean (ths/get-shape file :copy-structure-clean)
|
||||
copy-structure-clean-t (ths/get-shape file :copy-structure-clean-t)
|
||||
|
||||
;; Duplicate a text line in copy-structure-clean, updating
|
||||
;; both lines with the same attrs
|
||||
file (-> (update-attr file :copy-structure-unif-t font-size-path-0 "25")
|
||||
(change-structure :copy-structure-unif-t))
|
||||
copy-structure-unif (ths/get-shape file :copy-structure-unif)
|
||||
copy-structure-unif-t (ths/get-shape file :copy-structure-unif-t)
|
||||
|
||||
;; Duplicate a text line in copy-structure-clean, updating
|
||||
@ -1184,7 +1149,6 @@
|
||||
file (-> (change-structure file :copy-structure-mixed-t)
|
||||
(update-attr :copy-structure-mixed-t font-size-path-0 "35")
|
||||
(update-attr :copy-structure-mixed-t font-size-path-1 "40"))
|
||||
copy-structure-mixed (ths/get-shape file :copy-structure-mixed)
|
||||
copy-structure-mixed-t (ths/get-shape file :copy-structure-mixed-t)
|
||||
|
||||
|
||||
@ -1192,9 +1156,9 @@
|
||||
|
||||
|
||||
file' (-> file
|
||||
(tho/swap-component copy-structure-clean :c02 {:new-shape-label :copy-structure-clean-2 :keep-touched? true})
|
||||
(tho/swap-component copy-structure-unif :c02 {:new-shape-label :copy-structure-unif-2 :keep-touched? true})
|
||||
(tho/swap-component copy-structure-mixed :c02 {:new-shape-label :copy-structure-mixed-2 :keep-touched? true}))
|
||||
(tho/swap-component-in-shape :copy-structure-clean :c02 {:new-shape-label :copy-structure-clean-2 :keep-touched? true})
|
||||
(tho/swap-component-in-shape :copy-structure-unif :c02 {:new-shape-label :copy-structure-unif-2 :keep-touched? true})
|
||||
(tho/swap-component-in-shape :copy-structure-mixed :c02 {:new-shape-label :copy-structure-mixed-2 :keep-touched? true}))
|
||||
page' (thf/current-page file')
|
||||
copy-structure-clean' (ths/get-shape file' :copy-structure-clean-2)
|
||||
copy-structure-clean-t' (get-in page' [:objects (-> copy-structure-clean' :shapes first)])
|
||||
@ -1290,7 +1254,6 @@
|
||||
:children-labels [:copy-cp01]))
|
||||
|
||||
page (thf/current-page file)
|
||||
copy01 (ths/get-shape file :copy01)
|
||||
copy-cp01 (ths/get-shape file :copy-cp01)
|
||||
copy-cp01-rect-id (-> copy-cp01 :shapes first)
|
||||
|
||||
@ -1309,7 +1272,7 @@
|
||||
|
||||
;; ==== Action
|
||||
;; Switch :c01 for :c02
|
||||
file' (tho/swap-component file copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
file' (tho/swap-component-in-shape file :copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
copy02 (ths/get-shape file' :copy02)
|
||||
copy-cp02' (ths/get-shape-by-id file' (-> copy02 :shapes first))
|
||||
copy-cp02-rect' (ths/get-shape-by-id file' (-> copy-cp02' :shapes first))]
|
||||
@ -1337,17 +1300,16 @@
|
||||
:children-labels [:copy-cp01]))
|
||||
|
||||
copy01 (ths/get-shape file :copy01)
|
||||
copy-cp01 (ths/get-shape file :copy-cp01)
|
||||
external02 (thc/get-component file :external02)
|
||||
|
||||
;; On :c01, swap the copy of :external01 for a copy of :external02
|
||||
file (-> file
|
||||
(tho/swap-component copy-cp01 :external02 {:new-shape-label :copy-cp02 :keep-touched? false}))
|
||||
(tho/swap-component-in-shape :copy-cp01 :external02 {:new-shape-label :copy-cp02 :keep-touched? false}))
|
||||
copy-cp02 (ths/get-shape file :copy-cp02)
|
||||
|
||||
;; ==== Action
|
||||
;; Switch :c01 for :c02
|
||||
file' (tho/swap-component file copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
file' (tho/swap-component-in-shape file :copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
|
||||
copy02' (ths/get-shape file' :copy02)
|
||||
copy-cp02' (ths/get-shape file' :copy-cp02)]
|
||||
@ -1376,12 +1338,11 @@
|
||||
|
||||
page (thf/current-page file)
|
||||
copy01 (ths/get-shape file :copy01)
|
||||
copy-cp01 (ths/get-shape file :copy-cp01)
|
||||
external02 (thc/get-component file :external02)
|
||||
|
||||
;; On :c01, swap the copy of :external01 for a copy of :external02
|
||||
file (-> file
|
||||
(tho/swap-component copy-cp01 :external02 {:new-shape-label :copy-cp02 :keep-touched? false}))
|
||||
(tho/swap-component-in-shape :copy-cp01 :external02 {:new-shape-label :copy-cp02 :keep-touched? false}))
|
||||
copy-cp02 (ths/get-shape file :copy-cp02)
|
||||
copy-cp02-rect-id (-> copy-cp02 :shapes first)
|
||||
|
||||
@ -1396,7 +1357,7 @@
|
||||
|
||||
;; ==== Action
|
||||
;; Switch :c01 for :c02
|
||||
file' (tho/swap-component file copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
file' (tho/swap-component-in-shape file :copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
|
||||
copy02' (ths/get-shape file' :copy02)
|
||||
copy-cp02' (ths/get-shape file' :copy-cp02)
|
||||
@ -1463,7 +1424,7 @@
|
||||
;; ==== Action
|
||||
|
||||
|
||||
file' (tho/swap-component file c01-in-copy :c02 {:new-shape-label :c02-in-copy :keep-touched? true})
|
||||
file' (tho/swap-component-in-shape file :c01-in-copy :c02 {:new-shape-label :c02-in-copy :keep-touched? true})
|
||||
|
||||
page' (thf/current-page file')
|
||||
c02-in-copy' (ths/get-shape file' :c02-in-copy)
|
||||
@ -1515,7 +1476,7 @@
|
||||
rect01 (get-in page [:objects (:id rect01)])
|
||||
|
||||
;; ==== Action
|
||||
file' (tho/swap-component file copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
file' (tho/swap-component-in-shape file :copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
|
||||
page' (thf/current-page file')
|
||||
copy02' (ths/get-shape file' :copy02)
|
||||
@ -1564,7 +1525,7 @@
|
||||
rect01 (get-in page [:objects (:id rect01)])
|
||||
|
||||
;; ==== Action
|
||||
file' (tho/swap-component file copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
file' (tho/swap-component-in-shape file :copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
|
||||
page' (thf/current-page file')
|
||||
copy02' (ths/get-shape file' :copy02)
|
||||
@ -1613,7 +1574,7 @@
|
||||
rect01 (get-in page [:objects (:id rect01)])
|
||||
|
||||
;; ==== Action
|
||||
file' (tho/swap-component file copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
file' (tho/swap-component-in-shape file :copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
|
||||
page' (thf/current-page file')
|
||||
copy02' (ths/get-shape file' :copy02)
|
||||
@ -1660,7 +1621,7 @@
|
||||
rect01 (get-in page [:objects (:id rect01)])
|
||||
|
||||
;; ==== Action
|
||||
file' (tho/swap-component file copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
file' (tho/swap-component-in-shape file :copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
|
||||
page' (thf/current-page file')
|
||||
copy02' (ths/get-shape file' :copy02)
|
||||
@ -1714,7 +1675,7 @@
|
||||
rect01 (get-in page [:objects (:id rect01)])
|
||||
|
||||
;; ==== Action
|
||||
file' (tho/swap-component file copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
file' (tho/swap-component-in-shape file :copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
|
||||
page' (thf/current-page file')
|
||||
copy02' (ths/get-shape file' :copy02)
|
||||
@ -1763,7 +1724,7 @@
|
||||
rect01 (get-in page [:objects (:id rect01)])
|
||||
|
||||
;; ==== Action
|
||||
file' (tho/swap-component file copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
file' (tho/swap-component-in-shape file :copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
|
||||
page' (thf/current-page file')
|
||||
copy02' (ths/get-shape file' :copy02)
|
||||
@ -1812,7 +1773,7 @@
|
||||
rect01 (get-in page [:objects (:id rect01)])
|
||||
|
||||
;; ==== Action
|
||||
file' (tho/swap-component file copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
file' (tho/swap-component-in-shape file :copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
|
||||
page' (thf/current-page file')
|
||||
copy02' (ths/get-shape file' :copy02)
|
||||
@ -1859,7 +1820,7 @@
|
||||
rect01 (get-in page [:objects (:id rect01)])
|
||||
|
||||
;; ==== Action
|
||||
file' (tho/swap-component file copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
file' (tho/swap-component-in-shape file :copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
|
||||
page' (thf/current-page file')
|
||||
copy02' (ths/get-shape file' :copy02)
|
||||
@ -1910,7 +1871,7 @@
|
||||
rect01 (get-in page [:objects (:id rect01)])
|
||||
|
||||
;; ==== Action
|
||||
file' (tho/swap-component file copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
file' (tho/swap-component-in-shape file :copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
|
||||
page' (thf/current-page file')
|
||||
copy02' (ths/get-shape file' :copy02)
|
||||
@ -1956,7 +1917,7 @@
|
||||
rect01 (get-in page [:objects (:id rect01)])
|
||||
|
||||
;; ==== Action
|
||||
file' (tho/swap-component file copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
file' (tho/swap-component-in-shape file :copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
|
||||
page' (thf/current-page file')
|
||||
copy02' (ths/get-shape file' :copy02)
|
||||
@ -2023,7 +1984,7 @@
|
||||
text01 (get-in page [:objects (:id text01)])
|
||||
|
||||
;; ==== Action
|
||||
file' (tho/swap-component file copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
file' (tho/swap-component-in-shape file :copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
|
||||
page' (thf/current-page file')
|
||||
copy02' (ths/get-shape file' :copy02)
|
||||
@ -2055,7 +2016,7 @@
|
||||
rect01 (get-in page [:objects (-> copy01 :shapes first)])
|
||||
|
||||
;; ==== Action - Try to switch to a component with different shape type
|
||||
file' (tho/swap-component file copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
file' (tho/swap-component-in-shape file :copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
|
||||
page' (thf/current-page file')
|
||||
copy02' (ths/get-shape file' :copy02)
|
||||
@ -2098,7 +2059,7 @@
|
||||
path01 (get-in page [:objects (:id path01)])
|
||||
|
||||
;; ==== Action
|
||||
file' (tho/swap-component file copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
file' (tho/swap-component-in-shape file :copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
|
||||
page' (thf/current-page file')
|
||||
copy02' (ths/get-shape file' :copy02)
|
||||
@ -2146,7 +2107,7 @@
|
||||
rect01 (get-in page [:objects (:id rect01)])
|
||||
|
||||
;; ==== Action
|
||||
file' (tho/swap-component file copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
file' (tho/swap-component-in-shape file :copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
|
||||
page' (thf/current-page file')
|
||||
copy02' (ths/get-shape file' :copy02)
|
||||
@ -2190,7 +2151,7 @@
|
||||
rect01 (get-in page [:objects (-> copy01 :shapes first)])
|
||||
|
||||
;; ==== Action
|
||||
file' (tho/swap-component file copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
file' (tho/swap-component-in-shape file :copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
|
||||
page' (thf/current-page file')
|
||||
copy02' (ths/get-shape file' :copy02)
|
||||
@ -2243,7 +2204,7 @@
|
||||
old-position-data (:position-data text01)
|
||||
|
||||
;; ==== Action
|
||||
file' (tho/swap-component file copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
file' (tho/swap-component-in-shape file :copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
|
||||
page' (thf/current-page file')
|
||||
copy02' (ths/get-shape file' :copy02)
|
||||
@ -2306,7 +2267,7 @@
|
||||
rect01 (get-in page [:objects (:id rect01)])
|
||||
|
||||
;; ==== Action
|
||||
file' (tho/swap-component file copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
file' (tho/swap-component-in-shape file :copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
|
||||
page' (thf/current-page file')
|
||||
copy02' (ths/get-shape file' :copy02)
|
||||
@ -2357,7 +2318,7 @@
|
||||
rect01 (get-in page [:objects (:id rect01)])
|
||||
|
||||
;; ==== Action
|
||||
file' (tho/swap-component file copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
file' (tho/swap-component-in-shape file :copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
|
||||
page' (thf/current-page file')
|
||||
copy02' (ths/get-shape file' :copy02)
|
||||
@ -2411,7 +2372,7 @@
|
||||
rect01 (get-in page [:objects (:id rect01)])
|
||||
|
||||
;; ==== Action
|
||||
file' (tho/swap-component file copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
file' (tho/swap-component-in-shape file :copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
|
||||
page' (thf/current-page file')
|
||||
copy02' (ths/get-shape file' :copy02)
|
||||
@ -2468,7 +2429,7 @@
|
||||
rect01 (get-in page [:objects (:id rect01)])
|
||||
|
||||
;; ==== Action
|
||||
file' (tho/swap-component file copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
file' (tho/swap-component-in-shape file :copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
|
||||
page' (thf/current-page file')
|
||||
copy02' (ths/get-shape file' :copy02)
|
||||
@ -2532,7 +2493,7 @@
|
||||
rect01 (get-in page [:objects (:id rect01)])
|
||||
|
||||
;; ==== Action
|
||||
file' (tho/swap-component file copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
file' (tho/swap-component-in-shape file :copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
|
||||
page' (thf/current-page file')
|
||||
copy02' (ths/get-shape file' :copy02)
|
||||
@ -2588,7 +2549,7 @@
|
||||
rect01 (get-in page [:objects (:id rect01)])
|
||||
|
||||
;; ==== Action
|
||||
file' (tho/swap-component file copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
file' (tho/swap-component-in-shape file :copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
|
||||
page' (thf/current-page file')
|
||||
copy02' (ths/get-shape file' :copy02)
|
||||
@ -2653,7 +2614,7 @@
|
||||
rect01 (get-in page [:objects (:id rect01)])
|
||||
|
||||
;; ==== Action
|
||||
file' (tho/swap-component file copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
file' (tho/swap-component-in-shape file :copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
|
||||
page' (thf/current-page file')
|
||||
copy02' (ths/get-shape file' :copy02)
|
||||
@ -2710,7 +2671,7 @@
|
||||
rect01 (get-in page [:objects (:id rect01)])
|
||||
|
||||
;; ==== Action
|
||||
file' (tho/swap-component file copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
file' (tho/swap-component-in-shape file :copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||
|
||||
page' (thf/current-page file')
|
||||
copy02' (ths/get-shape file' :copy02)
|
||||
|
||||
@ -57,3 +57,38 @@
|
||||
|
||||
(t/testing "leaves filename intact when it has no extension"
|
||||
(t/is (= (media/strip-image-extension "README") "README"))))
|
||||
|
||||
(t/deftest test-font-display-variant
|
||||
(t/testing "preserves the foundry-supplied variant string verbatim"
|
||||
(t/is (= "Thin" (media/font-display-variant "Thin" 100 "normal")))
|
||||
(t/is (= "SemiBold" (media/font-display-variant "SemiBold" 600 "normal")))
|
||||
(t/is (= "Medium Oblique" (media/font-display-variant "Medium Oblique" 500 "italic")))
|
||||
(t/is (= "Ultra" (media/font-display-variant "Ultra" 900 "normal"))))
|
||||
|
||||
(t/testing "trims surrounding whitespace from upstream variant strings"
|
||||
(t/is (= "Bold" (media/font-display-variant " Bold " 700 "normal"))))
|
||||
|
||||
(t/testing "ignores blank or nil variant strings"
|
||||
(t/is (= "Hairline" (media/font-display-variant nil 100 "normal")))
|
||||
(t/is (= "Regular" (media/font-display-variant "" 400 "normal")))
|
||||
(t/is (= "Bold" (media/font-display-variant " " 700 "normal")))
|
||||
(t/is (= "Bold Italic" (media/font-display-variant nil 700 "italic"))))
|
||||
|
||||
(t/testing "fallback covers every supported numeric weight"
|
||||
(t/is (= "Hairline" (media/font-display-variant nil 100 "normal")))
|
||||
(t/is (= "Extra Light" (media/font-display-variant nil 200 "normal")))
|
||||
(t/is (= "Light" (media/font-display-variant nil 300 "normal")))
|
||||
(t/is (= "Regular" (media/font-display-variant nil 400 "normal")))
|
||||
(t/is (= "Medium" (media/font-display-variant nil 500 "normal")))
|
||||
(t/is (= "Semi Bold" (media/font-display-variant nil 600 "normal")))
|
||||
(t/is (= "Bold" (media/font-display-variant nil 700 "normal")))
|
||||
(t/is (= "Extra Bold" (media/font-display-variant nil 800 "normal")))
|
||||
(t/is (= "Black" (media/font-display-variant nil 900 "normal")))
|
||||
(t/is (= "Extra Black" (media/font-display-variant nil 950 "normal"))))
|
||||
|
||||
(t/testing "italic suffix only applied via the fallback path"
|
||||
(t/is (= "Italic" (media/font-display-variant "Italic" 400 "italic")))
|
||||
(t/is (= "Regular Italic" (media/font-display-variant nil 400 "italic"))))
|
||||
|
||||
(t/testing "stored variant survives even when its derived weight disagrees"
|
||||
(t/is (= "Ultra" (media/font-display-variant "Ultra" 400 "normal")))))
|
||||
|
||||
@ -15,6 +15,7 @@
|
||||
[common-tests.files-builder-test]
|
||||
[common-tests.files-changes-test]
|
||||
[common-tests.files-migrations-test]
|
||||
[common-tests.files.shapes-builder-test]
|
||||
[common-tests.geom-align-test]
|
||||
[common-tests.geom-bounds-map-test]
|
||||
[common-tests.geom-flex-layout-test]
|
||||
|
||||
@ -164,3 +164,78 @@
|
||||
{:color "#ffffff" :opacity 1.0 :offset 0.5}]
|
||||
result (colors/interpolate-gradient stops 1.0)]
|
||||
(t/is (= "#ffffff" (:color result))))))
|
||||
|
||||
(t/deftest rgb-to-hsb
|
||||
;; Achromatic black: brightness 0
|
||||
(let [[h s b] (colors/rgb->hsb [0 0 0])]
|
||||
(t/is (= 0 h))
|
||||
(t/is (= 0 s))
|
||||
(t/is (mth/close? b 0.0)))
|
||||
;; Pure red: hue 0, full saturation, brightness 100
|
||||
(let [[h s b] (colors/rgb->hsb [255 0 0])]
|
||||
(t/is (mth/close? h 0.0))
|
||||
(t/is (mth/close? s 1.0))
|
||||
(t/is (mth/close? b 100.0)))
|
||||
;; Pure white: brightness 100
|
||||
(let [[_ _ b] (colors/rgb->hsb [255 255 255])]
|
||||
(t/is (mth/close? b 100.0)))
|
||||
;; Mid gray: brightness ~50.2
|
||||
(let [[_ _ b] (colors/rgb->hsb [128 128 128])]
|
||||
(t/is (mth/close? b (* (/ 128.0 255.0) 100.0)))))
|
||||
|
||||
(t/deftest hsb-to-rgb
|
||||
(t/is (= [0 0 0] (colors/hsb->rgb [0 0 0])))
|
||||
(t/is (= [255 255 255] (colors/hsb->rgb [0 0 100])))
|
||||
;; Pure red from HSB
|
||||
(let [[r g b] (colors/hsb->rgb [0 1 100])]
|
||||
(t/is (= 255 r))
|
||||
(t/is (= 0 g))
|
||||
(t/is (= 0 b))))
|
||||
|
||||
(t/deftest hex-to-hsb
|
||||
;; Black
|
||||
(let [[h s b] (colors/hex->hsb "#000000")]
|
||||
(t/is (= 0 h))
|
||||
(t/is (= 0 s))
|
||||
(t/is (mth/close? b 0.0)))
|
||||
;; White: brightness 100
|
||||
(let [[_ _ b] (colors/hex->hsb "#ffffff")]
|
||||
(t/is (mth/close? b 100.0)))
|
||||
;; Red
|
||||
(let [[h s b] (colors/hex->hsb "#ff0000")]
|
||||
(t/is (mth/close? h 0.0))
|
||||
(t/is (mth/close? s 1.0))
|
||||
(t/is (mth/close? b 100.0))))
|
||||
|
||||
(t/deftest hsb-to-hex
|
||||
(t/is (= "#000000" (colors/hsb->hex [0 0 0])))
|
||||
(t/is (= "#ffffff" (colors/hsb->hex [0 0 100]))))
|
||||
|
||||
(t/deftest hsv-hsb-roundtrip
|
||||
;; HSV brightness is 0-255, HSB brightness is 0-100. Round-trip
|
||||
;; should reach the same triple within ±1 (integer rounding).
|
||||
(let [orig [210.0 0.5 128]
|
||||
hsb (colors/hsv->hsb orig)
|
||||
result (colors/hsb->hsv hsb)]
|
||||
(t/is (mth/close? (nth orig 0) (nth result 0)))
|
||||
(t/is (mth/close? (nth orig 1) (nth result 1)))
|
||||
(t/is (< (mth/abs (- (nth orig 2) (nth result 2))) 2))))
|
||||
|
||||
(t/deftest rgb-hsb-roundtrip
|
||||
;; RGB → HSB → RGB should land within ±1 per channel
|
||||
(let [orig [100 150 200]
|
||||
hsb (colors/rgb->hsb orig)
|
||||
result (colors/hsb->rgb hsb)]
|
||||
(t/is (every? true? (map #(< (mth/abs (- %1 %2)) 2) orig result)))))
|
||||
|
||||
(t/deftest hex-hsb-roundtrip
|
||||
;; HEX → HSB → HEX should preserve the color across the model swap
|
||||
(let [orig "#fabada"
|
||||
hsb (colors/hex->hsb orig)
|
||||
result (colors/hsb->hex hsb)]
|
||||
;; Allow ±1 per channel after the round-trip due to integer rounding
|
||||
(let [[r1 g1 b1] (colors/hex->rgb orig)
|
||||
[r2 g2 b2] (colors/hex->rgb result)]
|
||||
(t/is (< (mth/abs (- r1 r2)) 2))
|
||||
(t/is (< (mth/abs (- g1 g2)) 2))
|
||||
(t/is (< (mth/abs (- b1 b2)) 2)))))
|
||||
|
||||
@ -6,9 +6,13 @@
|
||||
|
||||
(ns common-tests.types.components-test
|
||||
(:require
|
||||
[app.common.test-helpers.components :as thc]
|
||||
[app.common.test-helpers.compositions :as tho]
|
||||
[app.common.test-helpers.files :as thf]
|
||||
[app.common.test-helpers.ids-map :as thi]
|
||||
[app.common.test-helpers.shapes :as ths]
|
||||
[app.common.types.component :as ctk]
|
||||
[app.common.types.file :as ctf]
|
||||
[clojure.test :as t]))
|
||||
|
||||
(t/use-fixtures :each thi/test-fixture)
|
||||
@ -39,3 +43,357 @@
|
||||
(t/is (= (ctk/get-swap-slot s4) #uuid "9cc181fa-5eef-8084-8004-7bb2ab45fd1f"))
|
||||
(t/is (= (ctk/get-swap-slot s5) #uuid "9cc181fa-5eef-8084-8004-7bb2ab45fd1f"))
|
||||
(t/is (nil? (ctk/get-swap-slot s6)))))
|
||||
|
||||
(t/deftest test-find-near-match
|
||||
|
||||
(t/testing "shapes not in a component have no near match"
|
||||
(let [file
|
||||
;; :frame1 [:name Frame1]
|
||||
;; :child1 [:name Rect1]
|
||||
(-> (thf/sample-file :file1)
|
||||
(tho/add-frame-with-child :frame1 :shape1))
|
||||
|
||||
page (thf/current-page file)
|
||||
|
||||
frame1 (ths/get-shape file :frame1)
|
||||
shape1 (ths/get-shape file :shape1)
|
||||
|
||||
near-match1 (ctf/find-near-match file page {} frame1)
|
||||
near-match2 (ctf/find-near-match file page {} shape1)]
|
||||
|
||||
(t/is (nil? near-match1))
|
||||
(t/is (nil? near-match2))))
|
||||
|
||||
(t/testing "shapes in a copy get the ref-shape"
|
||||
(let [file
|
||||
;; {:main-root} [:name Frame1] # [Component :component1]
|
||||
;; :main-child1 [:name Rect1]
|
||||
;; :main-child2 [:name Rect2]
|
||||
;; :main-child3 [:name Rect3]
|
||||
;;
|
||||
;; :copy-root [:name Frame1] #--> [Component :component1] :main-root
|
||||
;; <no-label> [:name Rect1] ---> :main-child1
|
||||
;; <no-label> [:name Rect2] ---> :main-child2
|
||||
;; <no-label> [:name Rect3] ---> :main-child3
|
||||
(-> (thf/sample-file :file1)
|
||||
(tho/add-component-with-many-children-and-copy :component1
|
||||
:main-root [:main-child1 :main-child2 :main-child3]
|
||||
:copy-root))
|
||||
|
||||
page (thf/current-page file)
|
||||
|
||||
main-root (ths/get-shape file :main-root)
|
||||
main-child1 (ths/get-shape file :main-child1)
|
||||
main-child2 (ths/get-shape file :main-child2)
|
||||
main-child3 (ths/get-shape file :main-child3)
|
||||
copy-root (ths/get-shape file :copy-root)
|
||||
copy-child1 (ths/get-shape-by-id file (nth (:shapes copy-root) 0))
|
||||
copy-child2 (ths/get-shape-by-id file (nth (:shapes copy-root) 1))
|
||||
copy-child3 (ths/get-shape-by-id file (nth (:shapes copy-root) 2))
|
||||
|
||||
near-main-root (ctf/find-near-match file page {} main-root)
|
||||
near-main-child1 (ctf/find-near-match file page {} main-child1)
|
||||
near-main-child2 (ctf/find-near-match file page {} main-child2)
|
||||
near-main-child3 (ctf/find-near-match file page {} main-child3)
|
||||
near-copy-root (ctf/find-near-match file page {} copy-root)
|
||||
near-copy-child1 (ctf/find-near-match file page {} copy-child1)
|
||||
near-copy-child2 (ctf/find-near-match file page {} copy-child2)
|
||||
near-copy-child3 (ctf/find-near-match file page {} copy-child3)]
|
||||
|
||||
(t/is (nil? near-main-root))
|
||||
(t/is (nil? near-main-child1))
|
||||
(t/is (nil? near-main-child2))
|
||||
(t/is (nil? near-main-child3))
|
||||
(t/is (nil? near-copy-root))
|
||||
(t/is (= (:id near-copy-child1) (thi/id :main-child1)))
|
||||
(t/is (= (:id near-copy-child2) (thi/id :main-child2)))
|
||||
(t/is (= (:id near-copy-child3) (thi/id :main-child3)))))
|
||||
|
||||
(t/testing "shapes in nested not swapped copies get the ref-shape"
|
||||
(let [file
|
||||
;; {:main1-root} [:name Frame1] # [Component :component1]
|
||||
;; :main1-child [:name Rect1]
|
||||
;;
|
||||
;; {:main2-root} [:name Frame2] # [Component :component2]
|
||||
;; :nested-head [:name Frame1] @--> [Component :component1] :main1-root
|
||||
;; :nested-child [:name Rect1] ---> :main1-child
|
||||
;;
|
||||
;; :copy2 [:name Frame2] #--> [Component :component2] :main2-root
|
||||
;; :copy2-nested-head [:name Frame1] @--> [Component :component1] :nested-head
|
||||
;; :copy2-nested-child [:name Rect1] ---> :nested-child
|
||||
(-> (thf/sample-file :file1)
|
||||
(tho/add-nested-component :component1 :main1-root :main1-child
|
||||
:component2 :main2-root :nested-head
|
||||
:nested-head-params {:children-labels [:nested-child]})
|
||||
(thc/instantiate-component :component2 :copy2
|
||||
:children-labels [:copy2-nested-head :copy2-nested-child]))
|
||||
|
||||
page (thf/current-page file)
|
||||
|
||||
main1-root (ths/get-shape file :main1-root)
|
||||
main1-child (ths/get-shape file :main1-child)
|
||||
main2-root (ths/get-shape file :main2-root)
|
||||
nested-head (ths/get-shape file :nested-head)
|
||||
nested-child (ths/get-shape file :nested-child)
|
||||
copy2 (ths/get-shape file :copy2)
|
||||
copy2-nested-head (ths/get-shape file :copy2-nested-head)
|
||||
copy2-nested-child (ths/get-shape file :copy2-nested-child)
|
||||
|
||||
near-main1-root (ctf/find-near-match file page {} main1-root)
|
||||
near-main1-child (ctf/find-near-match file page {} main1-child)
|
||||
near-main2-root (ctf/find-near-match file page {} main2-root)
|
||||
near-nested-head (ctf/find-near-match file page {} nested-head)
|
||||
near-nested-child (ctf/find-near-match file page {} nested-child)
|
||||
near-copy2 (ctf/find-near-match file page {} copy2)
|
||||
near-copy2-nested-head (ctf/find-near-match file page {} copy2-nested-head)
|
||||
near-copy2-nested-child (ctf/find-near-match file page {} copy2-nested-child)]
|
||||
|
||||
(t/is (nil? near-main1-root))
|
||||
(t/is (nil? near-main1-child))
|
||||
(t/is (nil? near-main2-root))
|
||||
(t/is (nil? near-nested-head))
|
||||
(t/is (= (:id near-nested-child) (thi/id :main1-child)))
|
||||
(t/is (nil? near-copy2))
|
||||
(t/is (= (:id near-copy2-nested-head) (thi/id :nested-head)))
|
||||
(t/is (= (:id near-copy2-nested-child) (thi/id :nested-child)))))
|
||||
|
||||
(t/testing "shapes in swapped copies get the swap slot"
|
||||
(let [file
|
||||
;; {:main1-root} [:name Frame1] # [Component :component1]
|
||||
;; :main1-child [:name Rect1]
|
||||
;;
|
||||
;; {:main2-root} [:name Frame2] # [Component :component2]
|
||||
;; :nested-head [:name Frame1] @--> [Component :component1] :main1-root
|
||||
;; :nested-child [:name Rect1] ---> :main1-child
|
||||
;;
|
||||
;; {:main3-root} [:name Frame3] # [Component :component3]
|
||||
;; :main3-child [:name Rect3]
|
||||
;;
|
||||
;; :copy2 [:name Frame2] #--> [Component :component2] :main2-root
|
||||
;; :copy2-nested-head [:name Frame3] @--> [Component :component3] :main3-root
|
||||
;; {swap-slot :nested-head}
|
||||
;; <no-label> [:name Rect3] ---> :main3-child
|
||||
(-> (thf/sample-file :file1)
|
||||
(tho/add-nested-component :component1 :main1-root :main1-child
|
||||
:component2 :main2-root :nested-head
|
||||
:nested-head-params {:children-labels [:nested-child]})
|
||||
(thc/instantiate-component :component2 :copy2 :children-labels [:copy2-nested-head])
|
||||
(tho/add-simple-component :component3 :main3-root :main3-child
|
||||
:root-params {:name "Frame3"}
|
||||
:child-params {:name "Rect3"})
|
||||
(tho/swap-component-in-first-child :copy2 :component3))
|
||||
|
||||
page (thf/current-page file)
|
||||
|
||||
main1-root (ths/get-shape file :main1-root)
|
||||
main1-child (ths/get-shape file :main1-child)
|
||||
main2-root (ths/get-shape file :main2-root)
|
||||
nested-head (ths/get-shape file :nested-head)
|
||||
nested-child (ths/get-shape file :nested-child)
|
||||
copy2 (ths/get-shape file :copy2)
|
||||
copy2-nested-head (ths/get-shape file :copy2-nested-head)
|
||||
copy2-nested-child (ths/get-shape-by-id file (first (:shapes copy2-nested-head)))
|
||||
|
||||
near-main1-root (ctf/find-near-match file page {} main1-root)
|
||||
near-main1-child (ctf/find-near-match file page {} main1-child)
|
||||
near-main2-root (ctf/find-near-match file page {} main2-root)
|
||||
near-nested-head (ctf/find-near-match file page {} nested-head)
|
||||
near-nested-child (ctf/find-near-match file page {} nested-child)
|
||||
near-copy2 (ctf/find-near-match file page {} copy2)
|
||||
near-copy2-nested-head (ctf/find-near-match file page {} copy2-nested-head)
|
||||
near-copy2-nested-child (ctf/find-near-match file page {} copy2-nested-child)]
|
||||
|
||||
(t/is (nil? near-main1-root))
|
||||
(t/is (nil? near-main1-child))
|
||||
(t/is (nil? near-main2-root))
|
||||
(t/is (nil? near-nested-head))
|
||||
(t/is (= (:id near-nested-child) (thi/id :main1-child)))
|
||||
(t/is (nil? near-copy2))
|
||||
(t/is (= (:id near-copy2-nested-head) (thi/id :nested-head)))
|
||||
(t/is (= (:id near-copy2-nested-child) (thi/id :main3-child)))))
|
||||
|
||||
(t/testing "shapes in second level nested copies under swapped get the shape in the new main"
|
||||
(let [file
|
||||
;; {:main1-root} [:name Frame1] # [Component :component1]
|
||||
;; :main1-child [:name Rect1]
|
||||
;;
|
||||
;; {:main2-root} [:name Frame2] # [Component :component2]
|
||||
;; :nested2-head [:name Frame1] @--> [Component :component1] :main1-root
|
||||
;; :nested2-child [:name Rect1] ---> :main1-child
|
||||
;;
|
||||
;; {:main3-root} [:name Frame3] # [Component :component3]
|
||||
;; :main3-child [:name Rect3]
|
||||
;;
|
||||
;; {:main4-root} [:name Frame4] # [Component :component4]
|
||||
;; :nested4-head [:name Frame3] @--> [Component :component1] :main3-root
|
||||
;; :nested4-child [:name Rect3] ---> :main3-child
|
||||
;;
|
||||
;; :copy2 [:name Frame2] #--> [Component :component2] :main2-root
|
||||
;; :copy2-nested-head [:name Frame4] @--> [Component :component4] :main4-root
|
||||
;; {swap-slot :nested2-head}
|
||||
;; <no-label> [:name Frame3] @--> :nested4-head
|
||||
;; <no-label> [:name Rect3] ---> :nested4-child
|
||||
(-> (thf/sample-file :file1)
|
||||
(tho/add-nested-component :component1 :main1-root :main1-child
|
||||
:component2 :main2-root :nested2-head
|
||||
:nested-head-params {:children-labels [:nested2-child]})
|
||||
(thc/instantiate-component :component2 :copy2 :children-labels [:copy2-nested-head])
|
||||
(tho/add-nested-component :component3 :main3-root :main3-child
|
||||
:component4 :main4-root :nested4-head
|
||||
:root1-params {:name "Frame3"}
|
||||
:main1-child-params {:name "Rect3"}
|
||||
:main2-root-params {:name "Frame4"}
|
||||
:nested-head-params {:children-labels [:nested4-child]})
|
||||
(tho/swap-component-in-first-child :copy2 :component4))
|
||||
|
||||
page (thf/current-page file)
|
||||
|
||||
main1-root (ths/get-shape file :main1-root)
|
||||
main1-child (ths/get-shape file :main1-child)
|
||||
main2-root (ths/get-shape file :main2-root)
|
||||
nested2-head (ths/get-shape file :nested2-head)
|
||||
nested2-child (ths/get-shape file :nested2-child)
|
||||
main3-root (ths/get-shape file :main3-root)
|
||||
main3-child (ths/get-shape file :main3-child)
|
||||
main4-root (ths/get-shape file :main4-root)
|
||||
nested4-head (ths/get-shape file :nested4-head)
|
||||
nested4-child (ths/get-shape file :nested4-child)
|
||||
copy2 (ths/get-shape file :copy2)
|
||||
copy2-nested-head (ths/get-shape file :copy2-nested-head)
|
||||
copy2-nested4-head (ths/get-shape-by-id file (first (:shapes copy2-nested-head)))
|
||||
copy2-nested4-child (ths/get-shape-by-id file (first (:shapes copy2-nested4-head)))
|
||||
|
||||
near-main1-root (ctf/find-near-match file page {} main1-root)
|
||||
near-main1-child (ctf/find-near-match file page {} main1-child)
|
||||
near-main2-root (ctf/find-near-match file page {} main2-root)
|
||||
near-nested2-head (ctf/find-near-match file page {} nested2-head)
|
||||
near-nested2-child (ctf/find-near-match file page {} nested2-child)
|
||||
near-main3-root (ctf/find-near-match file page {} main3-root)
|
||||
near-main3-child (ctf/find-near-match file page {} main3-child)
|
||||
near-main4-root (ctf/find-near-match file page {} main4-root)
|
||||
near-nested4-head (ctf/find-near-match file page {} nested4-head)
|
||||
near-nested4-child (ctf/find-near-match file page {} nested4-child)
|
||||
near-copy2 (ctf/find-near-match file page {} copy2)
|
||||
near-copy2-nested-head (ctf/find-near-match file page {} copy2-nested-head)
|
||||
near-copy2-nested4-head (ctf/find-near-match file page {} copy2-nested4-head)
|
||||
near-copy2-nested4-child (ctf/find-near-match file page {} copy2-nested4-child)]
|
||||
|
||||
(t/is (nil? near-main1-root))
|
||||
(t/is (nil? near-main1-child))
|
||||
(t/is (nil? near-main2-root))
|
||||
(t/is (nil? near-nested2-head))
|
||||
(t/is (= (:id near-nested2-child) (thi/id :main1-child)))
|
||||
(t/is (nil? near-main3-root))
|
||||
(t/is (nil? near-main3-child))
|
||||
(t/is (nil? near-main4-root))
|
||||
(t/is (nil? near-nested4-head))
|
||||
(t/is (= (:id near-nested4-child) (thi/id :main3-child)))
|
||||
(t/is (nil? near-copy2))
|
||||
(t/is (= (:id near-copy2-nested-head) (thi/id :nested2-head)))
|
||||
(t/is (= (:id near-copy2-nested4-head) (thi/id :nested4-head)))
|
||||
(t/is (= (:id near-copy2-nested4-child) (thi/id :nested4-child)))))
|
||||
|
||||
(t/testing "component in external libraries still work well"
|
||||
(let [library1
|
||||
;; {:main1-root} [:name Frame1] # [Component :component1]
|
||||
;; :main1-child [:name Rect1]
|
||||
;;
|
||||
;; {:main2-root} [:name Frame2] # [Component :component2]
|
||||
;; :nested2-head [:name Frame1] @--> [Component :component1] :main1-root
|
||||
;; :nested2-child [:name Rect1] ---> :main1-child
|
||||
(-> (thf/sample-file :library1)
|
||||
(tho/add-nested-component :component1 :main1-root :main1-child
|
||||
:component2 :main2-root :nested2-head
|
||||
:nested-head-params {:children-labels [:nested2-child]}))
|
||||
library2
|
||||
;; {:main3-root} [:name Frame3] # [Component :component3]
|
||||
;; :main3-child [:name Rect3]
|
||||
;;
|
||||
;; {:main4-root} [:name Frame4] # [Component :component4]
|
||||
;; :nested4-head [:name Frame3] @--> [Component :component1] :main3-root
|
||||
;; :nested4-child [:name Rect3] ---> :main3-child
|
||||
(-> (thf/sample-file :library2)
|
||||
(tho/add-nested-component :component3 :main3-root :main3-child
|
||||
:component4 :main4-root :nested4-head
|
||||
:root1-params {:name "Frame3"}
|
||||
:main1-child-params {:name "Rect3"}
|
||||
:main2-root-params {:name "Frame4"}
|
||||
:nested-head-params {:children-labels [:nested4-child]}))
|
||||
|
||||
file
|
||||
;; :copy2 [:name Frame2] #--> [Component :component2] :main2-root
|
||||
;; :copy2-nested-head [:name Frame4] @--> [Component :component4] :main4-root
|
||||
;; {swap-slot :nested2-head}
|
||||
;; <no-label> [:name Frame3] @--> :nested4-head
|
||||
;; <no-label> [:name Rect3] ---> :nested4-child
|
||||
(-> (thf/sample-file :file1)
|
||||
(thc/instantiate-component :component2 :copy2 :children-labels [:copy2-nested-head]
|
||||
:library library1)
|
||||
(tho/swap-component-in-first-child :copy2 :component4 :library library2))
|
||||
|
||||
page-library1 (thf/current-page library1)
|
||||
page-library2 (thf/current-page library2)
|
||||
page-file (thf/current-page file)
|
||||
libraries {(:id library1) library1
|
||||
(:id library2) library2}
|
||||
|
||||
main1-root (ths/get-shape library1 :main1-root)
|
||||
main1-child (ths/get-shape library1 :main1-child)
|
||||
main2-root (ths/get-shape library1 :main2-root)
|
||||
nested2-head (ths/get-shape library1 :nested2-head)
|
||||
nested2-child (ths/get-shape library1 :nested2-child)
|
||||
main3-root (ths/get-shape library2 :main3-root)
|
||||
main3-child (ths/get-shape library2 :main3-child)
|
||||
main4-root (ths/get-shape library2 :main4-root)
|
||||
nested4-head (ths/get-shape library2 :nested4-head)
|
||||
nested4-child (ths/get-shape library2 :nested4-child)
|
||||
copy2 (ths/get-shape file :copy2)
|
||||
copy2-nested-head (ths/get-shape file :copy2-nested-head)
|
||||
copy2-nested4-head (ths/get-shape-by-id file (first (:shapes copy2-nested-head)))
|
||||
copy2-nested4-child (ths/get-shape-by-id file (first (:shapes copy2-nested4-head)))
|
||||
|
||||
near-main1-root (ctf/find-near-match file page-file libraries main1-root)
|
||||
near-main1-child (ctf/find-near-match file page-file libraries main1-child)
|
||||
near-main2-root (ctf/find-near-match file page-file libraries main2-root)
|
||||
near-nested2-head (ctf/find-near-match library1 page-library1 libraries nested2-head)
|
||||
near-nested2-child (ctf/find-near-match library1 page-library1 libraries nested2-child)
|
||||
near-main3-root (ctf/find-near-match file page-file libraries main3-root)
|
||||
near-main3-child (ctf/find-near-match file page-file libraries main3-child)
|
||||
near-main4-root (ctf/find-near-match file page-file libraries main4-root)
|
||||
near-nested4-head (ctf/find-near-match library2 page-library2 libraries nested4-head)
|
||||
near-nested4-child (ctf/find-near-match library2 page-library2 libraries nested4-child)
|
||||
near-copy2 (ctf/find-near-match file page-file libraries copy2)
|
||||
near-copy2-nested-head (ctf/find-near-match file page-file libraries copy2-nested-head)
|
||||
near-copy2-nested4-head (ctf/find-near-match file page-file libraries copy2-nested4-head)
|
||||
near-copy2-nested4-child (ctf/find-near-match file page-file libraries copy2-nested4-child)]
|
||||
|
||||
(thf/dump-file library1 :keys [:name :swap-slot-label] :show-refs? true)
|
||||
(t/is (some? main1-root))
|
||||
(t/is (some? main1-child))
|
||||
(t/is (some? main2-root))
|
||||
(t/is (some? nested2-head))
|
||||
(t/is (some? nested2-child))
|
||||
(t/is (some? main3-root))
|
||||
(t/is (some? main3-child))
|
||||
(t/is (some? main4-root))
|
||||
(t/is (some? nested4-head))
|
||||
(t/is (some? nested4-child))
|
||||
(t/is (some? copy2))
|
||||
(t/is (some? copy2-nested-head))
|
||||
(t/is (some? copy2-nested4-head))
|
||||
(t/is (some? copy2-nested4-child))
|
||||
|
||||
(t/is (nil? near-main1-root))
|
||||
(t/is (nil? near-main1-child))
|
||||
(t/is (nil? near-main2-root))
|
||||
(t/is (nil? near-nested2-head))
|
||||
(t/is (= (:id near-nested2-child) (thi/id :main1-child)))
|
||||
(t/is (nil? near-main3-root))
|
||||
(t/is (nil? near-main3-child))
|
||||
(t/is (nil? near-main4-root))
|
||||
(t/is (nil? near-nested4-head))
|
||||
(t/is (= (:id near-nested4-child) (thi/id :main3-child)))
|
||||
(t/is (nil? near-copy2))
|
||||
(t/is (= (:id near-copy2-nested-head) (thi/id :nested2-head)))
|
||||
(t/is (= (:id near-copy2-nested4-head) (thi/id :nested4-head)))
|
||||
(t/is (= (:id near-copy2-nested4-child) (thi/id :nested4-child))))))
|
||||
|
||||
@ -667,6 +667,41 @@
|
||||
result (path.subpath/close-subpaths content)]
|
||||
(t/is (seq result)))))
|
||||
|
||||
(t/deftest subpath-merge-touching-subpaths
|
||||
(t/testing "adjacent subpaths sharing an endpoint collapse into one chain"
|
||||
;; Heroicons-style fragment: continuous polyline split as M-L M-L M-L
|
||||
;; with the second/third subpath starting at the first's endpoint.
|
||||
(let [content [{:command :move-to :params {:x 0.0 :y 10.0}}
|
||||
{:command :line-to :params {:x 10.0 :y 10.0}}
|
||||
{:command :move-to :params {:x 10.0 :y 10.0}}
|
||||
{:command :line-to :params {:x 5.0 :y 0.0}}
|
||||
{:command :move-to :params {:x 10.0 :y 10.0}}
|
||||
{:command :line-to :params {:x 5.0 :y 20.0}}]
|
||||
result (path.subpath/merge-touching-subpaths content)
|
||||
moves (filter #(= :move-to (:command %)) result)]
|
||||
;; Subpaths 1+2 share (10,10) → merged. Subpath 3 also starts at (10,10),
|
||||
;; but the merged chain now ends at (5,0), so it does NOT match and
|
||||
;; is preserved as its own subpath. Two move-tos in the final result.
|
||||
(t/is (= 2 (count moves)))
|
||||
(t/is (= 5 (count result)))))
|
||||
(t/testing "non-touching subpaths are left untouched"
|
||||
(let [content [{:command :move-to :params {:x 0.0 :y 0.0}}
|
||||
{:command :line-to :params {:x 5.0 :y 0.0}}
|
||||
{:command :move-to :params {:x 50.0 :y 50.0}}
|
||||
{:command :line-to :params {:x 60.0 :y 60.0}}]
|
||||
result (path.subpath/merge-touching-subpaths content)]
|
||||
(t/is (= content (vec result)))))
|
||||
(t/testing "closed subpath is not absorbed into a neighbour"
|
||||
(let [content [{:command :move-to :params {:x 0.0 :y 0.0}}
|
||||
{:command :line-to :params {:x 5.0 :y 0.0}}
|
||||
{:command :line-to :params {:x 5.0 :y 5.0}}
|
||||
{:command :line-to :params {:x 0.0 :y 0.0}}
|
||||
{:command :move-to :params {:x 0.0 :y 0.0}}
|
||||
{:command :line-to :params {:x 1.0 :y 1.0}}]
|
||||
result (path.subpath/merge-touching-subpaths content)
|
||||
moves (filter #(= :move-to (:command %)) result)]
|
||||
(t/is (= 2 (count moves))))))
|
||||
|
||||
(t/deftest subpath-reverse-content
|
||||
(let [result (path.subpath/reverse-content simple-open-content)]
|
||||
(t/is (= (count simple-open-content) (count result)))
|
||||
@ -1100,6 +1135,24 @@
|
||||
(t/is (path/content? result))
|
||||
(t/is (seq (vec result)))))
|
||||
|
||||
(t/deftest path-merge-touching-subpaths
|
||||
(t/testing "regression for #5283 — heroicons arrow path serialises as a single chain"
|
||||
;; SVG `d` originally split a continuous polyline by inserting a
|
||||
;; redundant moveto at the elbow. Importing it must collapse the
|
||||
;; first two subpaths so that stroke-linejoin renders the rounded tip.
|
||||
(let [content (path/from-string
|
||||
(str "M350.5,1846 L365.5,1846"
|
||||
" M365.5,1846 L358.75,1839.25"
|
||||
" M365.5,1846 L358.75,1852.75"))
|
||||
merged (path/merge-touching-subpaths content)
|
||||
rendered (str merged)]
|
||||
(t/is (path/content? merged))
|
||||
;; First two subpaths fold into M ... L ... L ... ; third stays
|
||||
;; separate (its start point matches the original M, not the merged
|
||||
;; chain's tail), so exactly two M commands remain.
|
||||
(t/is (= 2 (count (re-seq #"M" rendered))))
|
||||
(t/is (= 3 (count (re-seq #"L" rendered)))))))
|
||||
|
||||
(t/deftest path-move-content
|
||||
(let [content (path/content sample-content-square)
|
||||
move-vec (gpt/point 3.0 4.0)
|
||||
|
||||
@ -1,2 +1,3 @@
|
||||
// Frontend configuration
|
||||
//var penpotFlags = "";
|
||||
//var penpotOIDCName = "";
|
||||
|
||||
@ -25,7 +25,16 @@ update_flags() {
|
||||
fi
|
||||
}
|
||||
|
||||
update_oidc_name() {
|
||||
if [ -n "$PENPOT_OIDC_NAME" ]; then
|
||||
echo "$(sed \
|
||||
-e "s|^//var penpotOIDCName = .*;|var penpotOIDCName = \"$PENPOT_OIDC_NAME\";|g" \
|
||||
"$1")" > "$1"
|
||||
fi
|
||||
}
|
||||
|
||||
update_flags /var/www/app/js/config.js
|
||||
update_oidc_name /var/www/app/js/config.js
|
||||
|
||||
#########################################
|
||||
## Nginx Config
|
||||
|
||||
@ -219,8 +219,9 @@ Now that everything is in place you need a <code class="language-js">manifest.js
|
||||
{
|
||||
"name": "Plugin name",
|
||||
"description": "Plugin description",
|
||||
"code": "/plugin.js",
|
||||
"icon": "/icon.png",
|
||||
"version": 2,
|
||||
"code": "plugin.js",
|
||||
"icon": "icon.png",
|
||||
"permissions": [
|
||||
"content:read",
|
||||
"content:write",
|
||||
@ -234,6 +235,13 @@ Now that everything is in place you need a <code class="language-js">manifest.js
|
||||
}
|
||||
```
|
||||
|
||||
<p class="advice">
|
||||
Use <code class="language-js">"version": 2</code> when your
|
||||
<code class="language-js">code</code> and <code class="language-js">icon</code> values
|
||||
are relative paths. Version 2 resolves these assets from the manifest location.
|
||||
If omitted, Penpot treats the manifest as version 1.
|
||||
</p>
|
||||
|
||||
### Icon
|
||||
|
||||
The plugin icon must be an image file. All image formats are valid, so you can use whichever format works best for your needs. Although there is no specific size requirement, it is recommended that the icon be 56x56 pixels in order to ensure its optimal appearance across all devices.
|
||||
|
||||
@ -131,6 +131,7 @@ The <code class="language-js">manifest.json</code> file contains the basic infor
|
||||
{
|
||||
"name": "Your plugin name",
|
||||
"description": "Your plugin description",
|
||||
"version": 2,
|
||||
"code": "plugin.js",
|
||||
"icon": "Your icon",
|
||||
"permissions": [
|
||||
@ -147,6 +148,12 @@ The <code class="language-js">manifest.json</code> file contains the basic infor
|
||||
}
|
||||
```
|
||||
|
||||
<p class="advice">
|
||||
Set <code class="language-js">"version": 2</code> in your
|
||||
<code class="language-js">manifest.json</code> if you use relative paths for
|
||||
<code class="language-js">code</code> or <code class="language-js">icon</code>.
|
||||
</p>
|
||||
|
||||
#### Properties
|
||||
|
||||
- **Name and description**: your plugin's basic information, which will be displayed in the plugin manager modal.
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user