summaryrefslogtreecommitdiffstats
path: root/model
diff options
context:
space:
mode:
Diffstat (limited to 'model')
-rw-r--r--model/channel_list.go11
-rw-r--r--model/client4.go80
-rw-r--r--model/config.go57
-rw-r--r--model/license.go31
-rw-r--r--model/license_test.go5
5 files changed, 152 insertions, 32 deletions
diff --git a/model/channel_list.go b/model/channel_list.go
index 18c726908..d5a4ccb7c 100644
--- a/model/channel_list.go
+++ b/model/channel_list.go
@@ -50,3 +50,14 @@ func ChannelListFromJson(data io.Reader) *ChannelList {
return nil
}
}
+
+func ChannelSliceFromJson(data io.Reader) []*Channel {
+ decoder := json.NewDecoder(data)
+ var o []*Channel
+ err := decoder.Decode(&o)
+ if err == nil {
+ return o
+ } else {
+ return nil
+ }
+}
diff --git a/model/client4.go b/model/client4.go
index 3a6507f82..4a01a1f75 100644
--- a/model/client4.go
+++ b/model/client4.go
@@ -250,6 +250,10 @@ func (c *Client4) GetOAuthAppRoute(appId string) string {
return fmt.Sprintf("/oauth/apps/%v", appId)
}
+func (c *Client4) GetOpenGraphRoute() string {
+ return fmt.Sprintf("/opengraph")
+}
+
func (c *Client4) DoApiGet(url string, etag string) (*http.Response, *AppError) {
return c.DoApiRequest(http.MethodGet, c.ApiUrl+url, "", etag)
}
@@ -447,6 +451,40 @@ func (c *Client4) CreateUser(user *User) (*User, *Response) {
}
}
+// CreateUserWithHash creates a user in the system based on the provided user struct and hash created.
+func (c *Client4) CreateUserWithHash(user *User, hash, data string) (*User, *Response) {
+ var query string
+ if hash != "" && data != "" {
+ query = fmt.Sprintf("?d=%v&h=%v", url.QueryEscape(data), hash)
+ } else {
+ err := NewAppError("MissingHashOrData", "api.user.create_user.missing_hash_or_data.app_error", nil, "", http.StatusBadRequest)
+ return nil, &Response{StatusCode: err.StatusCode, Error: err}
+ }
+ if r, err := c.DoApiPost(c.GetUsersRoute()+query, user.ToJson()); err != nil {
+ return nil, &Response{StatusCode: r.StatusCode, Error: err}
+ } else {
+ defer closeBody(r)
+ return UserFromJson(r.Body), BuildResponse(r)
+ }
+}
+
+// CreateUserWithInviteId creates a user in the system based on the provided invited id.
+func (c *Client4) CreateUserWithInviteId(user *User, inviteId string) (*User, *Response) {
+ var query string
+ if inviteId != "" {
+ query = fmt.Sprintf("?iid=%v", url.QueryEscape(inviteId))
+ } else {
+ err := NewAppError("MissingInviteId", "api.user.create_user.missing_invite_id.app_error", nil, "", http.StatusBadRequest)
+ return nil, &Response{StatusCode: err.StatusCode, Error: err}
+ }
+ if r, err := c.DoApiPost(c.GetUsersRoute()+query, user.ToJson()); err != nil {
+ return nil, &Response{StatusCode: r.StatusCode, Error: err}
+ } else {
+ defer closeBody(r)
+ return UserFromJson(r.Body), BuildResponse(r)
+ }
+}
+
// GetMe returns the logged in user.
func (c *Client4) GetMe(etag string) (*User, *Response) {
if r, err := c.DoApiGet(c.GetUserRoute(ME), etag); err != nil {
@@ -1232,43 +1270,54 @@ func (c *Client4) GetPinnedPosts(channelId string, etag string) (*PostList, *Res
}
// GetPublicChannelsForTeam returns a list of public channels based on the provided team id string.
-func (c *Client4) GetPublicChannelsForTeam(teamId string, page int, perPage int, etag string) (*ChannelList, *Response) {
+func (c *Client4) GetPublicChannelsForTeam(teamId string, page int, perPage int, etag string) ([]*Channel, *Response) {
query := fmt.Sprintf("?page=%v&per_page=%v", page, perPage)
if r, err := c.DoApiGet(c.GetChannelsForTeamRoute(teamId)+query, etag); err != nil {
return nil, &Response{StatusCode: r.StatusCode, Error: err}
} else {
defer closeBody(r)
- return ChannelListFromJson(r.Body), BuildResponse(r)
+ return ChannelSliceFromJson(r.Body), BuildResponse(r)
+ }
+}
+
+// GetDeletedChannelsForTeam returns a list of public channels based on the provided team id string.
+func (c *Client4) GetDeletedChannelsForTeam(teamId string, page int, perPage int, etag string) ([]*Channel, *Response) {
+ query := fmt.Sprintf("/deleted?page=%v&per_page=%v", page, perPage)
+ if r, err := c.DoApiGet(c.GetChannelsForTeamRoute(teamId)+query, etag); err != nil {
+ return nil, &Response{StatusCode: r.StatusCode, Error: err}
+ } else {
+ defer closeBody(r)
+ return ChannelSliceFromJson(r.Body), BuildResponse(r)
}
}
// GetPublicChannelsByIdsForTeam returns a list of public channels based on provided team id string
-func (c *Client4) GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) (*ChannelList, *Response) {
+func (c *Client4) GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) ([]*Channel, *Response) {
if r, err := c.DoApiPost(c.GetChannelsForTeamRoute(teamId)+"/ids", ArrayToJson(channelIds)); err != nil {
return nil, &Response{StatusCode: r.StatusCode, Error: err}
} else {
defer closeBody(r)
- return ChannelListFromJson(r.Body), BuildResponse(r)
+ return ChannelSliceFromJson(r.Body), BuildResponse(r)
}
}
// GetChannelsForTeamForUser returns a list channels of on a team for a user.
-func (c *Client4) GetChannelsForTeamForUser(teamId, userId, etag string) (*ChannelList, *Response) {
+func (c *Client4) GetChannelsForTeamForUser(teamId, userId, etag string) ([]*Channel, *Response) {
if r, err := c.DoApiGet(c.GetUserRoute(userId)+c.GetTeamRoute(teamId)+"/channels", etag); err != nil {
return nil, &Response{StatusCode: r.StatusCode, Error: err}
} else {
defer closeBody(r)
- return ChannelListFromJson(r.Body), BuildResponse(r)
+ return ChannelSliceFromJson(r.Body), BuildResponse(r)
}
}
// SearchChannels returns the channels on a team matching the provided search term.
-func (c *Client4) SearchChannels(teamId string, search *ChannelSearch) (*ChannelList, *Response) {
+func (c *Client4) SearchChannels(teamId string, search *ChannelSearch) ([]*Channel, *Response) {
if r, err := c.DoApiPost(c.GetChannelsForTeamRoute(teamId)+"/search", search.ToJson()); err != nil {
return nil, &Response{StatusCode: r.StatusCode, Error: err}
} else {
defer closeBody(r)
- return ChannelListFromJson(r.Body), BuildResponse(r)
+ return ChannelSliceFromJson(r.Body), BuildResponse(r)
}
}
@@ -2564,3 +2613,18 @@ func (c *Client4) DeleteReaction(reaction *Reaction) (bool, *Response) {
return CheckStatusOK(r), BuildResponse(r)
}
}
+
+// Open Graph Metadata Section
+
+// OpenGraph return the open graph metadata for a particular url if the site have the metadata
+func (c *Client4) OpenGraph(url string) (map[string]string, *Response) {
+ requestBody := make(map[string]string)
+ requestBody["url"] = url
+
+ if r, err := c.DoApiPost(c.GetOpenGraphRoute(), MapToJson(requestBody)); err != nil {
+ return nil, &Response{StatusCode: r.StatusCode, Error: err}
+ } else {
+ defer closeBody(r)
+ return MapFromJson(r.Body), BuildResponse(r)
+ }
+}
diff --git a/model/config.go b/model/config.go
index aedba7013..907620124 100644
--- a/model/config.go
+++ b/model/config.go
@@ -75,12 +75,15 @@ const (
EMAIL_SETTINGS_DEFAULT_FEEDBACK_ORGANIZATION = ""
- SUPPORT_SETTINGS_DEFAULT_TERMS_OF_SERVICE_LINK = "https://about.mattermost.com/default-terms/"
- SUPPORT_SETTINGS_DEFAULT_PRIVACY_POLICY_LINK = "https://about.mattermost.com/default-privacy-policy/"
- SUPPORT_SETTINGS_DEFAULT_ABOUT_LINK = "https://about.mattermost.com/default-about/"
- SUPPORT_SETTINGS_DEFAULT_HELP_LINK = "https://about.mattermost.com/default-help/"
- SUPPORT_SETTINGS_DEFAULT_REPORT_A_PROBLEM_LINK = "https://about.mattermost.com/default-report-a-problem/"
- SUPPORT_SETTINGS_DEFAULT_SUPPORT_EMAIL = "feedback@mattermost.com"
+ SUPPORT_SETTINGS_DEFAULT_TERMS_OF_SERVICE_LINK = "https://about.mattermost.com/default-terms/"
+ SUPPORT_SETTINGS_DEFAULT_PRIVACY_POLICY_LINK = "https://about.mattermost.com/default-privacy-policy/"
+ SUPPORT_SETTINGS_DEFAULT_ABOUT_LINK = "https://about.mattermost.com/default-about/"
+ SUPPORT_SETTINGS_DEFAULT_HELP_LINK = "https://about.mattermost.com/default-help/"
+ SUPPORT_SETTINGS_DEFAULT_REPORT_A_PROBLEM_LINK = "https://about.mattermost.com/default-report-a-problem/"
+ SUPPORT_SETTINGS_DEFAULT_ADMINISTRATORS_GUIDE_LINK = "https://about.mattermost.com/administrators-guide/"
+ SUPPORT_SETTINGS_DEFAULT_TROUBLESHOOTING_FORUM_LINK = "https://about.mattermost.com/troubleshooting-forum/"
+ SUPPORT_SETTINGS_DEFAULT_COMMERCIAL_SUPPORT_LINK = "https://about.mattermost.com/commercial-support/"
+ SUPPORT_SETTINGS_DEFAULT_SUPPORT_EMAIL = "feedback@mattermost.com"
LDAP_SETTINGS_DEFAULT_FIRST_NAME_ATTRIBUTE = ""
LDAP_SETTINGS_DEFAULT_LAST_NAME_ATTRIBUTE = ""
@@ -274,12 +277,15 @@ type PrivacySettings struct {
}
type SupportSettings struct {
- TermsOfServiceLink *string
- PrivacyPolicyLink *string
- AboutLink *string
- HelpLink *string
- ReportAProblemLink *string
- SupportEmail *string
+ TermsOfServiceLink *string
+ PrivacyPolicyLink *string
+ AboutLink *string
+ HelpLink *string
+ ReportAProblemLink *string
+ AdministratorsGuideLink *string
+ TroubleshootingForumLink *string
+ CommercialSupportLink *string
+ SupportEmail *string
}
type TeamSettings struct {
@@ -758,6 +764,33 @@ func (o *Config) SetDefaults() {
*o.SupportSettings.ReportAProblemLink = SUPPORT_SETTINGS_DEFAULT_REPORT_A_PROBLEM_LINK
}
+ if !IsSafeLink(o.SupportSettings.AdministratorsGuideLink) {
+ *o.SupportSettings.AdministratorsGuideLink = ""
+ }
+
+ if o.SupportSettings.AdministratorsGuideLink == nil {
+ o.SupportSettings.AdministratorsGuideLink = new(string)
+ *o.SupportSettings.AdministratorsGuideLink = SUPPORT_SETTINGS_DEFAULT_ADMINISTRATORS_GUIDE_LINK
+ }
+
+ if !IsSafeLink(o.SupportSettings.TroubleshootingForumLink) {
+ *o.SupportSettings.TroubleshootingForumLink = ""
+ }
+
+ if o.SupportSettings.TroubleshootingForumLink == nil {
+ o.SupportSettings.TroubleshootingForumLink = new(string)
+ *o.SupportSettings.TroubleshootingForumLink = SUPPORT_SETTINGS_DEFAULT_TROUBLESHOOTING_FORUM_LINK
+ }
+
+ if !IsSafeLink(o.SupportSettings.CommercialSupportLink) {
+ *o.SupportSettings.CommercialSupportLink = ""
+ }
+
+ if o.SupportSettings.CommercialSupportLink == nil {
+ o.SupportSettings.CommercialSupportLink = new(string)
+ *o.SupportSettings.CommercialSupportLink = SUPPORT_SETTINGS_DEFAULT_COMMERCIAL_SUPPORT_LINK
+ }
+
if o.SupportSettings.SupportEmail == nil {
o.SupportSettings.SupportEmail = new(string)
*o.SupportSettings.SupportEmail = SUPPORT_SETTINGS_DEFAULT_SUPPORT_EMAIL
diff --git a/model/license.go b/model/license.go
index 57c49d3d8..558cd43fa 100644
--- a/model/license.go
+++ b/model/license.go
@@ -49,24 +49,26 @@ type Features struct {
MHPNS *bool `json:"mhpns"`
SAML *bool `json:"saml"`
PasswordRequirements *bool `json:"password_requirements"`
+ ElasticSearch *bool `json:"elastic_search"`
// after we enabled more features for webrtc we'll need to control them with this
FutureFeatures *bool `json:"future_features"`
}
func (f *Features) ToMap() map[string]interface{} {
return map[string]interface{}{
- "ldap": *f.LDAP,
- "mfa": *f.MFA,
- "google": *f.GoogleOAuth,
- "office365": *f.Office365OAuth,
- "compliance": *f.Compliance,
- "cluster": *f.Cluster,
- "metrics": *f.Metrics,
- "custom_brand": *f.CustomBrand,
- "mhpns": *f.MHPNS,
- "saml": *f.SAML,
- "password": *f.PasswordRequirements,
- "future": *f.FutureFeatures,
+ "ldap": *f.LDAP,
+ "mfa": *f.MFA,
+ "google": *f.GoogleOAuth,
+ "office365": *f.Office365OAuth,
+ "compliance": *f.Compliance,
+ "cluster": *f.Cluster,
+ "metrics": *f.Metrics,
+ "custom_brand": *f.CustomBrand,
+ "mhpns": *f.MHPNS,
+ "saml": *f.SAML,
+ "password": *f.PasswordRequirements,
+ "elastic_search": *f.ElasticSearch,
+ "future": *f.FutureFeatures,
}
}
@@ -135,6 +137,11 @@ func (f *Features) SetDefaults() {
f.PasswordRequirements = new(bool)
*f.PasswordRequirements = *f.FutureFeatures
}
+
+ if f.ElasticSearch == nil {
+ f.ElasticSearch = new(bool)
+ *f.ElasticSearch = *f.FutureFeatures
+ }
}
func (l *License) IsExpired() bool {
diff --git a/model/license_test.go b/model/license_test.go
index 1c6a277e8..8b65d0700 100644
--- a/model/license_test.go
+++ b/model/license_test.go
@@ -25,6 +25,7 @@ func TestLicenseFeaturesToMap(t *testing.T) {
CheckTrue(t, m["mhpns"].(bool))
CheckTrue(t, m["saml"].(bool))
CheckTrue(t, m["password"].(bool))
+ CheckTrue(t, m["elastic_search"].(bool))
CheckTrue(t, m["future"].(bool))
}
@@ -44,6 +45,7 @@ func TestLicenseFeaturesSetDefaults(t *testing.T) {
CheckTrue(t, *f.MHPNS)
CheckTrue(t, *f.SAML)
CheckTrue(t, *f.PasswordRequirements)
+ CheckTrue(t, *f.ElasticSearch)
CheckTrue(t, *f.FutureFeatures)
f = Features{}
@@ -62,6 +64,7 @@ func TestLicenseFeaturesSetDefaults(t *testing.T) {
*f.MHPNS = true
*f.SAML = true
*f.PasswordRequirements = true
+ *f.ElasticSearch = true
f.SetDefaults()
@@ -77,6 +80,7 @@ func TestLicenseFeaturesSetDefaults(t *testing.T) {
CheckTrue(t, *f.MHPNS)
CheckTrue(t, *f.SAML)
CheckTrue(t, *f.PasswordRequirements)
+ CheckTrue(t, *f.ElasticSearch)
CheckFalse(t, *f.FutureFeatures)
}
@@ -157,6 +161,7 @@ func TestLicenseToFromJson(t *testing.T) {
CheckBool(t, *f1.MHPNS, *f.MHPNS)
CheckBool(t, *f1.SAML, *f.SAML)
CheckBool(t, *f1.PasswordRequirements, *f.PasswordRequirements)
+ CheckBool(t, *f1.ElasticSearch, *f.ElasticSearch)
CheckBool(t, *f1.FutureFeatures, *f.FutureFeatures)
invalid := `{"asdf`