Commit Graph

203 Commits

Author SHA1 Message Date
Artur Pata c4ea07d8bc
Fix /change-domain page permissions (#5939)
* Add test case

* Fix change domain permissions

* Update changelog

* Add more comprehensive tests for other roles
2025-12-10 09:44:23 +00:00
Uku Taht 3c9ba41cb6
Use prima modal in ip_rules settings (#5910)
* Use prima modal in ip_rules settings

* Remove unused alias

* Do not render portal in test environment - fixes tests

* Simplify invitation modal tests

* Bump CI cache version to rebuild with prima 0.2.1

The CI was using cached dependencies with prima 0.1.9, which doesn't
support the portal parameter needed for tests. Bumping the cache
version forces a rebuild with the correct prima 0.2.1 from mix.lock.

* CI debugging

* Use correct mix env

* Resolve mix.env() at compile-time
2025-11-27 13:22:05 +00:00
Adam Rutkowski 0eea55d1c1
Slurp common test modules into exunit templates (#5909)
* Slurp common test stuff into exunit templates

* !fixup

* !fixup

* !fixup

* !fixup
2025-11-24 13:30:06 +00:00
Uku Taht 16cbc07f3d
Use Prima for invitation modal (#5843)
* Replace invitation modal with Prima

* Better focus handling

* Simplify css

* Remove unnecessary transition classes

* Clarify comment about testing

* Fix typo

* Remove alpine.js initialization

* Use prima 0.1.7

* Unlock autumn and rustler deps

* Npm run format

* Fix invitation modal reject button on mobile

Co-authored-by: Bijay-Shre-stha <bijayashrestha929@gmail.com>

* Update assets/js/liveview/live_socket.js

Co-authored-by: Artur Pata <artur.pata@gmail.com>

---------

Co-authored-by: Bijay-Shre-stha <bijayashrestha929@gmail.com>
Co-authored-by: Artur Pata <artur.pata@gmail.com>
2025-11-04 19:21:05 +00:00
Adam Rutkowski bce08903e5
Integrate consolidated view UI (#5798)
* Create static consolidated view UI on `/sites` page

- Improve existing site card layout
- Add static UI for the consolidated view
- Add dismissable upgrade card UI
- Extract favicon fetching logic to function
- Configure configurable fallback icon per route
- Add `/favicon/sources_globe/` route with different icon than `/favicon/sources/` to use on `/sites` page

* Improve the mobile view of the `/sites` page

* Minor query interface UX extension (#5713)

* Minor query interface extension

* !fixup

* !fixup

* Initial implementation of consolidated views on /sites

* Improve loading state

* no need to handle nil in main interface

* Juggle `can_manage_consolidated_view?`

* Require team setup in order to enable consolidated view

* nil catcher

* Fixup test fixture

* Don't show Consolidated View tab in CS if team is not setup

* Reorganize + test

* Remove comment

* Only show consolidated views to superadmins for now

* Remove temporary sleep

* CE unused bindings

* Clean up seeds

* EE

* Fixup test

* Test non-superadmin scenario

* Add a test guarding parity between small plots (consolidated vs individual)

* Move private function so CE won't complain

* See if the graphs are now similar at least :)

* sort

* Map keys are unsorted

* Ensure engagement events aren't counted as visitors on smol graphs

* just try and revert

* Revert "just try and revert"

This reverts commit 7584f59816.

* Simplify globe icon handling

* Remove unnecessary @rest

* Split tests into more focused cases

* Address jumpiness on furious refresh cycle

* Revert "Address jumpiness on furious refresh cycle"

This reverts commit 5c03b36918.

* Another attempt at jumpiness

* Enforce less noticeable lag applying the diff from loading to loaded

* Reduce flashing on stats load

---------

Co-authored-by: Sanne de Vries <sannedv@protonmail.com>
2025-10-22 10:58:26 +00:00
Uku Taht 46000fd4bc
Implement custom date/time range comparisons (#5805)
* Implement custom date/time range comparisons

* Update ts schema

* Use Etc/UTC, not UTC - timezone shifted structs are differrent otherwise

* Remove debug statement

* Adjusts timezone in tests

---------

Co-authored-by: Adam Rutkowski <hq@mtod.org>
2025-10-16 06:14:49 +00:00
Uku Taht f3d326b735
Upgrade phoenix & liveview (#5766)
* Upgrade phoenix and phoenix_live_view

* Use new phoenix controller options

* Run mix format

* Upgrade lazy_html and bcrypt

* Always put root layout

* Remove deprecated use Plug.Test

* Escpaing updates for LazyHTML

* Fix double layouts in site settings

* Fix more escaping in tests

* More LazyHTML updates

* Fix remaining LazyHTML issues

* More Floki -> LazyHTML conversions

* More Floki -> LazyHTML conversions

* Fix another issue with Floki -> LazyHTML

* Fix another lazyHTML issue

* Remove parsing from tree

* Fix HTML escaping in teams_test

* More test fixes

* More test fixes

* Add layout to browser_sso_notice pipeline

* Extract elem_count helper
2025-10-07 12:29:48 +00:00
RobertJoonas cc06a351bd
Remove virtual rollups in favour of persisted consolidated sites (#5749)
* virtual rollups -> consolidated sites

* fix queryparser and test

* fix legacy_query_builder and test

* fix typespec

* simple consolidated view query test (Stats API)

* add test util

* skip verification on consolidated sites

* add test for internal (dashboard) stats query

* fix CE

* Fix showing consilidated stats on the dashboard

...by making sure site.native_stats_start_at and stats_start_date are
set.

* fix CE again

* add typespecs and tests for native_stats_start_at

* skip else clause

* use ConsolidatedView.enable in test util

* defensive where builder

* remove redundant cache

* get query.consolidated_site_ids from cache

* fix test

* fix CE

* fix CE again

* eligibility check when enabling cvs

* create cvs with native_stats_start_at assigned already

* fix dialyzer warning
2025-09-25 13:58:32 +00:00
Adam Rutkowski 54a66c2fc8
`ConsolidatedView.Cache` - first pass (#5748)
* Introduce `ConsolidatedView.Cache`

* Make the small refresh faster (probably better planner hinting?)

Courtesy by @zoldar

Co-authored-by: Adrian Gruntkowski <adrian.gruntkowski@gmail.com>

* Revert "Make the small refresh faster (probably better planner hinting?)"

This reverts commit 03d18bc4ff.

* Clarify query ordering

* Fix get_from_source/1

* Fixup typespecs

---------

Co-authored-by: Adrian Gruntkowski <adrian.gruntkowski@gmail.com>
2025-09-25 10:16:35 +00:00
Artur Pata a0e5f801ff
Script v2: Maybe load installation type from DB (#5717)
* Maybe load installation type from DB

* Swap get_or_create... with get_tracker_script_configuration

* Fix getting saved_installation_type

* Add utility to htmlize quotes

* Update manual snippet not found error text

* Prevent custom URL input if scriptv2 not true

* Test verification v2 flows

* Fix import for CE test
2025-09-16 05:28:36 +00:00
Artur Pata f7acb068d4
Script v2: Change priority of CSP related error for verifying manual installations (#5707)
* Add logic to find Plausible script tag

* Clarify where cookies fixtures come from

* Add case for snippet not found

* Fix issue with installation type not propagating to diagnostics

* Better struct definition

* Refactor verification tests to be more comprehensive

* Fix compile error related to Test.Support.DNS

* Fix DNS imports for CE

* Refactor when tracker is in HTML is detected
2025-09-11 06:59:03 +00:00
Adrian Gruntkowski 8d6d828d1d
Reduce reliance on `Timex` and use native time API where feasible (#5712)
* Replace usages of `Timex.to_unix` with native API

* Wrap call to `Timex.is_valid_timezone?`

* Wrap calls to `Timex.today(tz)`

* Replace `Timex.today()` with `Date.utc_today()`

* Replace `Timex.now()` with `DateTime.utc_now()`

* Replace `Timex.compare` with `Date.compare`

* Wrap `Timex.diff` calls

* Replace `Timex.Timezone.convert` with `DateTime.shift_zone!`

* Wrap `Timex.parse!`

* Replace `Timex.to_date` with native API calls

* Replace `Timex.beginning|end_of...` with native API calls for Date

* Wrap `Timex.beginning|end_of...` for DateTimes and Dates for years

* Replace `Timex.format(!)` with native API calls

* Replace `Timex.to_naive_datetime` with native API calls

* Wrap time humanizing routines using Timex

* Remove unnecessary `use Timex` instances

* Replace `Timex.shift` with native API calls

* Make `QueryParser.parse_date` handle gaps and ambiguities gracefully

* Replace `Timex.now(tz)` with `DateTime.now!(tz)`

* Use a more suitable Date function for comparison (h/t @aerosol)
2025-09-10 10:21:36 +00:00
Adam Rutkowski afbc350b8d
CRM: implement basic SSO audit browser (#5586)
* Allow storing audit entry "change" raw

* Modify audit test helpers so they return actual audit entries

* Accept optional `rows` in input textarea component

* Instrument SAML consumption with audit entries

* :nail-care: EE-only modules don't need `on_ee`

* Derive audit encoder for SSO Identity

* Implement Audit tab in CRM

* Fix typo

* Instrument domain removal with audit entries

* Preload `sso_integration` for domain removal

* Use two else clauses for SAML consume errors
2025-07-23 16:45:33 +00:00
Adam Rutkowski adf39ca7a8
Audit trail for SSO (#5560)
* 

* wip

* wip

* Moduledoc false

* wip

* Update extra/lib/plausible/auth/sso/saml_config.ex

Co-authored-by: Adrian Gruntkowski <adrian.gruntkowski@gmail.com>

* Include only data keys present in changes

* Improve audit logging for SSO domain verification

Make it more compact and hopefully more readable to CS

* Harden existing tests

* Use consistent naming

* Update audit entries migration: use UUIDs for primary keys

* Fix up tests

* Format

* Only test audit for EE

* Remove temporary String.Chars implementation

* Always log keys as per `derive` directive; include changes for inserts

* Write `actor_type` to audit entries

* Extract Audit.Repo functions

* Moduledocs

* Include change in audited deletions

* Make audit available only in EE build

A bit clunky? cc @zoldar

* Put test behind ee compilation flag

* Pin user e-mail in test

* Ensure encoder opts are passed for nested calls

* Carry `__allow_not_loaded__` even if no extractor defined

* Turn `actor_type` into an ecto enum type

* Remove unused function

* s/sso_forced/sso_force_mode_changed

* Unwrap single item list for protocol implementation

Co-authored-by: Adrian Gruntkowski <adrian.gruntkowski@gmail.com>

* Migration: audit entries (#5581)

* Migration: audit entries

* Put migration behind EE conditional

---------

Co-authored-by: Adrian Gruntkowski <adrian.gruntkowski@gmail.com>
2025-07-22 10:53:24 +00:00
Adrian Gruntkowski a3c4d06fce
Use integration from identity during verification (#5578)
* Pass integration ID from SAML session in trusted identity struct

* Use integration from identity during verification
2025-07-21 15:26:37 +00:00
Adrian Gruntkowski 39656f782c
Implement listing and revoking of SSO sessions from team settings (#5529)
* Refactor and unify logic for account and site settings sidebars

* Implement listing and revoking of SSO sessions from team settings
2025-06-26 08:48:25 +00:00
Adam Rutkowski ef11425693
Calmer multiple teams experience (#5526)
* Offer team switcher on /sites if applicable

- in case of empty My Personal Sites view, and with
  another team with sites being available
- redirect straight to first team upon invoking team
  switcher, if there's only one available
- redirect to /sites from team switcher, if there
  are no set-up teams available

* Remove unused test helper

* Store and use last team identifier

* Remove alert about starting trial when adding first site

* Format

* Update lib/plausible_web/live/sites.ex

Co-authored-by: Adrian Gruntkowski <adrian.gruntkowski@gmail.com>

---------

Co-authored-by: Adrian Gruntkowski <adrian.gruntkowski@gmail.com>
2025-06-24 16:11:27 +00:00
Adrian Gruntkowski a2ed1e04b1
Revise system behaviour for SSO users (#5506)
* Setup MFA properly in SSO tests

* Move `new_identity` test helper to common helpers

* Make standard login only allow Owner SSO users

* Implement `Plausible.Users.type/1` for determining user type

* Implement plug restricting action based on user type

* Restrict or adjust access to settings actions to SSO users

* Make a very small refactor to `Auth.SSO` helper

* Prevent SSO users from acceptig team invitations

* Prevent SSO users from adding websites under "My Presonal Sites"

* Prevent implicit team creation by SSO users

* Add workaround for compiler warning under CE

* Remove SSO user on removing membership

* Prevent changing role to owner when 2FA not enabled

* Prevent provisioning from standard user with active personal team

* Fix `Auth.lookup/1` to not break for standard users on multiple teams

* Use `Plausible.always/1` (h/t @aerosol)

* Revert "Use `Plausible.always/1` (h/t @aerosol)"

This reverts commit 0ee7dd84d3.

* Rename `RestrictType` -> `RestrictUserType`

* Make the configuration intent more explicit in `RestrictUserType` plug

* Rename plug file
2025-06-23 08:19:12 +00:00
hq1 6040bed54b
SSO Domain Validation chain: dns_txt, url, meta_tag (#5414)
* Implement SSO Domain validation chain

* Use iolists 🆒

* Use aliases

* Update moduledoc

* Update test/plausible/auth/sso/domain/validation_test.exs

Co-authored-by: Adrian Gruntkowski <adrian.gruntkowski@gmail.com>

* Update test/plausible/auth/sso/domain/validation_test.exs

Co-authored-by: Adrian Gruntkowski <adrian.gruntkowski@gmail.com>

* Update test/plausible/auth/sso/domain/validation_test.exs

Co-authored-by: Adrian Gruntkowski <adrian.gruntkowski@gmail.com>

* Match non-empty list for meta tag check

---------

Co-authored-by: Adrian Gruntkowski <adrian.gruntkowski@gmail.com>
2025-06-03 15:07:57 +00:00
RobertJoonas 38f1de6ecd
Starter Tier: Teams UI follow-ups (#5456)
* keep teams feature explicitly for UI

* keep devsubscriptions in sync with prod

On prod, when a subscription is created without a current team in assings,
a new team is force created for that user.

* disable team creation when no point to create it

* fix ce_test compile warning

* fix tests on CE

* Update lib/plausible/teams/billing.ex

Co-authored-by: hq1 <hq@mtod.org>

* add solo team in seeds

* fix top border blur + stop autofocusing input when blurred

---------

Co-authored-by: hq1 <hq@mtod.org>
2025-06-03 10:14:50 +00:00
Adrian Gruntkowski 4a587e2a6e
Implement remaining `SSO` functions needed for setup (#5444)
* Move data mgmt logic from `UserAuth` to `Auth.UserSessions`

* Implement remaining SSO code API needed for setup

* Change `deprovision_user` -> `deprovision_user!`

* Change `UserSessions.create` -> `UserSessions.create!`

* Change `any_verified_domain?` -> `no_verified_domains?` (h/t @aerosol)
2025-06-03 06:21:51 +00:00
RobertJoonas e38bda6d00
Starter feature gates (UI) (#5426)
* replace yellow warning notice with more inviting cta (funnels)

* align VAT notice with /year on the upgrade page

* improve tooltip component

do not hide the tooltip when the mouse enters the tooltip itself directly
from the trigger element. This allows clicking links in tooltips.

* improve site segments feature gate UI

Disable the save button when site segment option is selected in create or
edit form. Also render a different upgrade notice if the user is not the owner.

* replace upgrade notices with blur UI

To fully get rid of Notice.premium_feature, we will also display a
"not allowed" cursor with tooltips asking to upgrade where necessary.

* extract toggle switch component

* Hide currency toggle from goal edit form

The currency field cannot be changed for an existing goal anyway. Therefore
it makes sense not to show it at all. This commit makes the currency picker
always visible when editing a revenue goal, and always hidden for custom
event edit form.

* simplify api key creation form

Turn "Sites API access" into a toggle switch identical to "Enable revenue
tracking" in goal creation form.

* remove team setup CTAs for Starter tier

* fix team member limit for starter

* adjust v5 plan limits and limit exceeded notices

* do not display global notices on upgrade-success page

* fix settings/subscription monthly quota boxes alignment

* fix CI

* use tailwind backdrop-blur

* remove dangling log + avoid passing setSaveDisabled

* remove duplicate function clauses revenue goals

* revert create api key UI change but disable button still

* optimize for darkmode

* blur team settings > team members for Starter

* rename team accounts to team management
2025-05-30 13:34:19 +00:00
RobertJoonas 2dd144bf85
Starter tier: Upgrade page remodelling (#5394)
* add a new (feature flagged) upgrade page offering v5 plans

* include starter tier plans in available_plans_for + use dev prices in test

* upgrade page remodelling with starter tier

* mobile optimizations

* optimize for darkmode

* add embedded dashboards as a growth benefit

* do not hide header on LegacyChoosePlan

* consistent v5 plan feature order

* slight grandfathering notice adjustment

* display monthly price too on yearly plans

* default to v5 plans unlesss legacy? is true

* refactor: suggest volume not plan for emails

* align back link with page title

* render grandfathering notice for growth v4 too
2025-05-20 13:22:12 +00:00
RobertJoonas 1de37a125c
Staging subscriptions (#5349)
* sandbox_plans.json -> sandbox_plans_v4.json

* add mix task and generate sandbox plans

* manually add sandbox_legacy_plans.json

* make all staging plans consistent with prod

* slight code style improvement

* add kb link
2025-05-05 09:23:19 +00:00
Karl-Aksel Puulmann 70ed352bcc
Remove accidental console.log (#5371)
https://github.com/plausible/analytics/pull/5328 accidentally added a
console.log to a test template. This minor change removes that.
2025-04-30 10:43:57 +00:00
hq1 b9ee37ef8c
Adjust notices & permissions (#5348)
* Change how generic notices refer the account

It's now "This team", unless no team is selected.

* Only owner and billing roles can access/manage subscriptions

* Change how Team Settings options are exposed:

- Subscription only available to owner/billing roles
- Invoices only available to owner/billing roles
- API Keys only available to owner/billing/admin/editor roles

* s/team members/members - to avoid repetition

* Only owner/billing can manage dev subscriptions

* Adjust existing tests

* Add test
2025-04-22 06:05:58 +00:00
Karl-Aksel Puulmann 2114c6232d
Allow marking custom events as non-interactive (#5295)
* Tracker: Allow sending non-interactive custom events

These will not affect is_bounce

* Allow marking events as `non-interactive` in events API, change bounce definition

Ref: https://3.basecamp.com/5308029/buckets/26383192/card_tables/cards/8450017341
Feedback: https://feedback.plausible.io/220

* CHANGELOG.md

* credo

* Update tracker script version

* Explicitly ignore event.interactive in schema

* Replace an old test util
2025-04-21 08:11:58 +00:00
RobertJoonas cb465511bb
Streamline creating/updating/deleting subscriptions in development (#5328)
* streamline dev subscriptions

* spawn -> Task

* fix button alignment

* do not define routes in test env

* remove explicit mentions of dev env when deciding whether to sandbox paddle

* decide checkout behaviour at compile time

* Timex -> Date

* hum

* make it work for enterprise plans too

* allow convenient subscription status change

* fix ci warnings

* remove redundant commented out code

* fix crash + review suggestion

---------

Co-authored-by: Adam Rutkowski <hq@mtod.org>
2025-04-16 13:43:17 +00:00
ruslandoga 9bfb1992d9
Sessions transfer (#5229)
* sessions transfer

* took on ignore

* add slow test

* more tests

* allow BIG messages

* update tests

* continue

* continue

* cleanup

* fewer changes

* add config tests

* todo

* use less app env

* oops

* fixes

* cleanup

* update tests

* remove useless tests

* more buckets

* Update lib/plausible/session/transfer.ex

* Update transfer.ex

* Update lib/plausible/session/transfer.ex

* avoid calling into ConCache directly

* cleanup, add docs

* Update lib/plausible/session/transfer.ex

* fewer options

* there is no loop

* force deploy

* force deploy again

* individual puts

* fewer changes in cache/adapter.ex

* oops

* use existing atom names

* Cosmetic changes

* Bring back slow tag

---------

Co-authored-by: hq1 <hq@mtod.org>
2025-04-16 09:56:39 +00:00
Adrian Gruntkowski ec4c6c453a
Switch from `Site.locked` to `Team.locked` (#5304)
* Switch to `Team.locked` for checking lock state

* Rename `update_for_sites` => `update_for`
2025-04-15 06:59:34 +00:00
Adrian Gruntkowski 94e9a20038
Populate `team_id` when provisioning API key (#5234)
* Set team when creating API key

* Create API key with team ID and adjust API key CRM

* Make CRM work with team-less API keys still

* Scope owner's API keys by team on setup

* Rate limit team scoped API keys by their team

* Enforce team scoping for API key with a team

* Prevent using legacy API keys against setup teams

* Enforce team scoping in Sites API too

* Scope API keys list in settings by team

* Do not prevent legacy API keys from accessing setup teams

* List legacy API keys across all teams

* Display "API Keys" under "Team Settings" when team is setup

* Scope teams index in Sites API as well

* Test Sites API actions

* Revert "Scope owner's API keys by team on setup"

This reverts commit 08fd5b4e801417a28ebb9937457cf3e59f7386a0.

* Test and slightly simplify API key CRM logic

* Test API key provisioning from Account Settings

* Test `AuthorizePublicApi` plug adjustments

* Simplify conditionals (h/t @aerosol)

* Change back to using `schema` in CRM logic

* Don't run tests triggering Kaffy warning locally

* Run quirky Kaffy tests only on CI in EE env
2025-03-31 11:35:09 +00:00
RobertJoonas 08d865b214
Google Search Terms error message: too recent period (#5212)
* consider too recent period erroneous + missing tests

* to typescript + center loading spinner
2025-03-20 07:38:33 +00:00
Adrian Gruntkowski f15305254b
Implement team deletion and refactor user deletion (#5196)
* Implement team deletion and refactor user deletion

* Secure team deletion endpoints with team access plug

* Add dedicated tests for `Teams.delete/1`

* Test new controller actions and views

* Rephrase "Setup a team" => "Create a team"

* Improve team-related copy

* Fix personal team removal on user delete with multiple teams

* Wrap `delete_user!` contents in a transaction

* Add notice in user deletion view in case of multiple teams ownership

* Add a basic test and fix copy
2025-03-18 08:34:07 +00:00
RobertJoonas c8ba6d918c
Scroll depth flag cleanup (#5195)
* Backend: get rid of scroll_depth.ex

This commit starts treating the scroll depth feature as *always visible*,
removing the ClickHouse queries on dashboard loads and starting to always
include scroll_depth in dashboard reports and export queries.

* Frontend: remove site.scrollDepthVisible

* adjust csv_importer_test

* remove site.scroll_depth_visible_at
2025-03-13 13:39:38 +00:00
Karl-Aksel Puulmann e9b30e0ba5
time-on-page: query (#5159)
* Default to time_on_page

* Add new columns to schema

* Read from new column in legacy query

* Read/write new imported_pages columns

* Remove time_on_page column from imported_pages

* Simple, stupid new_time_on_page metric

* Update csv_importer schema

* Refactor: consistent __internal helpers, this will help with joining the query

* Refactor select_joined_metrics

* Refactor: pass `query` to event_metric

* Refactor: remove needless site argument from various calls

* Legacy joining query attempt

* Move test around

* Add more tests for both legacy and new time_on_page metrics in query API

* time_on_page reported in seconds

* timeseries test for metric

* WIP

* Wrap main query in subquery - without this run into trouble performing the join

* Calculate time_on_page in main query, no more new_time_on_page

* Add some TODOs

* Return NULL over 0 when no visits with time-on-page data

* Update moduledoc

* Update some tests that were not expecting integers

* Add a TODO

* Update tests

* Make graphing time series with combined metrics work.

* Slightly more consistent approach to flag updating in APIv2

* Seeds with engagement data

* Make graphing time series when cutoff is in the middle work

Bakes less assumptions into everything as well.

* Rename to legacy_time_on_page_cutoff

* Fixup lib/plausible_web/controllers/api/external_query_api_controller.ex

* Remove a todo and dead/misleading code

* Remove a resolved todo

* Remove needless rounding

* gen types

* Update pages test

* Remove needless columns from select

* Update tests: timestamps and remove comment

* Flip branches
2025-03-11 11:19:58 +00:00
Adrian Gruntkowski 486a272498
Refine team switching and switch from `my_team` to `current_team` (#5144)
* Rename "My Team" to "My Personal Sites"

* Rename "Create" to "Setup" in context of teams

* Set default Team Name to "Username's Team"

* wip

* end

* Expose team identifier

* fixup

* team id

* wip

* Rename `Teams.name()` -> `Teams.default_name()` for clarity

* Update test name

* Always reset team name when navigating to Team CTA

* Always use default team name for non-setup team

* Add tests for team name function

* Put sites list heading change behind FF

* Don't rely on FF for implicit team existence check

* Remove unnecessary team pick by parameter in site creation action

* Put first 3 teams in auth assigns context

* Fix setting current team from session

* Make `dropdown_item` component accept method for link

* Implement embedded team switcher in nav bar

* Store only personal team under my_team

* WIP

* Minor team switcher visual tweak

* Fix personal team selection

* Show only guest sites when no team picked

* Show CTA only in reference to `@my_team`

* Fix dedicated team switcher view

* Move picker indicator to the right in dedicated team select

* Alter site listing logic and fix tests

* Add viewer invitation to seeds

* Fix embedded team switch display condition

* Switch current team after setup

* Explicitly clean current team session value when no longer valid

* Remove redundant team switching logic

* Add quick link to team settings

* Don't show quick link when there's no current team

* Fix dedicated team switcher for no current team case

* Add test for my team fallback case

* Don't allow opening team settings for personal team

* Fix formatting

* Add site listing tests

* Fix team switching to avoid clash with existing conn params

* Fix formatting

* Remove unneeded `method` from `dropdown_item` component

* Decalre attributes for `team_switcher` component

* Render Invoices/Subscription sections based on team state

* Fix formatting

---------

Co-authored-by: Adam Rutkowski <hq@mtod.org>
2025-03-11 08:31:12 +00:00
hq1 aa91289153
Team provisioning tweaks (#5155)
* Remove "team layout updated" flash message

* Remove flash when switching team

* Prevent illegal UI states when at team members limit already

* Test UI states at team members limit

* Remove unnecessary socket assign
2025-03-06 12:52:44 +00:00
hq1 ccdf50b734
Balance sessions across worker queues instead of explicit locks (#5113) 2025-02-26 08:03:52 +00:00
Adrian Gruntkowski bf010a1537
Implement support for multiple team owners and multiple teams per user (#5008)
* Add tests for `Teams.get_or_create/1` and `Teams.get_by_owner/1`

* Start populating `current_team` in assigns fetching value from session

* Clean up team passing in invitation services

* Make site transfer service handle multi-team scenario

* Handle multi-team and permission transfer errors on controller level

* Handle multi-teams in site creation on service and controller level

* Drop validation limiting full membership to a single team

* Make user deletion account for public team ownership

* Adjust feature availability checks for Stats API key

* Use current_team when determining limits on site transfer invitation

* Adjust trial upgrade email submission to account for multiple owners

* Remove unnecessary `Teams.load_for_site/1`

* Spike renaming `owner` and `ownership` relationships to plural versions

* Make HelpScout integration handle owner of multiple teams gracefully

* Add FIXME note

* Resolve paddle callback issue by always provisioning a new team when none passed

* Set `current_team` as `my_team` only when user is an owner

* Implement basics of Teams CRM

* Extend Teams CRM

* Further adjust User and Site CRM and refine Team CRM

* Convert Enterprise Plan CRM to refer to team directly and not via user

* Remove unused virtual fields from User schema

* Add note to HelpScout integration

* Allow listing multiple owners under Site Settings / People

* Remove unused User schema relations

* Fix current team fetch in auth plug and context

* Implement basic team switcher

* Ensure (site) editor role is properly handled in site actions auth

* Don't set `site_limit_exceeded` error marker on `permission_denied` error

* Link from HS integration to Team CRM instead of User CRM when available

* Ensure consistent ordering of preloaded owners

* Add `with_subscription` preload for optimisitation

* Add ability to search sites by team identifier

* Add ability to pick team when transferring ownership directly

* Fix failing HelpScout tests

* Scope by team when listing sites in dashboard and via API (optional)

* Add ability to search by team identifier in plans CRM lookup widget

* Add subscription plan, status and grace period to team status info

* Expose teams list in user CRM edit form and fix team details CRM view

* Fix Team Switcher styling

* Reorganise header nav menu

* Avoid additional queries when authenticating user

* Hide the pay/site transfer message on lock screen when teams FF is on

---------

Co-authored-by: Adam Rutkowski <hq@mtod.org>
2025-02-19 09:33:25 +00:00
RobertJoonas 51a6ca6654
Refactor comparison query & including imported data (#5068)
* write comparison_utc_time_range into query

* write site_imports into query

* use struct! over Query.set

* variable to module attr

* remove redundant comment

* reject over filter

* Map.reject over Enum.reject
2025-02-17 10:44:48 +00:00
hq1 2cc3615486
Team Management UI (#4997)
* Start PromEx first; don't run the Oban plugin in test

* Implement `find_team_invitations`

* Implement `all_members`

* Allow disabling e-mail notifications on team member removal

Will be needed later, when operations are applied
in bulk and notifications go out only when transaction
succeeded.

* Fix visuals per @ukutath's suggestions

* Add `:setup_team` test context function

* Don't show team settings in the sidebar, if setup incomplete

* Add high-level interface for team layout arrangement

Will be used in setup but also later on, in membership settings.

* Update team/setup to use `Team.Management.Layout`

* Implement team general settings allowing layout arrangement

* Format

* Remove unused setup_team

* Add id attributes to member dropdown elements

* Format

* Unify team management experience

By sharing the same form layout in both views,
and enabling promoting guests to team members
in a separate section.

* Rename Invitations/Memberships getters

* Tweak team setup layout

* Update team setup markers only once

* Update tests

* Add another future regression test

* Fix typo

* Prune guest memberships on guest->team member promotion

* Remove now unnecessary `Candidates` module

* Add missing tests

* Catch up on multiple owners fixes

* Add missing describe-block setup

* Hopefully make Layout easier to follow

* Remove default prevention from dropdown

* Remove unused assign

* Make `sorted_for_display` skip scheduled for deletion

* `use PlausibleWeb.Component`

* Use `data-test-kind` for test specific selectors

* Remove `class="relative"` from `.dropdown` instances
2025-02-10 06:48:36 +00:00
Karl-Aksel Puulmann 3f6c64cf03
Update queries to work off of `engagement` events over pageleaves (#5053)
Note that export pageleave_visitors column has not been updated here.
2025-02-06 11:27:38 +00:00
Adrian Gruntkowski 62c6cb5f4c
Implement `assert_matches` with expanded expressions support in match assertions (#5024)
* An experiment in more advanced predicates in pattern matches

* More friendly pin expressions in comparison report

* Use the new assert in a real test

* Remove synthetic failing test

* Add moduledoc

* Rename `exact` to `exactly`

* Make standard match bindings not throw unused warnings

* Add basic support for ^strict_map() operator

* Improve strict map checking to support nesting and better error report

* Add checks for more common data types, including serialized time formats

* Refactor the macro for a bit better legibility

* Reduce code nesting further

* Fix documentation definition
2025-01-31 11:18:54 +00:00
Karl-Aksel Puulmann 7c6ba04a3c
Handle missing scroll depth #2 (#5017)
* add migration

* move scroll_depth_enabled? fn

* maybe set engagement_metrics_enabled_at when requesting dashboard

* maybe set engagement_metrics_enabled_at in shared_link action

* maybe set engagement_metrics_enabled_at on full export

* fix tests

* feature gate scroll depth on the dashboard with site.engagement_metrics_enabled_at

* feature gate scroll depth in full export too

* fix npm ci

* Rename things into FE, remove unneccessary flag checks

* Continue with renaming

* Rename site flag to be more descriptive

* Move business logic, calculate based on scroll depth, make more precalculatable

* Some docs

* Rename to site.scrollDepthVisible in frontend

* Update migration

* Fix template

* Remove boilerplate from tests

* Update tests

* More straight-forward test

* Update condition

---------

Co-authored-by: Robert Joonas <robertjoonas16@gmail.com>
2025-01-29 09:47:49 +00:00
Adrian Gruntkowski a45bc1c963
Implement team member and invitation management actions (#4977)
* Implement scaffolding for team member and invite mgmt actions

* Implement updating team role

* Prevent changing role if the subject is the only remaining owner

* Implement removing team membership

* Fix only remaining owner removal checks

* Fix remove team membership service

* Fix and clean up imports

* Implement team invitation removal

* Fix errors surfaced by dialyzer

* Test and fix removing team invitations

* Make accept invitation action work for team invitations

* Test rejecting team invitation

* Test team membership role update and removal actions

* Fix flash message interpolation and missing team in transfer result

* Implement migration adding UUID identifier to team

* Set UUID identifier on team creation

* Implement get team by identifier

* Display team invitations on /sites

* Test rendering team invitations on /sites

* Add team management notices on /settings/people

* Test showing team management notices on /settings/people

* Stop drawing double horizontal rule

* Add modueldoc

* Handle guest member trying to call team membership endpoints gracefully

---------

Co-authored-by: Adam Rutkowski <hq@mtod.org>
2025-01-20 14:24:21 +00:00
Artur Pata 5af43a93d5
Refactor Segments controller to be thinner (#4981)
* Refactor segments model

* Fix inconsistent code

* Remove superfluous error case

* Beautify Plausible.Segments module
2025-01-20 09:58:31 +00:00
hq1 558352c8ac
Implement Team setup CTA+view (#4960)
* spike

* wip omg

* Add option to clear combobox dropdown on selection

* Extend combobox on selection made callback

* Remove IO.inspect

* Add more guests via seeds

* Implement basic UX for arbitrary e-mail addresses

* Save team name on change

* Don't crash on invalid team name input

* Enable :teams flag via seeds

* Implement changing roles

* Display avatars in combobox when selecting member candidates

* Reduce noise

* Add 'Create team' button to the layout

* Revert "Extend combobox on selection made callback"

This reverts commit 874d566d12.

* Fix seeds

* Make email submittion optional in InviteToTeam service

* Implement finalising team setup (WIP)

* Revert "Display avatars in combobox when selecting member candidates"

This reverts commit ff1a30deb3.

* Use regular redirect to preserve flash

* Check team's setup complete status on mount

* Add `dev` param, allowing redirect skip on setup complete

* Bootstrap test module

* Add sample test touching on combobox in team setup

* WIP: testing team setup LV

* Fixup test

* Remove unused bindings

* Add another minor test

* Test removing a member candidate

* Finish up remaining tests

* Rename main module

* Put  team setup view behind a feature flag

* Update main nav dropdown

* Update ComboBox tests

* Fix CandidatesTest regression

* Bring back OG combo-box.js

* Fix dark mode red

* Minor styling fixes

* Extract setup_team function into context

* Remove Floki calls, use Plausible.HTML proxy instead

* Make credo happy

* Use path helpers instead of hardcoded paths

* Fix formatting

* Revert "Merge branch 'master' into setup-teams-01"

This reverts commit bc436c50f8, reversing
changes made to 2eb128d91e.

* Reapply "Merge branch 'master' into setup-teams-01"

This reverts commit c7ebdd2156.

* Alter clear_on_select behavior

* Revert "Alter clear_on_select behavior"

This reverts commit deb20c41f0.

* Look up guests with distinct:true

* Revert "Look up guests with distinct:true"

This reverts commit 352d2717f4.

* Look up guests with distinct:true

* Try something dumb

* huh?

* Bring back problematic changes

* Make combobox dropdown open state and spinner behave on form update

* Don't explicitly send update on live component attribute update

* Don't explicitly send updates to options in funnel combobox either

* Revert "Temporarily disable combobox spinner (#4971)"

This reverts commit 3abf974a56.

* Fix formatting

* Set 'id' on element with phx-update=ignore

* Rework options and suggestions setup in combobox

* Fix suggestions for async

* Fix formatting

---------

Co-authored-by: Adrian Gruntkowski <adrian.gruntkowski@gmail.com>
2025-01-15 11:31:45 +00:00
Artur Pata f169f0caff
Establish saved segments API (#4899)
* Implement segments endpoint controllers

* Refactor endpoint controllers to be based on capabilities

* Add saved_segments feature flag check

* Fix issue when querying all segments on Growth plans

* Validate segment

* Refactor naming to permissions

* Add some permission based tests

* Give more info to compiler about expected args shape

* Implement centralized permission checking module

* Refactor to conventional rights validation

* Update tests

* Add name and segment_data length and filter depth validation

* Refactor route names and add tests for FF check plug

* Refactor mixed segments query name

* Remove inconsistent strict not equals

* Use a different format for result is Map case

* Remove newline between spec and def

* Fix issue with too deep nesting

* Verify in tests that segment is actually removed/not removed from DB

* Fix typo in fn name
2025-01-14 10:12:36 +00:00
Uku Taht 6c30f62d5d
Upgrade deps, add storybook (#4947)
* Add `<.dropdown_item>`

* Make the ellipsis menu functional again

* Upgrade deps so that storybook can be added

* Add storybook and dropdown story

* Remove lingering warnings/errors

* Add color mode to storybook

* Use new liveview used_input? function

* Alpine improvements

* Add select input to storybook

* Bring back `render_form` for CRM

* Configure eslint so it can see deps

* Remove LiveViewTest patch

* Fix test for phoenix liveview 1.0

* Build assets in prod

* Fix tests

* Attempt to fix lint error

* Add explicit text color to input

* mix format

* Format after merge master

* Add moduledocs

* Only run storybook in production

* Update storybook dependency

* Mix format
2025-01-13 12:31:18 +00:00
Adrian Gruntkowski 71d442a9a2
Extend existing invite accept and reject flows to support team invitations (#4953)
* Implement team invitation lookup and rejection

* Implement skeleton for team invitation accept service

* Implement accepting team invite within the existing flow

* [WIP] Test accepting team invites

* Clean up and fix team member assertions

* Rename predicate check in accept invitation flow

* Extend tests further

* Finish tests and fix guest -> team role upgrade
2025-01-13 08:21:25 +00:00