Files
mattermost/server/.gitignore
T
41c482b497 Enable single team and channel migrations between instances (#37868)
* Add TeamName to bulk_export.go and add CLI flag for --team for single team migration

* Add team name to job data map and modify exportAllTeams to have a case for exporting a single team. May need to be put into its own method.

* Add single-team filtering to bulk export pipeline

* Start unit tests; Include ex-team-members and bots in single-team export to ensure all post authors are resolvable on import

* Add channel name to export options and create a --channel flag for channel migration

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

* Changes for enabling single-channel migration

* Add import-side fixes for team/channel migration

- Preserve existing destination team display name on re-import (importTeam
  only sets DisplayName for new teams, guarded by team.Id == "")
- Use --destination-team slug verbatim as display name for new teams, rather
  than inheriting the source team's display name or auto-humanizing the slug
- Create deactivated shell accounts for missing post authors in channel-scoped
  imports instead of silently dropping their posts
- Infer sourceTeamName from first team line when ExportScopeAdditional is
  absent (full-team exports from older server binaries); fixes --destination-team
  being silently ignored in that case
- Update --destination-team flag description: works for full-team exports too,
  not channel-scoped only
- Add migration_test.go with 36 tests covering all import-side scenarios

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

* Additional unit tests

* Add checks for nonexistent teams and channels and add/change unit tests

* Fix team display name not updating on re-import

DisplayName was guarded by `team.Id == ""`, so updating an existing team's
display name via bulk import was silently ignored.

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

* Ignore local migration artifacts (exports, PDFs, demo notes)

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

* Remove duplicate comment

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Handle different types of errors separately to increase clarity

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Update TestExistingUsersOnlyMode to reflect deactivated user creation

importUser now creates missing users as deactivated placeholders when
existingUsersOnly is true (to preserve post authorship), so the test
should assert the user was created but deactivated, not that creation
failed. Addresses Copilot suggestion on PR #37868.

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

* Update description for BulkImportOpts

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Add validation for BulkExport to require TeamName when ChannelName is set

* Return 404 for missing team and distinct error for deleted team in exportAllTeams

Previously both cases returned the same generic 500 error id. Now
store.ErrNotFound maps to a 404 with a new id, and the deleted-team
branch gets its own distinct id. Translations added for both.
Addresses CodeRabbit suggestion on PR #37868.

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

* Add includeArchivedChannels parameter to GetPostAuthorIDs methods for improved filtering

* Stop imports from renaming existing teams on dest server to slug

* Optimize SQL query when filtering for posts from a specific team or channel

* Log warning for failed export scope metadata decoding in bulk import.

* Handle user not found error during import and log appropriate message

* Enable existingUsersOnly flag for team migrations

* Add SSO auth data matching

* Add SSO auth_data matching and username remap for scoped imports.

* Optimize user retrieval by batching remapped usernames for improved performance

* Rename existingUsersOnly flag to deactivateMissingUsers for clarity in user import handling

* Implement pre-creation of SSO users during import to ensure auth_data matching

* Add SSO provider configuration checks and skip option for bulk import

- Implement checkSSOProviderConfig to validate SSO settings before import.
- Introduce SkipPreflight option in BulkImportOpts to bypass SSO checks.
- Update import commands to include skip-preflight flag for user imports.
- Enhance tests for SSO provider configuration validation.

* Implement checkpointing for bulk imports to allow resuming from previous failures

* Add team/channel ID flags and clarify name vs ID in migration commands

* Fix nil post panic and FlaggedBy crash in scoped imports

* Fix checkpoint threshold, error drain, and SSO auth overwrite in import pipeline

* Fix checkpoint bug

* Add tests suggested by copilot

* Support multiple teams and channels in bulk export via comma-separated names/ids

* Add unit tests for bulk exports

* Add "Imported - Inactive" tag to identify deactivated shell accounts

Surfaces a tag in profile popovers, @mention suggestions, and inline
user profiles for users created as deactivated shells during a scoped
import. The tag is cleared automatically on first login.

* Enhance user import functionality to handle existing users and deactivate missing users

* Refactor tests to ensure preCreateSSOUser handles user creation correctly without deactivating missing users; improve formatting in import process command tests and profile popover title component.

* Add warnings for missing users during direct post import in scoped import

* Enhance import functionality to handle channel scope errors, improve user import validation, and update test cases for robustness

* Add tests for ImportedInactiveTag rendering in user profiles and mentions; implement logic to handle imported inactive users

* Add regression test for re-importing archived channels to ensure proper unarchiving

* Fix channel name remapping in migration tests to resolve imported team by name

* Regenerate mmctl docs and add missing i18n/gitignore entries

- Regenerate mmctl_export_create.rst and mmctl_import_process.rst to
  include the new --team-name/--team-id, --channel-name/--channel-id,
  --destination-team-name/id, --destination-channel-name/id, and
  --skip-preflight flags
- Add tag.default.imported_inactive i18n string to en.json
- Ignore server/data_dest/ in .gitignore

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

* Refactor user import logic to improve remap handling and enhance test coverage for SSO user matching

* Add error translations for channel and user import processes; improve existing error messages

* Add tests for splitTrimNames function and enhance error handling in import tests. Fix label for inactive users to be all caps.

* Enhance bulk import functionality to return line number and preserve team display names during import. Update error translations for improved clarity.

* Update ImportedInactiveTag text to uppercase and adjust user type casting in tests

* Update team display name during team name rewrite and restore user limits for production

* Refactor bulk import functions to include destination team parameter and preserve display names during import. Update related tests for consistency.

* Update ImportedInactiveTag text to uppercase in tests for consistency

* Add tests for importing user data and post author IDs for teams and channels

* Update user profile snapshots to include tests for ImportedInactiveTag rendering

* Update snapshot tests to include importedInactiveTag in aria-describedby attributes

* Refactor bulk import checkpoints for improved error handling and resumption

* Improve error handling in bulk import and add tests for scanner I/O errors

* Fix email/username conflicts silently ignored in non-scoped imports

* Update GetUser calls to include context in export and migration tests

* Add missing type attribute to UserProfile button snapshots

* Fix custom emoji never being exported in bulk export archives

* Add unit tests for export_process/import_process job workers

These packages had zero test coverage of any kind. Cover the checkpoint
persistence, checkpoint-file-mismatch fallback, 100MB threshold gate,
job.Data -> BulkExportOpts/BulkImportOpts mapping, and error paths flagged
by the PR test-coverage bot.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* Skip missing thread followers during scoped import instead of failing

* Guard extractThreadMembers against nil ThreadFollowers

* Batch-prefetch thread follower usernames during import

* Skip missing users during scoped imports instead of aborting (thread followers and DM/GM channel members)

* Update server/cmd/mmctl/commands/export.go

Co-authored-by: Scott Bishel <scott.bishel@mattermost.com>

* Preserve destination-side deletions and group message membership changes across re-imports, and fix the resulting unguarded-userMap panics

* Add tests for rewriteTeamName function to handle nil user teams and unrelated line types

* Link scoped-import shell conflicts to the existing account by email/username instead of dropping their posts

* Fix i18n

* Skip posts referencing a channel missing on the destination instead of aborting the import

* Skip a role update that would demote the destination's last system admin instead of aborting the import

* Preserve a source user's pre-existing DeleteAt instead of overwriting it with the import timestamp

* Prevent scoped imports from hijacking an unrelated destination account via username match in preCreateSSOUser

* Preserve a SAML destination user's live email instead of reverting it to a stale source export value

* Populate SchemeName in team-scoped exports so custom permission schemes survive migration

* Look up an archived target channel with GetByNameIncludeDeleted so its members aren't dropped from scoped exports

* Error on --destination-channel-name against a multi-channel export instead of silently no-oping the rename

* Error on --destination-team-name against an unscoped multi-team export instead of silently renaming only the first team

* Resume from a stale in-progress import job's checkpoint instead of only checking failed jobs

* Fix --channel-id team-name inference to only fire when no team was explicitly provided

* Log the same username-collision misattribution warning for the general fallback path as the email path already had

* Harden scoped imports against identity misattribution and stale checkpoints

* Trigger workflow from human actor

* Refactor checkpoint logic to simplify calculation for resumed imports

* Stop scoped imports from silently dropping lines and leaking workers on early return

Also scope custom emoji behind --include-custom-emoji, show the resume warning before the prompt, and keep unscoped exports on their original post-ID query plan.

* Deactivate and tag pre-created SSO shells so scoped imports don't land them active

Also re-link username collisions to the existing destination account instead of
dropping that user's posts, while leaving email collisions unresolved rather than
redirecting content to a differently-named account.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* Regenerate mmctl docs to include --include-custom-emoji flag

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

* Include reaction authors and thread followers in channel-scoped user export; remove email from log

Channel-scoped exports now pre-fetch reaction authors and thread followers
so users whose only connection to a channel is a reaction or thread follow
are included in the export and their state resolves correctly on import.

Also removes mlog.String("email") from the email-collision warning in
importUser — source_username already identifies the record and logging
email writes PII into server logs.

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

* Require --imported-users=active|inactive on scoped imports so migrations into an empty server don't lock everyone out

* Add error translations for export and reaction functionalities

* Add tests to include users who reacted or followed threads in channel exports

* Fix duplicate replies on scoped-import re-import/resume

importReplies looked up an existing reply by its original source CreateAt
while storing it under a value clamped up to the parent post's CreateAt.
When a reply's source CreateAt preceded its parent's, the re-import/resume
lookup missed the stored row and inserted a duplicate. Compute the clamped
effective CreateAt once and use it for both the existence lookup and the
stored value.

Add regression tests: a reply-before-parent re-import idempotency test, and
a crash-and-resume exactly-once test covering the checkpoint/resume path (no
lost or duplicated posts/replies/reactions across resume and repeated resume).

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

* Fix scoped-import password clobber and missing-channel membership abort

Addresses two reproducible defects from the PR QA review:

1. A scoped import reset the password of a pre-existing destination account
   that merely shared a username with an imported user. Exports carry no
   password, so importUser generated a random one and called UpdatePassword on
   the matched existing account, locking the real user out. Only update an
   existing account's password when the import explicitly carried one; new
   accounts still get their generated password via CreateUser.

2. A dest-missing channel aborted the whole scoped import via user-channel
   membership (import_user_channels.channel_not_found), so the advertised
   skip-and-continue behavior did not hold when a destination channel was
   deleted or renamed between runs. Thread deactivateMissingUsers into
   importUserTeams/importUserChannels and skip a missing channel's membership
   with a warning in scoped mode, mirroring the post-skip path.

Add regression tests for both, and fix gofmt/import formatting in the new test
files (check-style).

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

* Modernize rangeint loop in resume test

The enterprise golangci-lint run enables the modernize linter, which flagged
the classic index loop in buildResumeJSONL. Use range-over-int.

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

* Restore access-control i18n keys dropped by the master merge

The master merge into this branch lost four app.pap.* entries from
server/i18n/en.json that the merged (server + enterprise) source still
references, causing the enterprise Check i18n job to fail. Regenerated en.json
via mmgotool i18n extract with the matching enterprise checkout and restored the
original English translations. Re-running extract is now idempotent.

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

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Mattermost Build <build@mattermost.com>
Co-authored-by: Scott Bishel <scott.bishel@mattermost.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2026-09-15 14:00:00 -07:00

134 lines
1.5 KiB
Plaintext

logs
.DS_Store
node_modules
/data
/dist
/webapp/dist
jobserver
npm-debug.log
webapp/yarn-error.log
mattermost.mattermost-license
config/mattermost.mattermost-license
config/config*.json
config/*.crt
config/*.key
web/static/js/bundle*.js
web/static/js/bundle*.js.map
web/static/js/libs*.js
config/active.dat
config/logging.json
/plugins
# go.work file
go.work
go.work.sum
#license files
*.license
*.mattermost-license
# Build Targets
.prebuild
.npminstall
.yarninstall
/prepackaged_plugins
# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a
*.so
# Folders
_obj
_test
testfiles
# Architecture specific extensions/prefixes
[568vq].out
*.cgo1.go
*.cgo2.c
_cgo_defun.c
_cgo_gotypes.go
_cgo_export.*
_testmain.go
*.exe
*.test
*.prof
# Log files
*.log
*.log.jsonl
*.log.gz
# Fuzz binaries and working dir
*fuzz.zip
app/workdir
.tmp
# Vim temporary files
[._]*.s[a-w][a-z]
[._]s[a-w][a-z]
*.un~
Session.vim
.netrwhist
*~
# VSCode project files
.vscode
*.code-workspace
# Gogland project files
mattermost-server.iml
# Build files
*bundle.js
web/sass-files/sass/.sass-cache/
*config.codekit
*.sass-cache
*styles.css
# Default local file storage
data/*
webapp/data/*
api/data/*
api4/data/*
app/data/*
cover.out
ecover.out
mmctlcover.out
cprofile.out
*.test
webapp/coverage
/report.xml
/gotestsum.json
.agignore
.ctags
/tags
.idea
/debug
/client
__debug_bin
report.xml
*coverage.txt
go.*.orig
config.override.mk
docker-compose.override.yaml
# Export artifacts
*_export.zip
*_export-report.json
# mmctl binary
/mmctl