mirror of
https://github.com/hanzoai/team.git
synced 2026-09-30 01:57:35 +00:00
* Add TeamSettings.LockProfileFieldsForEmailUsers with server-side enforcement Co-authored-by: Nick Misasi <[email protected]> * Add API tests for LockProfileFieldsForEmailUsers enforcement Co-authored-by: Nick Misasi <[email protected]> * Hide admin-locked profile fields in user settings and add System Console dropdown Co-authored-by: Nick Misasi <[email protected]> * Support pre-set username and name on team email invites Co-authored-by: Nick Misasi <[email protected]> * Add tests for invite profiles; fix resend worker channel-list parsing Co-authored-by: Nick Misasi <[email protected]> * Add pre-set profile inputs to member invite modal Co-authored-by: Nick Misasi <[email protected]> * Prefill and lock pre-set username on signup page Co-authored-by: Nick Misasi <[email protected]> * Add first/last name editing to System Console user detail and document new setting Co-authored-by: Nick Misasi <[email protected]> * Fix lint issues in invite modal profile inputs Co-authored-by: Nick Misasi <[email protected]> * Fix double outline on invite modal profile inputs inside GenericModal Co-authored-by: Nick Misasi <[email protected]> * Refactor invite emails to InviteEmailData struct and harden invite profile validation Co-authored-by: nick.misasi <[email protected]> * Centralize profile-lock permission exemption in app layer and add config coverage Co-authored-by: nick.misasi <[email protected]> * Per-field name locking in profile settings, typed lock setting, and shared invite profile helpers Co-authored-by: nick.misasi <[email protected]> * Add Playwright E2E coverage for locked profile fields and pre-set invite profiles Co-authored-by: nick.misasi <[email protected]> * Sync playwright package-lock with merged workspace versions Co-authored-by: nick.misasi <[email protected]> * Restore upstream playwright package-lock (fix npm ci drift) Co-authored-by: nick.misasi <[email protected]> * Assert invite input cleared instead of chip text after adding email Co-authored-by: nick.misasi <[email protected]> * Fix invite modal scroll, username error layout, and clipped autocomplete Keep the footer pinned while tall profile rows scroll, show username validation full-width after blur, and portal select menus so they are not clipped by the scroll container. * fixes for autocomplete items not aligning properly * Make invite autocomplete menu portal opt-in and fix modal chrome Confine document.body menu portaling to the invite modal via a menuPortal prop, and restore click-away, slide-in animation, and header alignment for the scrolling invite modal layout. * Fix eslint lines-around-comment on menuPortal props * Fix stylelint property order in invitation modal SCSS. * Fix stylelint property order in invitation_modal.scss Co-authored-by: nick.misasi <[email protected]> * Adapt invite modal E2E to portaled autocomplete menus Co-authored-by: nick.misasi <[email protected]> * Simplify locked profile invite implementation Co-authored-by: nick.misasi <[email protected]> * Fix invite modal review and E2E feedback Co-authored-by: nick.misasi <[email protected]> * Retry flaky enterprise CI Co-authored-by: nick.misasi <[email protected]> * Retry Docker image export CI Co-authored-by: nick.misasi <[email protected]> * Minimize locked profile fields diff Co-authored-by: nick.misasi <[email protected]> * Fix locked profile E2E documentation Co-authored-by: nick.misasi <[email protected]> * Address minimized test review feedback Co-authored-by: nick.misasi <[email protected]> * Fix email test whitespace Co-authored-by: nick.misasi <[email protected]> * Retry OpenSearch download CI Co-authored-by: nick.misasi <[email protected]> * Retry flaky Cypress thread navigation Co-authored-by: nick.misasi <[email protected]> * Preserve legacy invite behavior without profiles Co-authored-by: nick.misasi <[email protected]> * Clarify invite profile validation Co-authored-by: nick.misasi <[email protected]> * Retry flaky enterprise E2E Co-authored-by: nick.misasi <[email protected]> --------- Co-authored-by: Matthew Birtch <[email protected]> Co-authored-by: Hanzo Dev <[email protected]>
115 lines
4.0 KiB
Go
115 lines
4.0 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package model
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"unicode/utf8"
|
|
)
|
|
|
|
type MemberInvite struct {
|
|
Emails []string `json:"emails"`
|
|
ChannelIds []string `json:"channelIds,omitempty"`
|
|
Message string `json:"message"`
|
|
Profiles []*MemberInviteProfile `json:"profiles,omitempty"`
|
|
}
|
|
|
|
// MemberInviteProfile carries admin-chosen profile fields for a single invited email,
|
|
// applied to the account created from that invitation.
|
|
type MemberInviteProfile struct {
|
|
Email string `json:"email"`
|
|
Username string `json:"username"`
|
|
FirstName string `json:"first_name"`
|
|
LastName string `json:"last_name"`
|
|
}
|
|
|
|
func (i *MemberInvite) Auditable() map[string]any {
|
|
return map[string]any{
|
|
"emails": i.Emails,
|
|
"channel_ids": i.ChannelIds,
|
|
"profile_count": len(i.Profiles),
|
|
}
|
|
}
|
|
|
|
// IsValid validates that the invitation info is loaded correctly and with the correct structure
|
|
func (i *MemberInvite) IsValid() *AppError {
|
|
if len(i.Emails) == 0 {
|
|
return NewAppError("MemberInvite.IsValid", "model.member.is_valid.emails.app_error", nil, "", http.StatusBadRequest)
|
|
}
|
|
|
|
if len(i.ChannelIds) > 0 {
|
|
for _, channel := range i.ChannelIds {
|
|
if len(channel) != 26 {
|
|
return NewAppError("MemberInvite.IsValid", "model.member.is_valid.channel.app_error", nil, "channel="+channel, http.StatusBadRequest)
|
|
}
|
|
}
|
|
}
|
|
|
|
// Profiles must reference distinct invited emails and use unique usernames, case-insensitively.
|
|
invitedEmails := make(map[string]struct{}, len(i.Emails))
|
|
for _, email := range i.Emails {
|
|
invitedEmails[NormalizeEmail(email)] = struct{}{}
|
|
}
|
|
|
|
seenProfileEmails := make(map[string]struct{}, len(i.Profiles))
|
|
seenUsernames := make(map[string]struct{}, len(i.Profiles))
|
|
for _, profile := range i.Profiles {
|
|
if profile == nil {
|
|
return NewAppError("MemberInvite.IsValid", "model.member.is_valid.profile_nil.app_error", nil, "", http.StatusBadRequest)
|
|
}
|
|
|
|
email := NormalizeEmail(profile.Email)
|
|
if _, exists := invitedEmails[email]; !exists {
|
|
return NewAppError("MemberInvite.IsValid", "model.member.is_valid.profile_email.app_error", nil, "email="+profile.Email, http.StatusBadRequest)
|
|
}
|
|
if _, exists := seenProfileEmails[email]; exists {
|
|
return NewAppError("MemberInvite.IsValid", "model.member.is_valid.profile_email_duplicate.app_error", nil, "email="+profile.Email, http.StatusBadRequest)
|
|
}
|
|
seenProfileEmails[email] = struct{}{}
|
|
|
|
username := NormalizeUsername(profile.Username)
|
|
if !IsValidUsername(username) {
|
|
return NewAppError("MemberInvite.IsValid", "model.member.is_valid.profile_username.app_error", nil, "username="+profile.Username, http.StatusBadRequest)
|
|
}
|
|
if _, exists := seenUsernames[username]; exists {
|
|
return NewAppError("MemberInvite.IsValid", "model.member.is_valid.profile_username_duplicate.app_error", nil, "username="+profile.Username, http.StatusBadRequest)
|
|
}
|
|
seenUsernames[username] = struct{}{}
|
|
|
|
if appErr := validateMemberInviteProfileNames(profile); appErr != nil {
|
|
return appErr
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func validateMemberInviteProfileNames(profile *MemberInviteProfile) *AppError {
|
|
if utf8.RuneCountInString(profile.FirstName) > UserFirstNameMaxRunes {
|
|
return NewAppError("MemberInvite.IsValid", "model.member.is_valid.profile_first_name.app_error", nil, "email="+profile.Email, http.StatusBadRequest)
|
|
}
|
|
if utf8.RuneCountInString(profile.LastName) > UserLastNameMaxRunes {
|
|
return NewAppError("MemberInvite.IsValid", "model.member.is_valid.profile_last_name.app_error", nil, "email="+profile.Email, http.StatusBadRequest)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (i *MemberInvite) UnmarshalJSON(b []byte) error {
|
|
var emails []string
|
|
if err := json.Unmarshal(b, &emails); err == nil {
|
|
*i = MemberInvite{}
|
|
i.Emails = emails
|
|
return nil
|
|
}
|
|
|
|
type TempMemberInvite MemberInvite
|
|
var o2 TempMemberInvite
|
|
if err := json.Unmarshal(b, &o2); err != nil {
|
|
return err
|
|
}
|
|
*i = MemberInvite(o2)
|
|
return nil
|
|
}
|