* Create scheduled post api (#27920) * Added migration files for Postgres * Added migrations for MySQL * Added store method * Added API and store tests * Renamed migration after syncing with master * Added app layer tests * API is ready * API is ready * API is ready * Renamed migration after syncing with master * Updated migration list * Fixed retry layer tests * Allowed posts with empty messages * Review fixes * Reverted an incorrect change * Renamed migration and fixed ID assignment * CI * Send post button changes (#28019) * added Split button * WIP * Added core menu options * WIP * WIP * WIP * Handled displaying error in creating scheduled post * lint fixes * webapp i18n fix * Review fixes * Fixed a webapp test * A few more fixes * Removed a duplicate comment * Scheduled post job (#28088) * Added the job function * Added query for fetching scheduled posts for pricessing * WIP * WIP * WIP * WIP * WIP * WIP * Reafactoring of scheduled post job * Lint fixes * Updated i18n files * FInishing touches * Added tests for GetScheduledPosts * Added tests for PermanentlyDeleteScheduledPosts * Updated all layer * Some changes as discussed with team * Added tests for UpdatedScheduledPost * Code review refactoring * Added job test * MM-60120 - Custom time selection (#28120) * Added a common date time picker modal and used it for post reminder * Added a common date time picker modal and used it for post reminderggp * Added modal for custom schedule time and fixed TZ issue * WIP * Removed event from useSubmit hook * Removed event from useSubmit hook * Added timezone handling * fixed type error * Updated i18n strings * Minor cleanup * updated snapshots * review fixes * Handled event * Supported for having a DM thread open in RHS while in a regular channel * Review fixes * MM-60136 - Scheduled messages tab (#28133) * WIP * WIP * Created Tabs and Tab wrapper with added styling * Added API to get scheduled posts * WIP * Displated scheduled post count * i18n fix * Added tests * Handled asetting active tab absed on URL: * Reverted unintended change * Added API to client ad OpenAPI specs * Renamed file * Adding fileinfo to schedule posts * Partial review fixes * Made get scheduled post API return posts by teamID * review fixes * Moved scheduled post redux code to MM-redux package * Usedd selector factory * WIP: * WIP: * Lint fix * Fixed an incorrect openapi spec file * Removed redundent permission check * Clreaed scheduled post data on logout * Removed unused i18n string: * lint fix * Render scheduled posts (#28208) * WIP * WIP * Created Tabs and Tab wrapper with added styling * Added API to get scheduled posts * WIP * Displated scheduled post count * i18n fix * Added tests * Handled asetting active tab absed on URL: * Reverted unintended change * Added API to client ad OpenAPI specs * Renamed file * Created common component for draft list item * WIP * WIP * Adding fileinfo to schedule posts * Basic rendering * Added count badge to tabs * WIP * Made the Drafts LHS iteam appear if no drafts exist but scheduled posts do * Fixed icon size * Partial review fixes * Made get scheduled post API return posts by teamID * Handled initial vs team switch load * Displayed scheduled date in panel header * Added error message and error indiocator * WIP * review fixes * WIP Adding error reason tag * Added error codes * Moved scheduled post redux code to MM-redux package * Usedd selector factory * WIP: * WIP: * Lint fix * Fixed an incorrect openapi spec file * Removed redundent permission check * Clreaed scheduled post data on logout * Removed unused i18n string: * lint fix * Opened rescheduling modal * Updated graphic for empty state of schduled post list * Added delete scheduled post option and modal * Badge and timezone fix * WIP: * Added send now confirmation modal * lint * Webapp i18n fix * Fixed webapp test * Fixed a bug where DM/GM scheduled posts weren't immideatly showing up in UI * Minor fixes * WIP * Review fixes * Review fixes * Optimisations * Fixed reducer name * Moment optimizatin * Updated route check * MM-60144 - added API to update a scheduled post (#28248) * WIP * Added api and ap layer for update scheduled post ̛̦̄ * Added API to OpenAI specs, Go client and TS client * removed permissio check * Added tests * Fixed tests * Added PreUpdate method on scheduled post model * MM-60131 - Reschedule post integration (#28281) * Handled rescheduling post in webapp * Added error handling * MM-60146 - Delete scheduled post api (#28265) * WIP * Added api and ap layer for update scheduled post ̛̦̄ * Added API to OpenAI specs, Go client and TS client * removed permissio check * Added tests * Fixed tests * Added PreUpdate method on scheduled post model * Added delete scheduled post API * Added API to Go client and OpenAPI specs * Added API to TS client * Added tests * CI * Rmeoved two incorrect code comments * MM-60653 - Integrated delete scheduled post API (#28296) * Integrated delete scheduled apost API * Lint fix * Review fixes * Excluded draft checks from scheduled posts (#28370) * Excluded draft checks from scheduled posts * Added a removed todo * MM-60125 - Scheduled post channel indicator (#28320) * Integrated delete scheduled apost API * Lint fix * Added state for storing scheduled posts by channel ID * Refactored redux store to store scheudled posts by ID, thens tore IDs everywhere * Refactored redux store to store scheudled posts by ID, thens tore IDs everywhere * WIP * Added scheduled post indiocator * Handled single and multiple scheudled posts * Review fixes * Fixed styling and handled center channel, RHS and threads view * Lint fix * i18n fix * Fixed a cycling dependency * Lint fix * Added some more comments * Updated styling * Review fixes * Added common component for remote user time and scheduled post indicator * Updated scheduled post count * Minor change * Moved CSS code around * Fixed a bug where files in scheduled post didn't show up until refresh (#28359) --------- Co-authored-by: Daniel Espino García <larkox@gmail.com> * Scheduled post config (#28485) * Added config * Added config on server and webapp side * Added config check in server and webapp * Added license check * Added license check * Added placeholder help text * Added license check to job * Fixed job test * Review fixes * Updated English text * Review fixes * MM-60118 - Added index on ScheduledPosts table (#28579) * Added index * Updated indexes * Scheduled posts misc fixes (#28625) * Added detailed logging for scheduled post job * Limited scheduled posts processing to 24 hours * Marked old scheduled posts as unable to send * Added t5ests * converted some logs to trace level * Fixed a bug causing error message to show up on deleting a scheduled post in a deleted thread (#28630) * Fixed scheduled posts link in RHS (#28659) * Fixed scheduled posts link in RHS * Review fixes * Fix permission name in scheduled posts by team (#28580) * Fix permission name * fix wording --------- Co-authored-by: Mattermost Build <build@mattermost.com> * FIxed width of generic modal header to fix browser channel modal (#28639) * Only consider error-free scheduled posts for indicator in channel and RHS (#28683) * Show only errro free scheudled posts in post box indicator * Fixed a bug to handle no scheduled posts * Fixed draft and scheudled post UI in mobile view (#28680) * MM-60873 and MM-60872 - Fixed a bug with updating scheduled posts (#28656) * Fixed a bug with updating scheduled posts * Better selectors * MOved shceuled post message length validation to app layer * MM-60732 - Scheduled posts channel link now takes you to the first scheduled post in channel/thread in list (#28768) * Ordered scheudle dposts by schgeudled at nad create at * Ordered in client * Added scroll to target * Removed classname prop * Fixed tests * Added doc * Import fix * MM-60961 - Fixed a bug where API used incoming create at date for scheduled post (#28703) * Fixed a bug where API used incoming create at date for scheduled post * Stopped sending created at value for scheduled post * MM-60785 - Fixed a bug where scheduled posts of channel we are no longer member of didn't show up (#28637) * Fixed a bug where scheduled posts of channel we are no longer member of didn't show up * Added a comment * CI * Used data loader to optimise laoding missing channels * Minor refactoring * MM-60963 - Added common checks for post and scheduled posts (#28713) * Added commen checks for post and scheuled posts * Sanitised scheduled posts * Fixed tests * Splitted post checks into app and context functions * Added checks on scheduiled posts job as well: * i18n fix * Fixed a test * Renamed a func * removed duplicate check * Scheduled posts UI fixes (#28828) * Fixed send button and time picker borders * Fixed center alignment of time picker * Removed on for today and tomorrow * Lint fix * Date time modal hover state fix * Badge fix * Fixed a mnerge issue * Scheduled Post send now and add schedule on draft (#28851) * Added send now option on scheduled posts * Minor refactoring * WIP * WIP * WIP * Lint fix * i18n fix * Snapshot update * Review fixes * Scheduled post inline editing (#28893) * Added send now option on scheduled posts * Minor refactoring * WIP * WIP * WIP * Lint fix * i18n fix * Snapshot update * Displayed editing component in scheduled post * Added handling for updating scheduled post * Handle events * Fixed escape key issue in scheudled post editing * Fixes * Displayed error message for editing error * Don't show mention warning * Handled dev mode (#28918) * MInor fixes * client fix * Fixes * CI * Removed dev mode behaviour temperorily (#29008) --------- Co-authored-by: Daniel Espino García <larkox@gmail.com> Co-authored-by: Eva Sarafianou <eva.sarafianou@gmail.com> Co-authored-by: Mattermost Build <build@mattermost.com>
468 строки
14 KiB
Go
468 строки
14 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package model
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
const (
|
|
DayInSeconds = 24 * 60 * 60
|
|
DayInMilliseconds = DayInSeconds * 1000
|
|
|
|
ExpiredLicenseError = "api.license.add_license.expired.app_error"
|
|
InvalidLicenseError = "api.license.add_license.invalid.app_error"
|
|
LicenseGracePeriod = DayInMilliseconds * 10 //10 days
|
|
LicenseRenewalLink = "https://mattermost.com/renew/"
|
|
|
|
LicenseShortSkuE10 = "E10"
|
|
LicenseShortSkuE20 = "E20"
|
|
LicenseShortSkuProfessional = "professional"
|
|
LicenseShortSkuEnterprise = "enterprise"
|
|
)
|
|
|
|
const (
|
|
LicenseUpForRenewalEmailSent = "LicenseUpForRenewalEmailSent"
|
|
)
|
|
|
|
var (
|
|
trialDuration = 30*(time.Hour*24) + (time.Hour * 8) // 720 hours (30 days) + 8 hours is trial license duration
|
|
adminTrialDuration = 30*(time.Hour*24) + (time.Hour * 23) + (time.Minute * 59) + (time.Second * 59) // 720 hours (30 days) + 23 hours, 59 mins and 59 seconds
|
|
|
|
// a sanctioned trial's duration is either more than the upper bound,
|
|
// or less than the lower bound
|
|
sanctionedTrialDurationLowerBound = 31*(time.Hour*24) + (time.Hour * 23) + (time.Minute * 59) + (time.Second * 59) // 744 hours (31 days) + 23 hours, 59 mins and 59 seconds
|
|
sanctionedTrialDurationUpperBound = 29*(time.Hour*24) + (time.Hour * 23) + (time.Minute * 59) + (time.Second * 59) // 696 hours (29 days) + 23 hours, 59 mins and 59 seconds
|
|
)
|
|
|
|
type LicenseRecord struct {
|
|
Id string `json:"id"`
|
|
CreateAt int64 `json:"create_at"`
|
|
Bytes string `json:"-"`
|
|
}
|
|
|
|
type License struct {
|
|
Id string `json:"id"`
|
|
IssuedAt int64 `json:"issued_at"`
|
|
StartsAt int64 `json:"starts_at"`
|
|
ExpiresAt int64 `json:"expires_at"`
|
|
Customer *Customer `json:"customer"`
|
|
Features *Features `json:"features"`
|
|
SkuName string `json:"sku_name"`
|
|
SkuShortName string `json:"sku_short_name"`
|
|
IsTrial bool `json:"is_trial"`
|
|
IsGovSku bool `json:"is_gov_sku"`
|
|
SignupJWT *string `json:"signup_jwt"`
|
|
}
|
|
|
|
type Customer struct {
|
|
Id string `json:"id"`
|
|
Name string `json:"name"`
|
|
Email string `json:"email"`
|
|
Company string `json:"company"`
|
|
}
|
|
|
|
type TrialLicenseRequest struct {
|
|
ServerID string `json:"server_id"`
|
|
Email string `json:"email"`
|
|
Name string `json:"name"`
|
|
SiteURL string `json:"site_url"`
|
|
SiteName string `json:"site_name"`
|
|
Users int `json:"users"`
|
|
TermsAccepted bool `json:"terms_accepted"`
|
|
ReceiveEmailsAccepted bool `json:"receive_emails_accepted"`
|
|
ContactName string `json:"contact_name"`
|
|
ContactEmail string `json:"contact_email"`
|
|
CompanyName string `json:"company_name"`
|
|
CompanyCountry string `json:"company_country"`
|
|
CompanySize string `json:"company_size"`
|
|
}
|
|
|
|
// If any of the below fields are set, this is not a legacy request, and all fields should be validated
|
|
func (tlr *TrialLicenseRequest) IsLegacy() bool {
|
|
return tlr.CompanyCountry == "" && tlr.CompanyName == "" && tlr.CompanySize == "" && tlr.ContactName == ""
|
|
}
|
|
|
|
func (tlr *TrialLicenseRequest) IsValid() bool {
|
|
if !tlr.TermsAccepted {
|
|
return false
|
|
}
|
|
|
|
if tlr.Email == "" {
|
|
return false
|
|
}
|
|
|
|
if tlr.Users <= 0 {
|
|
return false
|
|
}
|
|
|
|
if tlr.CompanyCountry == "" {
|
|
return false
|
|
}
|
|
|
|
if tlr.CompanyName == "" {
|
|
return false
|
|
}
|
|
|
|
if tlr.CompanySize == "" {
|
|
return false
|
|
}
|
|
|
|
if tlr.ContactName == "" {
|
|
return false
|
|
}
|
|
|
|
return true
|
|
}
|
|
|
|
type Features struct {
|
|
Users *int `json:"users"`
|
|
LDAP *bool `json:"ldap"`
|
|
LDAPGroups *bool `json:"ldap_groups"`
|
|
MFA *bool `json:"mfa"`
|
|
GoogleOAuth *bool `json:"google_oauth"`
|
|
Office365OAuth *bool `json:"office365_oauth"`
|
|
OpenId *bool `json:"openid"`
|
|
Compliance *bool `json:"compliance"`
|
|
Cluster *bool `json:"cluster"`
|
|
Metrics *bool `json:"metrics"`
|
|
MHPNS *bool `json:"mhpns"`
|
|
SAML *bool `json:"saml"`
|
|
Elasticsearch *bool `json:"elastic_search"`
|
|
Announcement *bool `json:"announcement"`
|
|
ThemeManagement *bool `json:"theme_management"`
|
|
EmailNotificationContents *bool `json:"email_notification_contents"`
|
|
DataRetention *bool `json:"data_retention"`
|
|
MessageExport *bool `json:"message_export"`
|
|
CustomPermissionsSchemes *bool `json:"custom_permissions_schemes"`
|
|
CustomTermsOfService *bool `json:"custom_terms_of_service"`
|
|
GuestAccounts *bool `json:"guest_accounts"`
|
|
GuestAccountsPermissions *bool `json:"guest_accounts_permissions"`
|
|
IDLoadedPushNotifications *bool `json:"id_loaded"`
|
|
LockTeammateNameDisplay *bool `json:"lock_teammate_name_display"`
|
|
EnterprisePlugins *bool `json:"enterprise_plugins"`
|
|
AdvancedLogging *bool `json:"advanced_logging"`
|
|
Cloud *bool `json:"cloud"`
|
|
SharedChannels *bool `json:"shared_channels"`
|
|
RemoteClusterService *bool `json:"remote_cluster_service"`
|
|
OutgoingOAuthConnections *bool `json:"outgoing_oauth_connections"`
|
|
|
|
// after we enabled more features we'll need to control them with this
|
|
FutureFeatures *bool `json:"future_features"`
|
|
}
|
|
|
|
func (f *Features) ToMap() map[string]any {
|
|
return map[string]any{
|
|
"ldap": *f.LDAP,
|
|
"ldap_groups": *f.LDAPGroups,
|
|
"mfa": *f.MFA,
|
|
"google": *f.GoogleOAuth,
|
|
"office365": *f.Office365OAuth,
|
|
"openid": *f.OpenId,
|
|
"compliance": *f.Compliance,
|
|
"cluster": *f.Cluster,
|
|
"metrics": *f.Metrics,
|
|
"mhpns": *f.MHPNS,
|
|
"saml": *f.SAML,
|
|
"elastic_search": *f.Elasticsearch,
|
|
"email_notification_contents": *f.EmailNotificationContents,
|
|
"data_retention": *f.DataRetention,
|
|
"message_export": *f.MessageExport,
|
|
"custom_permissions_schemes": *f.CustomPermissionsSchemes,
|
|
"guest_accounts": *f.GuestAccounts,
|
|
"guest_accounts_permissions": *f.GuestAccountsPermissions,
|
|
"id_loaded": *f.IDLoadedPushNotifications,
|
|
"lock_teammate_name_display": *f.LockTeammateNameDisplay,
|
|
"enterprise_plugins": *f.EnterprisePlugins,
|
|
"advanced_logging": *f.AdvancedLogging,
|
|
"cloud": *f.Cloud,
|
|
"shared_channels": *f.SharedChannels,
|
|
"remote_cluster_service": *f.RemoteClusterService,
|
|
"future": *f.FutureFeatures,
|
|
"outgoing_oauth_connections": *f.OutgoingOAuthConnections,
|
|
}
|
|
}
|
|
|
|
func (f *Features) SetDefaults() {
|
|
if f.FutureFeatures == nil {
|
|
f.FutureFeatures = NewPointer(true)
|
|
}
|
|
|
|
if f.Users == nil {
|
|
f.Users = NewPointer(0)
|
|
}
|
|
|
|
if f.LDAP == nil {
|
|
f.LDAP = NewPointer(*f.FutureFeatures)
|
|
}
|
|
|
|
if f.LDAPGroups == nil {
|
|
f.LDAPGroups = NewPointer(*f.FutureFeatures)
|
|
}
|
|
|
|
if f.MFA == nil {
|
|
f.MFA = NewPointer(*f.FutureFeatures)
|
|
}
|
|
|
|
if f.GoogleOAuth == nil {
|
|
f.GoogleOAuth = NewPointer(*f.FutureFeatures)
|
|
}
|
|
|
|
if f.Office365OAuth == nil {
|
|
f.Office365OAuth = NewPointer(*f.FutureFeatures)
|
|
}
|
|
|
|
if f.OpenId == nil {
|
|
f.OpenId = NewPointer(*f.FutureFeatures)
|
|
}
|
|
|
|
if f.Compliance == nil {
|
|
f.Compliance = NewPointer(*f.FutureFeatures)
|
|
}
|
|
|
|
if f.Cluster == nil {
|
|
f.Cluster = NewPointer(*f.FutureFeatures)
|
|
}
|
|
|
|
if f.Metrics == nil {
|
|
f.Metrics = NewPointer(*f.FutureFeatures)
|
|
}
|
|
|
|
if f.MHPNS == nil {
|
|
f.MHPNS = NewPointer(*f.FutureFeatures)
|
|
}
|
|
|
|
if f.SAML == nil {
|
|
f.SAML = NewPointer(*f.FutureFeatures)
|
|
}
|
|
|
|
if f.Elasticsearch == nil {
|
|
f.Elasticsearch = NewPointer(*f.FutureFeatures)
|
|
}
|
|
|
|
if f.Announcement == nil {
|
|
f.Announcement = NewPointer(true)
|
|
}
|
|
|
|
if f.ThemeManagement == nil {
|
|
f.ThemeManagement = NewPointer(true)
|
|
}
|
|
|
|
if f.EmailNotificationContents == nil {
|
|
f.EmailNotificationContents = NewPointer(*f.FutureFeatures)
|
|
}
|
|
|
|
if f.DataRetention == nil {
|
|
f.DataRetention = NewPointer(*f.FutureFeatures)
|
|
}
|
|
|
|
if f.MessageExport == nil {
|
|
f.MessageExport = NewPointer(*f.FutureFeatures)
|
|
}
|
|
|
|
if f.CustomPermissionsSchemes == nil {
|
|
f.CustomPermissionsSchemes = NewPointer(*f.FutureFeatures)
|
|
}
|
|
|
|
if f.GuestAccounts == nil {
|
|
f.GuestAccounts = NewPointer(*f.FutureFeatures)
|
|
}
|
|
|
|
if f.GuestAccountsPermissions == nil {
|
|
f.GuestAccountsPermissions = NewPointer(*f.FutureFeatures)
|
|
}
|
|
|
|
if f.CustomTermsOfService == nil {
|
|
f.CustomTermsOfService = NewPointer(*f.FutureFeatures)
|
|
}
|
|
|
|
if f.IDLoadedPushNotifications == nil {
|
|
f.IDLoadedPushNotifications = NewPointer(*f.FutureFeatures)
|
|
}
|
|
|
|
if f.LockTeammateNameDisplay == nil {
|
|
f.LockTeammateNameDisplay = NewPointer(*f.FutureFeatures)
|
|
}
|
|
|
|
if f.EnterprisePlugins == nil {
|
|
f.EnterprisePlugins = NewPointer(*f.FutureFeatures)
|
|
}
|
|
|
|
if f.AdvancedLogging == nil {
|
|
f.AdvancedLogging = NewPointer(*f.FutureFeatures)
|
|
}
|
|
|
|
if f.Cloud == nil {
|
|
f.Cloud = NewPointer(false)
|
|
}
|
|
|
|
if f.SharedChannels == nil {
|
|
f.SharedChannels = NewPointer(*f.FutureFeatures)
|
|
}
|
|
|
|
if f.RemoteClusterService == nil {
|
|
f.RemoteClusterService = NewPointer(*f.FutureFeatures)
|
|
}
|
|
|
|
if f.OutgoingOAuthConnections == nil {
|
|
f.OutgoingOAuthConnections = NewPointer(*f.FutureFeatures)
|
|
}
|
|
}
|
|
|
|
func (l *License) IsExpired() bool {
|
|
return l.ExpiresAt < GetMillis()
|
|
}
|
|
|
|
func (l *License) IsPastGracePeriod() bool {
|
|
timeDiff := GetMillis() - l.ExpiresAt
|
|
return timeDiff > LicenseGracePeriod
|
|
}
|
|
|
|
func (l *License) IsWithinExpirationPeriod() bool {
|
|
days := l.DaysToExpiration()
|
|
return days <= 60 && days >= 58
|
|
}
|
|
|
|
func (l *License) DaysToExpiration() int {
|
|
dif := l.ExpiresAt - GetMillis()
|
|
d, _ := time.ParseDuration(fmt.Sprint(dif) + "ms")
|
|
days := d.Hours() / 24
|
|
return int(days)
|
|
}
|
|
|
|
func (l *License) IsStarted() bool {
|
|
return l.StartsAt < GetMillis()
|
|
}
|
|
|
|
func (l *License) IsCloud() bool {
|
|
return l != nil && l.Features != nil && l.Features.Cloud != nil && *l.Features.Cloud
|
|
}
|
|
|
|
func (l *License) IsTrialLicense() bool {
|
|
return l.IsTrial || (l.ExpiresAt-l.StartsAt) == trialDuration.Milliseconds() || (l.ExpiresAt-l.StartsAt) == adminTrialDuration.Milliseconds()
|
|
}
|
|
|
|
func (l *License) IsSanctionedTrial() bool {
|
|
duration := l.ExpiresAt - l.StartsAt
|
|
|
|
return l.IsTrialLicense() &&
|
|
(duration >= sanctionedTrialDurationLowerBound.Milliseconds() || duration <= sanctionedTrialDurationUpperBound.Milliseconds())
|
|
}
|
|
|
|
func (l *License) HasEnterpriseMarketplacePlugins() bool {
|
|
return *l.Features.EnterprisePlugins ||
|
|
l.SkuShortName == LicenseShortSkuE20 ||
|
|
l.SkuShortName == LicenseShortSkuProfessional ||
|
|
l.SkuShortName == LicenseShortSkuEnterprise
|
|
}
|
|
|
|
func (l *License) HasRemoteClusterService() bool {
|
|
if l == nil {
|
|
return false
|
|
}
|
|
|
|
// If SharedChannels is enabled then RemoteClusterService must be enabled.
|
|
if l.HasSharedChannels() {
|
|
return true
|
|
}
|
|
|
|
return (l.Features != nil && l.Features.RemoteClusterService != nil && *l.Features.RemoteClusterService) ||
|
|
l.SkuShortName == LicenseShortSkuProfessional ||
|
|
l.SkuShortName == LicenseShortSkuEnterprise
|
|
}
|
|
|
|
func (l *License) HasSharedChannels() bool {
|
|
if l == nil {
|
|
return false
|
|
}
|
|
|
|
return (l.Features != nil && l.Features.SharedChannels != nil && *l.Features.SharedChannels) ||
|
|
l.SkuShortName == LicenseShortSkuProfessional ||
|
|
l.SkuShortName == LicenseShortSkuEnterprise
|
|
}
|
|
|
|
// IsE20OrEnterprise returns true when the license is for E20 or Enterprise.
|
|
func (l *License) IsE20OrEnterprise() bool {
|
|
return l.SkuShortName == LicenseShortSkuE20 || l.SkuShortName == LicenseShortSkuEnterprise
|
|
}
|
|
|
|
// NewTestLicense returns a license that expires in the future and has the given features.
|
|
func NewTestLicense(features ...string) *License {
|
|
ret := &License{
|
|
ExpiresAt: GetMillis() + 90*DayInMilliseconds,
|
|
Customer: &Customer{
|
|
Id: "some ID",
|
|
Email: "admin@example.com",
|
|
Name: "Main Contact Person",
|
|
Company: "My awesome Company",
|
|
},
|
|
Features: &Features{},
|
|
}
|
|
ret.Features.SetDefaults()
|
|
|
|
featureMap := map[string]bool{}
|
|
for _, feature := range features {
|
|
featureMap[feature] = true
|
|
}
|
|
featureJson, _ := json.Marshal(featureMap)
|
|
json.Unmarshal(featureJson, &ret.Features)
|
|
|
|
return ret
|
|
}
|
|
|
|
// NewTestLicense returns a license that expires in the future and set as false the given features.
|
|
func NewTestLicenseWithFalseDefaults(features ...string) *License {
|
|
ret := &License{
|
|
ExpiresAt: GetMillis() + 90*DayInMilliseconds,
|
|
Customer: &Customer{},
|
|
Features: &Features{},
|
|
}
|
|
ret.Features.SetDefaults()
|
|
|
|
featureMap := map[string]bool{}
|
|
for _, feature := range features {
|
|
featureMap[feature] = false
|
|
}
|
|
featureJson, _ := json.Marshal(featureMap)
|
|
json.Unmarshal(featureJson, &ret.Features)
|
|
|
|
return ret
|
|
}
|
|
|
|
func NewTestLicenseSKU(skuShortName string, features ...string) *License {
|
|
lic := NewTestLicense(features...)
|
|
lic.SkuShortName = skuShortName
|
|
return lic
|
|
}
|
|
|
|
func (lr *LicenseRecord) IsValid() *AppError {
|
|
if !IsValidId(lr.Id) {
|
|
return NewAppError("LicenseRecord.IsValid", "model.license_record.is_valid.id.app_error", nil, "", http.StatusBadRequest)
|
|
}
|
|
|
|
if lr.CreateAt == 0 {
|
|
return NewAppError("LicenseRecord.IsValid", "model.license_record.is_valid.create_at.app_error", nil, "", http.StatusBadRequest)
|
|
}
|
|
|
|
if lr.Bytes == "" || len(lr.Bytes) > 10000 {
|
|
return NewAppError("LicenseRecord.IsValid", "model.license_record.is_valid.bytes.app_error", nil, "", http.StatusBadRequest)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (lr *LicenseRecord) PreSave() {
|
|
lr.CreateAt = GetMillis()
|
|
}
|
|
|
|
func MinimumProfessionalProvidedLicense(license *License) *AppError {
|
|
if license == nil || (license.SkuShortName != LicenseShortSkuProfessional && license.SkuShortName != LicenseShortSkuEnterprise) {
|
|
return NewAppError("", NoTranslation, nil, "license is neither professional nor enterprise", http.StatusNotImplemented)
|
|
}
|
|
return nil
|
|
}
|