From eacc06c7fc712e8b2e71c408327a449bc32c34d9 Mon Sep 17 00:00:00 2001 From: Reed Garmsen Date: Fri, 13 Nov 2015 16:22:32 -0800 Subject: Allow admins to change the display name for the default channel --- api/channel.go | 8 ++-- web/react/components/channel_header.jsx | 41 +++++++++++--------- web/react/components/navbar.jsx | 56 ++++++++++++++------------- web/react/components/rename_channel_modal.jsx | 51 +++++++++++++++--------- web/sass-files/sass/partials/_forms.scss | 4 ++ 5 files changed, 92 insertions(+), 68 deletions(-) diff --git a/api/channel.go b/api/channel.go index 75ca9680d..99640e71a 100644 --- a/api/channel.go +++ b/api/channel.go @@ -205,9 +205,11 @@ func updateChannel(c *Context, w http.ResponseWriter, r *http.Request) { } if oldChannel.Name == model.DEFAULT_CHANNEL { - c.Err = model.NewAppError("updateChannel", "Cannot update the default channel "+model.DEFAULT_CHANNEL, "") - c.Err.StatusCode = http.StatusForbidden - return + if (len(channel.Name) > 0 && channel.Name != oldChannel.Name) || (len(channel.Type) > 0 && channel.Type != oldChannel.Type) { + c.Err = model.NewAppError("updateChannel", "Tried to perform an invalid update of the default channel "+model.DEFAULT_CHANNEL, "") + c.Err.StatusCode = http.StatusForbidden + return + } } oldChannel.Header = channel.Header diff --git a/web/react/components/channel_header.jsx b/web/react/components/channel_header.jsx index a8d4ec100..79c7f90a9 100644 --- a/web/react/components/channel_header.jsx +++ b/web/react/components/channel_header.jsx @@ -276,26 +276,27 @@ export default class ChannelHeader extends React.Component { ); - if (!ChannelStore.isDefault(channel)) { - if (isAdmin) { - dropdownContents.push( -
  • + - - {'Rename '}{channelTerm}{'...'} - -
  • - ); + {'Rename '}{channelTerm}{'...'} + + + ); + + if (!ChannelStore.isDefault(channel)) { dropdownContents.push(
  • ); } + } + if (!ChannelStore.isDefault(channel)) { dropdownContents.push(
  • - this.setState({showMembersModal: true})} - > - {'Manage Members'} - -
  • - ); + if (!isDirect && isAdmin) { + if (!ChannelStore.isDefault(channel)) { + manageMembersOption = ( +
  • + this.setState({showMembersModal: true})} + > + {'Manage Members'} + +
  • + ); + + deleteChannelOption = ( +
  • + + {'Delete Channel...'} + +
  • + ); + } renameChannelOption = (
  • @@ -206,21 +223,6 @@ export default class Navbar extends React.Component {
  • ); - - deleteChannelOption = ( -
  • - - {'Delete Channel...'} - -
  • - ); } var notificationPreferenceOption; diff --git a/web/react/components/rename_channel_modal.jsx b/web/react/components/rename_channel_modal.jsx index 9fb3af035..f47009cce 100644 --- a/web/react/components/rename_channel_modal.jsx +++ b/web/react/components/rename_channel_modal.jsx @@ -5,6 +5,7 @@ const Utils = require('../utils/utils.jsx'); const Client = require('../utils/client.jsx'); const AsyncClient = require('../utils/async_client.jsx'); const ChannelStore = require('../stores/channel_store.jsx'); +const Constants = require('../utils/constants.jsx'); export default class RenameChannelModal extends React.Component { constructor(props) { @@ -36,10 +37,10 @@ export default class RenameChannelModal extends React.Component { return; } - let channel = ChannelStore.get(this.state.channelId); + const channel = ChannelStore.get(this.state.channelId); const oldName = channel.name; const oldDisplayName = channel.displayName; - let state = {serverError: ''}; + const state = {serverError: ''}; channel.display_name = this.state.displayName.trim(); if (!channel.display_name) { @@ -60,7 +61,7 @@ export default class RenameChannelModal extends React.Component { state.nameError = 'This field must be less than 22 characters'; state.invalid = true; } else { - let cleanedName = Utils.cleanUpUrlable(channel.name); + const cleanedName = Utils.cleanUpUrlable(channel.name); if (cleanedName === channel.name) { state.nameError = ''; } else { @@ -76,7 +77,7 @@ export default class RenameChannelModal extends React.Component { } Client.updateChannel(channel, - function handleUpdateSuccess() { + () => { $(ReactDOM.findDOMNode(this.refs.modal)).modal('hide'); AsyncClient.getChannel(channel.id); @@ -84,12 +85,12 @@ export default class RenameChannelModal extends React.Component { ReactDOM.findDOMNode(this.refs.displayName).value = ''; ReactDOM.findDOMNode(this.refs.channelName).value = ''; - }.bind(this), - function handleUpdateError(err) { + }, + (err) => { state.serverError = err.message; state.invalid = true; this.setState(state); - }.bind(this) + } ); } onNameChange() { @@ -99,10 +100,12 @@ export default class RenameChannelModal extends React.Component { this.setState({displayName: ReactDOM.findDOMNode(this.refs.displayName).value}); } displayNameKeyUp() { - const displayName = ReactDOM.findDOMNode(this.refs.displayName).value.trim(); - const channelName = Utils.cleanUpUrlable(displayName); - ReactDOM.findDOMNode(this.refs.channelName).value = channelName; - this.setState({channelName: channelName}); + if (this.state.channelName !== Constants.DEFAULT_CHANNEL) { + const displayName = ReactDOM.findDOMNode(this.refs.displayName).value.trim(); + const channelName = Utils.cleanUpUrlable(displayName); + ReactDOM.findDOMNode(this.refs.channelName).value = channelName; + this.setState({channelName: channelName}); + } } handleClose() { this.setState({ @@ -150,6 +153,15 @@ export default class RenameChannelModal extends React.Component { serverError =
    ; } + let handleInputLabel = 'Handle'; + let handleInputClass = 'form-control'; + let readOnlyHandleInput = false; + if (this.state.channelName === Constants.DEFAULT_CHANNEL) { + handleInputLabel += ' - Cannot be changed for the default channel'; + handleInputClass += ' disabled-input'; + readOnlyHandleInput = true; + } + return (
    - - Close + + {'Close'} -

    Rename Channel

    +

    {'Rename Channel'}

    - +
    - + {nameError}
    @@ -210,14 +223,14 @@ export default class RenameChannelModal extends React.Component { className='btn btn-default' data-dismiss='modal' > - Cancel + {'Cancel'}
    diff --git a/web/sass-files/sass/partials/_forms.scss b/web/sass-files/sass/partials/_forms.scss index 2d7b6cd26..9499d9b53 100644 --- a/web/sass-files/sass/partials/_forms.scss +++ b/web/sass-files/sass/partials/_forms.scss @@ -43,3 +43,7 @@ margin: 10px 0 0; color: #999; } + +.disabled-input { + background-color: #dddddd !important; +} \ No newline at end of file -- cgit v1.2.3-1-g7c22 From 1874a16666cdcf65b11f2d0f03d50d6b880e15f7 Mon Sep 17 00:00:00 2001 From: Reed Garmsen Date: Fri, 13 Nov 2015 17:15:09 -0800 Subject: Fixed unit test issues --- api/channel_test.go | 3 ++- web/sass-files/sass/partials/_forms.scss | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/api/channel_test.go b/api/channel_test.go index faed387dd..e7e1f4eb0 100644 --- a/api/channel_test.go +++ b/api/channel_test.go @@ -215,8 +215,9 @@ func TestUpdateChannel(t *testing.T) { for _, c := range data.Channels { if c.Name == model.DEFAULT_CHANNEL { c.Header = "new header" + c.Name = "pseudo-square" if _, err := Client.UpdateChannel(c); err == nil { - t.Fatal("should have errored on updating default channel") + t.Fatal("should have errored on updating default channel name") } break } diff --git a/web/sass-files/sass/partials/_forms.scss b/web/sass-files/sass/partials/_forms.scss index 9499d9b53..685677ad0 100644 --- a/web/sass-files/sass/partials/_forms.scss +++ b/web/sass-files/sass/partials/_forms.scss @@ -46,4 +46,4 @@ .disabled-input { background-color: #dddddd !important; -} \ No newline at end of file +} -- cgit v1.2.3-1-g7c22