Merge branch 'master' of github.com:mattermost/mattermost-server into MM-47853-true-up-review-telemetry-off-non-air-gapped

Этот коммит содержится в:
Conor Macpherson
2022-12-19 15:40:03 -05:00
родитель 96ed60a472 79193240e9
Коммит 12328278f8
100 изменённых файлов: 3145 добавлений и 493 удалений

Просмотреть файл

@@ -1060,6 +1060,24 @@ func (c *Client4) GetUsers(page int, perPage int, etag string) ([]*User, *Respon
return list, BuildResponse(r), nil
}
// GetUsersWithChannelRoles returns a page of users on the system. Page counting starts at 0.
func (c *Client4) GetUsersWithCustomQueryParameters(page int, perPage int, queryParameters, etag string) ([]*User, *Response, error) {
query := fmt.Sprintf("?page=%v&per_page=%v&%v", page, perPage, queryParameters)
r, err := c.DoAPIGet(c.usersRoute()+query, etag)
if err != nil {
return nil, BuildResponse(r), err
}
defer closeBody(r)
var list []*User
if r.StatusCode == http.StatusNotModified {
return list, BuildResponse(r), nil
}
if err := json.NewDecoder(r.Body).Decode(&list); err != nil {
return nil, nil, NewAppError("GetUsers", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
}
return list, BuildResponse(r), nil
}
// GetUsersInTeam returns a page of users on a team. Page counting starts at 0.
func (c *Client4) GetUsersInTeam(teamId string, page int, perPage int, etag string) ([]*User, *Response, error) {
query := fmt.Sprintf("?in_team=%v&page=%v&per_page=%v", teamId, page, perPage)
@@ -1240,6 +1258,24 @@ func (c *Client4) GetUsersInGroup(groupID string, page int, perPage int, etag st
return list, BuildResponse(r), nil
}
// GetUsersInGroup returns a page of users in a group. Page counting starts at 0.
func (c *Client4) GetUsersInGroupByDisplayName(groupID string, page int, perPage int, etag string) ([]*User, *Response, error) {
query := fmt.Sprintf("?sort=display_name&in_group=%v&page=%v&per_page=%v", groupID, page, perPage)
r, err := c.DoAPIGet(c.usersRoute()+query, etag)
if err != nil {
return nil, BuildResponse(r), err
}
defer closeBody(r)
var list []*User
if r.StatusCode == http.StatusNotModified {
return list, BuildResponse(r), nil
}
if err := json.NewDecoder(r.Body).Decode(&list); err != nil {
return nil, nil, NewAppError("GetUsersInGroupByDisplayName", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
}
return list, BuildResponse(r), nil
}
// GetUsersByIds returns a list of users based on the provided user ids.
func (c *Client4) GetUsersByIds(userIds []string) ([]*User, *Response, error) {
r, err := c.DoAPIPost(c.usersRoute()+"/ids", ArrayToJSON(userIds))
@@ -8540,6 +8576,72 @@ func (c *Client4) GetNewTeamMembersSince(teamID string, timeRange string, page i
return newTeamMembersList, BuildResponse(r), nil
}
func (c *Client4) SelfHostedSignupAvailable() (*Response, error) {
r, err := c.DoAPIGet(c.hostedCustomerRoute()+"/signup_available", "")
if err != nil {
return BuildResponse(r), err
}
defer closeBody(r)
return BuildResponse(r), nil
}
func (c *Client4) SelfHostedSignupCustomer(form *SelfHostedCustomerForm) (*Response, *SelfHostedSignupCustomerResponse, error) {
payloadBytes, err := json.Marshal(form)
if err != nil {
return nil, nil, NewAppError("SelfHostedSignupCustomer", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
}
r, err := c.DoAPIPost(c.hostedCustomerRoute()+"/customer", string(payloadBytes))
if err != nil {
return BuildResponse(r), nil, err
}
data, err := io.ReadAll(r.Body)
if err != nil {
return BuildResponse(r), nil, err
}
defer closeBody(r)
response := SelfHostedSignupCustomerResponse{}
err = json.Unmarshal(data, &response)
if err != nil {
return BuildResponse(r), nil, err
}
return BuildResponse(r), &response, nil
}
func (c *Client4) SelfHostedSignupConfirm(form *SelfHostedConfirmPaymentMethodRequest) (*Response, *SelfHostedSignupConfirmClientResponse, error) {
payloadBytes, err := json.Marshal(form)
if err != nil {
return nil, nil, NewAppError("SelfHostedSignupConfirm", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
}
r, err := c.DoAPIPost(c.hostedCustomerRoute()+"/confirm", string(payloadBytes))
if err != nil {
return BuildResponse(r), nil, err
}
data, err := io.ReadAll(r.Body)
if err != nil {
return BuildResponse(r), nil, err
}
defer closeBody(r)
response := SelfHostedSignupConfirmClientResponse{}
err = json.Unmarshal(data, &response)
if err != nil {
return BuildResponse(r), nil, err
}
defer closeBody(r)
return BuildResponse(r), &response, nil
}
func (c *Client4) GetPostInfo(postId string) (*PostInfo, *Response, error) {
r, err := c.DoAPIGet(c.postRoute(postId)+"/info", "")
if err != nil {

Просмотреть файл

@@ -166,7 +166,6 @@ type Subscription struct {
Seats int `json:"seats"`
Status string `json:"status"`
DNS string `json:"dns"`
IsPaidTier string `json:"is_paid_tier"`
LastInvoice *Invoice `json:"last_invoice"`
UpcomingInvoice *Invoice `json:"upcoming_invoice"`
IsFreeTrial string `json:"is_free_trial"`
@@ -291,17 +290,14 @@ type ProductLimits struct {
Teams *TeamsLimits `json:"teams,omitempty"`
}
type BootstrapSelfHostedSignupRequest struct {
Email string `json:"email"`
}
type BootstrapSelfHostedSignupResponse struct {
Progress string `json:"progress"`
}
type BootstrapSelfHostedSignupResponseInternal struct {
Progress string `json:"progress"`
License string `json:"license"`
// CreateSubscriptionRequest is the parameters for the API request to create a subscription.
type CreateSubscriptionRequest struct {
ProductID string `json:"product_id"`
AddOns []string `json:"add_ons"`
Seats int `json:"seats"`
Total float64 `json:"total"`
InternalPurchaseOrder string `json:"internal_purchase_order"`
DiscountID string `json:"discount_id"`
}
func (p *Product) IsYearly() bool {

Просмотреть файл

@@ -383,7 +383,7 @@ type ServiceSettings struct {
CollapsedThreads *string `access:"experimental_features"`
ManagedResourcePaths *string `access:"environment_web_server,write_restrictable,cloud_restrictable"`
EnableCustomGroups *bool `access:"site_users_and_teams"`
SelfHostedFirstTimePurchase *bool `access:"write_restrictable,cloud_restrictable"`
SelfHostedPurchase *bool `access:"write_restrictable,cloud_restrictable"`
AllowSyncedDrafts *bool `access:"site_posts"`
}
@@ -854,8 +854,8 @@ func (s *ServiceSettings) SetDefaults(isUpdate bool) {
s.AllowSyncedDrafts = NewBool(true)
}
if s.SelfHostedFirstTimePurchase == nil {
s.SelfHostedFirstTimePurchase = NewBool(false)
if s.SelfHostedPurchase == nil {
s.SelfHostedPurchase = NewBool(true)
}
}

Просмотреть файл

@@ -104,7 +104,7 @@ func (f *FeatureFlags) SetDefaults() {
f.AnnualSubscription = false
f.ReduceOnBoardingTaskList = false
f.ThreadsEverywhere = false
f.GlobalDrafts = false
f.GlobalDrafts = true
}
func (f *FeatureFlags) Plugins() map[string]string {

Просмотреть файл

@@ -144,9 +144,7 @@ func (syncable *GroupSyncable) MarshalJSON() ([]byte, error) {
Alias: (*Alias)(syncable),
})
default:
return nil, &json.MarshalerError{
Err: fmt.Errorf("unknown syncable type: %s", syncable.Type),
}
return nil, fmt.Errorf("unknown syncable type: %s", syncable.Type)
}
}

20
model/group_syncable_test.go Обычный файл
Просмотреть файл

@@ -0,0 +1,20 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package model
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/require"
)
func TestGroupSyncableMarshal(t *testing.T) {
require.NotPanics(t, func() {
var syncable GroupSyncable
_, err := json.Marshal(&syncable)
require.Error(t, err)
t.Log(err.Error())
}, "marshaling groupsyncable should not panic")
}

58
model/hosted_customer.go Обычный файл
Просмотреть файл

@@ -0,0 +1,58 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package model
type BootstrapSelfHostedSignupRequest struct {
Email string `json:"email"`
Reset bool `json:"reset"`
}
type BootstrapSelfHostedSignupResponse struct {
Progress string `json:"progress"`
}
type BootstrapSelfHostedSignupResponseInternal struct {
Progress string `json:"progress"`
License string `json:"license"`
}
// email contained in token, so not in the request body.
type SelfHostedCustomerForm struct {
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
BillingAddress *Address `json:"billing_address"`
Organization string `json:"organization"`
}
type SelfHostedConfirmPaymentMethodRequest struct {
StripeSetupIntentID string `json:"stripe_setup_intent_id"`
Subscription CreateSubscriptionRequest `json:"subscription"`
}
// SelfHostedSignupPaymentResponse contains feels needed for self hosted signup to confirm payment and receive license.
type SelfHostedSignupCustomerResponse struct {
CustomerId string `json:"customer_id"`
SetupIntentId string `json:"setup_intent_id"`
SetupIntentSecret string `json:"setup_intent_secret"`
Progress string `json:"progress"`
}
// SelfHostedSignupConfirmResponse contains data received on successful self hosted signup
type SelfHostedSignupConfirmResponse struct {
License string `json:"license"`
Progress string `json:"progress"`
}
type SelfHostedSignupConfirmClientResponse struct {
License map[string]string `json:"license"`
Progress string `json:"progress"`
}
type SelfHostedBillingAccessRequest struct {
LicenseId string `json:"license_id"`
}
type SelfHostedBillingAccessResponse struct {
Token string `json:"token"`
}

Просмотреть файл

@@ -248,6 +248,9 @@ func ToDailyPostCountViewModel(dpc []*DurationPostCount, startTime *time.Time, n
return viewModel
}
// Deprecated: This method doesn't perform error checking.
// Use GetStartOfDayForTimeRange instead.
//
// StartOfDayForTimeRange gets the unix start time in milliseconds from the given time range.
// Time range can be one of: "today", "7_day", or "28_day".
func StartOfDayForTimeRange(timeRange string, location *time.Location) *time.Time {

Просмотреть файл

@@ -39,4 +39,5 @@ const (
MigrationKeyAddCustomUserGroupsPermissions = "custom_groups_permissions"
MigrationKeyAddPlayboosksManageRolesPermissions = "playbooks_manage_roles"
MigrationKeyAddProductsBoardsPermissions = "products_boards"
MigrationKeyAddCustomUserGroupsPermissionRestore = "custom_groups_permission_restore"
)

Просмотреть файл

@@ -366,6 +366,7 @@ var PermissionCreateCustomGroup *Permission
var PermissionManageCustomGroupMembers *Permission
var PermissionEditCustomGroup *Permission
var PermissionDeleteCustomGroup *Permission
var PermissionRestoreCustomGroup *Permission
var AllPermissions []*Permission
var DeprecatedPermissions []*Permission
@@ -1960,6 +1961,13 @@ func initializePermissions() {
PermissionScopeGroup,
}
PermissionRestoreCustomGroup = &Permission{
"restore_custom_group",
"authentication.permissions.restore_custom_group.name",
"authentication.permissions.restore_custom_group.description",
PermissionScopeGroup,
}
// Playbooks
PermissionPublicPlaybookCreate = &Permission{
"playbook_public_create",
@@ -2340,6 +2348,7 @@ func initializePermissions() {
PermissionManageCustomGroupMembers,
PermissionEditCustomGroup,
PermissionDeleteCustomGroup,
PermissionRestoreCustomGroup,
}
DeprecatedPermissions = []*Permission{

Просмотреть файл

@@ -119,7 +119,7 @@ type Post struct {
}
func (o *Post) Auditable() map[string]interface{} {
return map[string]interface{}{ // TODO check this
return map[string]interface{}{
"id": o.Id,
"create_at": o.CreateAt,
"update_at": o.UpdateAt,
@@ -195,6 +195,15 @@ func (o *PostPatch) WithRewrittenImageURLs(f func(string) string) *PostPatch {
return &copy
}
func (o *PostPatch) Auditable() map[string]interface{} {
return map[string]interface{}{
"is_pinned": o.IsPinned,
"props": o.Props,
"file_ids": o.FileIds,
"has_reactions": o.HasReactions,
}
}
type PostForExport struct {
Post
TeamName string

Просмотреть файл

@@ -348,6 +348,7 @@ func init() {
PermissionCreateCustomGroup.Id,
PermissionEditCustomGroup.Id,
PermissionDeleteCustomGroup.Id,
PermissionRestoreCustomGroup.Id,
PermissionManageCustomGroupMembers.Id,
}
@@ -953,6 +954,7 @@ func MakeDefaultRoles() map[string]*Role {
PermissionCreateCustomGroup.Id,
PermissionEditCustomGroup.Id,
PermissionDeleteCustomGroup.Id,
PermissionRestoreCustomGroup.Id,
PermissionManageCustomGroupMembers.Id,
},
SchemeManaged: true,

Просмотреть файл

@@ -13,6 +13,7 @@ import (
// It should be maintained in chronological order with most current
// release at the front of the list.
var versions = []string{
"7.7.0",
"7.6.0",
"7.5.0",
"7.4.0",

Просмотреть файл

@@ -81,6 +81,7 @@ const (
WebsocketEventDraftDeleted = "draft_deleted"
WebsocketEventAcknowledgementAdded = "post_acknowledgement_added"
WebsocketEventAcknowledgementRemoved = "post_acknowledgement_removed"
WebsocketEventHostedCustomerSignupProgressUpdated = "hosted_customer_signup_progress_updated"
)
type WebSocketMessage interface {