Add system console switch for enabling link previews (#5663)
Этот коммит содержится в:
коммит произвёл
Christopher Speller
родитель
f99658152a
Коммит
e87f5c6cf9
@@ -452,6 +452,11 @@ func getFileInfosForPost(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getOpenGraphMetadata(c *Context, w http.ResponseWriter, r *http.Request) {
|
func getOpenGraphMetadata(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||||
|
if !*utils.Cfg.ServiceSettings.EnableLinkPreviews {
|
||||||
|
c.Err = model.NewAppError("getOpenGraphMetadata", "api.post.link_preview_disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
props := model.StringInterfaceFromJson(r.Body)
|
props := model.StringInterfaceFromJson(r.Body)
|
||||||
|
|
||||||
ogJSONGeneric, ok := openGraphDataCache.Get(props["url"])
|
ogJSONGeneric, ok := openGraphDataCache.Get(props["url"])
|
||||||
|
|||||||
@@ -1307,6 +1307,12 @@ func TestGetOpenGraphMetadata(t *testing.T) {
|
|||||||
th := Setup().InitBasic()
|
th := Setup().InitBasic()
|
||||||
Client := th.BasicClient
|
Client := th.BasicClient
|
||||||
|
|
||||||
|
enableLinkPreviews := *utils.Cfg.ServiceSettings.EnableLinkPreviews
|
||||||
|
defer func() {
|
||||||
|
*utils.Cfg.ServiceSettings.EnableLinkPreviews = enableLinkPreviews
|
||||||
|
}()
|
||||||
|
*utils.Cfg.ServiceSettings.EnableLinkPreviews = true
|
||||||
|
|
||||||
ogDataCacheMissCount := 0
|
ogDataCacheMissCount := 0
|
||||||
|
|
||||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -1355,4 +1361,9 @@ func TestGetOpenGraphMetadata(t *testing.T) {
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*utils.Cfg.ServiceSettings.EnableLinkPreviews = false
|
||||||
|
if _, err := Client.DoApiPost("/get_opengraph_metadata", "{\"url\":\"/og-data/\"}"); err == nil || err.StatusCode != http.StatusNotImplemented {
|
||||||
|
t.Fatal("should have failed with 501 - disabled link previews")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
"EnableOnlyAdminIntegrations": true,
|
"EnableOnlyAdminIntegrations": true,
|
||||||
"EnablePostUsernameOverride": false,
|
"EnablePostUsernameOverride": false,
|
||||||
"EnablePostIconOverride": false,
|
"EnablePostIconOverride": false,
|
||||||
|
"EnableLinkPreviews": false,
|
||||||
"EnableTesting": false,
|
"EnableTesting": false,
|
||||||
"EnableDeveloper": false,
|
"EnableDeveloper": false,
|
||||||
"EnableSecurityFixAlert": true,
|
"EnableSecurityFixAlert": true,
|
||||||
|
|||||||
@@ -3,6 +3,10 @@
|
|||||||
"id": "April",
|
"id": "April",
|
||||||
"translation": "April"
|
"translation": "April"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "api.post.link_preview_disabled.app_error",
|
||||||
|
"translation": "Link previews have been disabled by the system administrator."
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "August",
|
"id": "August",
|
||||||
"translation": "August"
|
"translation": "August"
|
||||||
|
|||||||
@@ -129,6 +129,7 @@ type ServiceSettings struct {
|
|||||||
EnableOnlyAdminIntegrations *bool
|
EnableOnlyAdminIntegrations *bool
|
||||||
EnablePostUsernameOverride bool
|
EnablePostUsernameOverride bool
|
||||||
EnablePostIconOverride bool
|
EnablePostIconOverride bool
|
||||||
|
EnableLinkPreviews *bool
|
||||||
EnableTesting bool
|
EnableTesting bool
|
||||||
EnableDeveloper *bool
|
EnableDeveloper *bool
|
||||||
EnableSecurityFixAlert *bool
|
EnableSecurityFixAlert *bool
|
||||||
@@ -495,6 +496,11 @@ func (o *Config) SetDefaults() {
|
|||||||
*o.ServiceSettings.SiteURL = SERVICE_SETTINGS_DEFAULT_SITE_URL
|
*o.ServiceSettings.SiteURL = SERVICE_SETTINGS_DEFAULT_SITE_URL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if o.ServiceSettings.EnableLinkPreviews == nil {
|
||||||
|
o.ServiceSettings.EnableLinkPreviews = new(bool)
|
||||||
|
*o.ServiceSettings.EnableLinkPreviews = false
|
||||||
|
}
|
||||||
|
|
||||||
if o.ServiceSettings.EnableDeveloper == nil {
|
if o.ServiceSettings.EnableDeveloper == nil {
|
||||||
o.ServiceSettings.EnableDeveloper = new(bool)
|
o.ServiceSettings.EnableDeveloper = new(bool)
|
||||||
*o.ServiceSettings.EnableDeveloper = false
|
*o.ServiceSettings.EnableDeveloper = false
|
||||||
|
|||||||
@@ -267,6 +267,7 @@ func getClientConfig(c *model.Config) map[string]string {
|
|||||||
props["EnableOnlyAdminIntegrations"] = strconv.FormatBool(*c.ServiceSettings.EnableOnlyAdminIntegrations)
|
props["EnableOnlyAdminIntegrations"] = strconv.FormatBool(*c.ServiceSettings.EnableOnlyAdminIntegrations)
|
||||||
props["EnablePostUsernameOverride"] = strconv.FormatBool(c.ServiceSettings.EnablePostUsernameOverride)
|
props["EnablePostUsernameOverride"] = strconv.FormatBool(c.ServiceSettings.EnablePostUsernameOverride)
|
||||||
props["EnablePostIconOverride"] = strconv.FormatBool(c.ServiceSettings.EnablePostIconOverride)
|
props["EnablePostIconOverride"] = strconv.FormatBool(c.ServiceSettings.EnablePostIconOverride)
|
||||||
|
props["EnableLinkPreviews"] = strconv.FormatBool(*c.ServiceSettings.EnableLinkPreviews)
|
||||||
props["EnableTesting"] = strconv.FormatBool(c.ServiceSettings.EnableTesting)
|
props["EnableTesting"] = strconv.FormatBool(c.ServiceSettings.EnableTesting)
|
||||||
props["EnableDeveloper"] = strconv.FormatBool(*c.ServiceSettings.EnableDeveloper)
|
props["EnableDeveloper"] = strconv.FormatBool(*c.ServiceSettings.EnableDeveloper)
|
||||||
props["EnableDiagnostics"] = strconv.FormatBool(*c.LogSettings.EnableDiagnostics)
|
props["EnableDiagnostics"] = strconv.FormatBool(*c.LogSettings.EnableDiagnostics)
|
||||||
|
|||||||
@@ -623,6 +623,10 @@ export function redirectUserToDefaultTeam() {
|
|||||||
|
|
||||||
requestOpenGraphMetadata.openGraphMetadataOnGoingRequests = {}; // Format: {<url>: true}
|
requestOpenGraphMetadata.openGraphMetadataOnGoingRequests = {}; // Format: {<url>: true}
|
||||||
export function requestOpenGraphMetadata(url) {
|
export function requestOpenGraphMetadata(url) {
|
||||||
|
if (global.mm_config.EnableLinkPreviews !== 'true') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const onself = requestOpenGraphMetadata;
|
const onself = requestOpenGraphMetadata;
|
||||||
|
|
||||||
if (!onself.openGraphMetadataOnGoingRequests[url]) {
|
if (!onself.openGraphMetadataOnGoingRequests[url]) {
|
||||||
|
|||||||
@@ -689,6 +689,16 @@ export default class AdminSidebar extends React.Component {
|
|||||||
|
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
<AdminSidebarSection
|
||||||
|
name='link_previews'
|
||||||
|
title={
|
||||||
|
<FormattedMessage
|
||||||
|
id='admin.sidebar.linkPreviews'
|
||||||
|
defaultMessage='Link Previews'
|
||||||
|
/>
|
||||||
|
|
||||||
|
}
|
||||||
|
/>
|
||||||
<AdminSidebarSection
|
<AdminSidebarSection
|
||||||
name='legal_and_support'
|
name='legal_and_support'
|
||||||
title={
|
title={
|
||||||
|
|||||||
66
webapp/components/admin_console/link_previews_settings.jsx
Обычный файл
66
webapp/components/admin_console/link_previews_settings.jsx
Обычный файл
@@ -0,0 +1,66 @@
|
|||||||
|
// Copyright (c) 2017 Mattermost, Inc. All Rights Reserved.
|
||||||
|
// See License.txt for license information.
|
||||||
|
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import AdminSettings from './admin_settings.jsx';
|
||||||
|
import BooleanSetting from './boolean_setting.jsx';
|
||||||
|
import {FormattedMessage} from 'react-intl';
|
||||||
|
import SettingsGroup from './settings_group.jsx';
|
||||||
|
|
||||||
|
export default class LinkPreviewsSettings extends AdminSettings {
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
|
||||||
|
this.getConfigFromState = this.getConfigFromState.bind(this);
|
||||||
|
|
||||||
|
this.renderSettings = this.renderSettings.bind(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
getConfigFromState(config) {
|
||||||
|
config.ServiceSettings.EnableLinkPreviews = this.state.enableLinkPreviews;
|
||||||
|
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
|
getStateFromConfig(config) {
|
||||||
|
return {
|
||||||
|
enableLinkPreviews: config.ServiceSettings.EnableLinkPreviews
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
renderTitle() {
|
||||||
|
return (
|
||||||
|
<h3>
|
||||||
|
<FormattedMessage
|
||||||
|
id='admin.customization.linkPreviews'
|
||||||
|
defaultMessage='Link Previews'
|
||||||
|
/>
|
||||||
|
</h3>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
renderSettings() {
|
||||||
|
return (
|
||||||
|
<SettingsGroup>
|
||||||
|
<BooleanSetting
|
||||||
|
id='enableLinkPreviews'
|
||||||
|
label={
|
||||||
|
<FormattedMessage
|
||||||
|
id='admin.customization.enableLinkPreviewsTitle'
|
||||||
|
defaultMessage='Enable Link Previews:'
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
helpText={
|
||||||
|
<FormattedMessage
|
||||||
|
id='admin.customization.enableLinkPreviewsDesc'
|
||||||
|
defaultMessage='Enable users to display a preview of website content below the message, if available. When true, website previews can be enabled from Account Settings > Advanced > Preview pre-release features.'
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
value={this.state.enableLinkPreviews}
|
||||||
|
onChange={this.handleChange}
|
||||||
|
/>
|
||||||
|
</SettingsGroup>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -53,14 +53,19 @@ export default class AdvancedSettingsDisplay extends React.Component {
|
|||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const webrtcEnabled = global.mm_config.EnableWebrtc === 'true';
|
||||||
|
const linkPreviewsEnabled = global.mm_config.EnableLinkPreviews === 'true';
|
||||||
|
|
||||||
|
if (!webrtcEnabled) {
|
||||||
|
preReleaseFeaturesKeys = preReleaseFeaturesKeys.filter((f) => f !== 'WEBRTC_PREVIEW');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!linkPreviewsEnabled) {
|
||||||
|
preReleaseFeaturesKeys = preReleaseFeaturesKeys.filter((f) => f !== 'EMBED_PREVIEW');
|
||||||
|
}
|
||||||
|
|
||||||
let enabledFeatures = 0;
|
let enabledFeatures = 0;
|
||||||
for (const [name, value] of advancedSettings) {
|
for (const [name, value] of advancedSettings) {
|
||||||
const webrtcEnabled = global.mm_config.EnableWebrtc === 'true';
|
|
||||||
|
|
||||||
if (!webrtcEnabled) {
|
|
||||||
preReleaseFeaturesKeys = preReleaseFeaturesKeys.filter((f) => f !== 'WEBRTC_PREVIEW');
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const key of preReleaseFeaturesKeys) {
|
for (const key of preReleaseFeaturesKeys) {
|
||||||
const feature = PreReleaseFeatures[key];
|
const feature = PreReleaseFeatures[key];
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
{
|
{
|
||||||
|
"admin.customization.enableLinkPreviewsDesc": "Enable users to display a preview of website content below the message, if available. When true, website previews can be enabled from Account Settings > Advanced > Preview pre-release features.",
|
||||||
|
"admin.customization.enableLinkPreviewsTitle": "Enable Link Previews:",
|
||||||
|
"admin.customization.linkPreviews": "Link Previews",
|
||||||
|
"admin.sidebar.linkPreviews": "Link Previews",
|
||||||
"multiselect.go": "Go",
|
"multiselect.go": "Go",
|
||||||
"multiselect.instructions": "Use up/down arrows to navigate and enter to select",
|
"multiselect.instructions": "Use up/down arrows to navigate and enter to select",
|
||||||
"multiselect.placeholder": "Search and add members",
|
"multiselect.placeholder": "Search and add members",
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ import StorageSettings from 'components/admin_console/storage_settings.jsx';
|
|||||||
import ImageSettings from 'components/admin_console/image_settings.jsx';
|
import ImageSettings from 'components/admin_console/image_settings.jsx';
|
||||||
import CustomBrandSettings from 'components/admin_console/custom_brand_settings.jsx';
|
import CustomBrandSettings from 'components/admin_console/custom_brand_settings.jsx';
|
||||||
import CustomEmojiSettings from 'components/admin_console/custom_emoji_settings.jsx';
|
import CustomEmojiSettings from 'components/admin_console/custom_emoji_settings.jsx';
|
||||||
|
import LinkPreviewsSettings from 'components/admin_console/link_previews_settings.jsx';
|
||||||
import LegalAndSupportSettings from 'components/admin_console/legal_and_support_settings.jsx';
|
import LegalAndSupportSettings from 'components/admin_console/legal_and_support_settings.jsx';
|
||||||
import NativeAppLinkSettings from 'components/admin_console/native_app_link_settings.jsx';
|
import NativeAppLinkSettings from 'components/admin_console/native_app_link_settings.jsx';
|
||||||
import ComplianceSettings from 'components/admin_console/compliance_settings.jsx';
|
import ComplianceSettings from 'components/admin_console/compliance_settings.jsx';
|
||||||
@@ -180,6 +181,10 @@ export default (
|
|||||||
path='custom_emoji'
|
path='custom_emoji'
|
||||||
component={CustomEmojiSettings}
|
component={CustomEmojiSettings}
|
||||||
/>
|
/>
|
||||||
|
<Route
|
||||||
|
path='link_previews'
|
||||||
|
component={LinkPreviewsSettings}
|
||||||
|
/>
|
||||||
<Route
|
<Route
|
||||||
path='legal_and_support'
|
path='legal_and_support'
|
||||||
component={LegalAndSupportSettings}
|
component={LegalAndSupportSettings}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user