PLT-2674 Private Group should not have Leave option when only one member remains (#2888)
Этот коммит содержится в:
коммит произвёл
Christopher Speller
родитель
4f39b8b2e4
Коммит
45b22f312d
@@ -576,6 +576,7 @@ func leave(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
sc := Srv.Store.Channel().Get(id)
|
sc := Srv.Store.Channel().Get(id)
|
||||||
uc := Srv.Store.User().Get(c.Session.UserId)
|
uc := Srv.Store.User().Get(c.Session.UserId)
|
||||||
|
ccm := Srv.Store.Channel().GetMemberCount(id)
|
||||||
|
|
||||||
if cresult := <-sc; cresult.Err != nil {
|
if cresult := <-sc; cresult.Err != nil {
|
||||||
c.Err = cresult.Err
|
c.Err = cresult.Err
|
||||||
@@ -583,9 +584,13 @@ func leave(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
} else if uresult := <-uc; uresult.Err != nil {
|
} else if uresult := <-uc; uresult.Err != nil {
|
||||||
c.Err = cresult.Err
|
c.Err = cresult.Err
|
||||||
return
|
return
|
||||||
|
} else if ccmresult := <-ccm; ccmresult.Err != nil {
|
||||||
|
c.Err = ccmresult.Err
|
||||||
|
return
|
||||||
} else {
|
} else {
|
||||||
channel := cresult.Data.(*model.Channel)
|
channel := cresult.Data.(*model.Channel)
|
||||||
user := uresult.Data.(*model.User)
|
user := uresult.Data.(*model.User)
|
||||||
|
membersCount := ccmresult.Data.(int64)
|
||||||
|
|
||||||
if !c.HasPermissionsToTeam(channel.TeamId, "leave") {
|
if !c.HasPermissionsToTeam(channel.TeamId, "leave") {
|
||||||
return
|
return
|
||||||
@@ -597,6 +602,12 @@ func leave(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if channel.Type == model.CHANNEL_PRIVATE && membersCount == 1 {
|
||||||
|
c.Err = model.NewLocAppError("leave", "api.channel.leave.last_member.app_error", nil, "userId="+user.Id)
|
||||||
|
c.Err.StatusCode = http.StatusBadRequest
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if channel.Name == model.DEFAULT_CHANNEL {
|
if channel.Name == model.DEFAULT_CHANNEL {
|
||||||
c.Err = model.NewLocAppError("leave", "api.channel.leave.default.app_error", map[string]interface{}{"Channel": model.DEFAULT_CHANNEL}, "")
|
c.Err = model.NewLocAppError("leave", "api.channel.leave.default.app_error", map[string]interface{}{"Channel": model.DEFAULT_CHANNEL}, "")
|
||||||
c.Err.StatusCode = http.StatusBadRequest
|
c.Err.StatusCode = http.StatusBadRequest
|
||||||
|
|||||||
@@ -485,8 +485,10 @@ func TestLeaveChannel(t *testing.T) {
|
|||||||
|
|
||||||
Client.Must(Client.JoinChannel(channel1.Id))
|
Client.Must(Client.JoinChannel(channel1.Id))
|
||||||
|
|
||||||
// No error if you leave a channel you cannot see
|
// Cannot leave a the private group if you are the only member
|
||||||
Client.Must(Client.LeaveChannel(channel3.Id))
|
if _, err := Client.LeaveChannel(channel3.Id); err == nil {
|
||||||
|
t.Fatal("should have errored, cannot leave private group if only one member")
|
||||||
|
}
|
||||||
|
|
||||||
rchannel := Client.Must(Client.CreateDirectChannel(th.BasicUser.Id)).Data.(*model.Channel)
|
rchannel := Client.Must(Client.CreateDirectChannel(th.BasicUser.Id)).Data.(*model.Channel)
|
||||||
|
|
||||||
|
|||||||
@@ -223,6 +223,10 @@
|
|||||||
"id": "api.channel.leave.direct.app_error",
|
"id": "api.channel.leave.direct.app_error",
|
||||||
"translation": "Cannot leave a direct message channel"
|
"translation": "Cannot leave a direct message channel"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "api.channel.leave.last_member.app_error",
|
||||||
|
"translation": "You're the only member left, try removing the Private Group instead of leaving."
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "api.channel.leave.left",
|
"id": "api.channel.leave.left",
|
||||||
"translation": "%v has left the channel."
|
"translation": "%v has left the channel."
|
||||||
|
|||||||
@@ -223,6 +223,10 @@
|
|||||||
"id": "api.channel.leave.direct.app_error",
|
"id": "api.channel.leave.direct.app_error",
|
||||||
"translation": "No puedes dejar un mensaje directo a un canal"
|
"translation": "No puedes dejar un mensaje directo a un canal"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "api.channel.leave.last_member.app_error",
|
||||||
|
"translation": "Eres el último miembro que queda, intenta remover el Grupo Privado en vez de salirte."
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "api.channel.leave.left",
|
"id": "api.channel.leave.left",
|
||||||
"translation": "%v ha abandonado el canal."
|
"translation": "%v ha abandonado el canal."
|
||||||
|
|||||||
@@ -409,7 +409,8 @@ export default class ChannelHeader extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ChannelStore.isDefault(channel)) {
|
const canLeave = channel.type === Constants.PRIVATE_CHANNEL ? this.state.userCount > 1 : true;
|
||||||
|
if (!ChannelStore.isDefault(channel) && canLeave) {
|
||||||
dropdownContents.push(
|
dropdownContents.push(
|
||||||
<li
|
<li
|
||||||
key='leave_channel'
|
key='leave_channel'
|
||||||
|
|||||||
@@ -218,20 +218,23 @@ export default class Navbar extends React.Component {
|
|||||||
</li>
|
</li>
|
||||||
);
|
);
|
||||||
|
|
||||||
leaveChannelOption = (
|
const canLeave = channel.type === Constants.PRIVATE_CHANNEL ? this.state.userCount > 1 : true;
|
||||||
<li role='presentation'>
|
if (canLeave) {
|
||||||
<a
|
leaveChannelOption = (
|
||||||
role='menuitem'
|
<li role='presentation'>
|
||||||
href='#'
|
<a
|
||||||
onClick={this.handleLeave}
|
role='menuitem'
|
||||||
>
|
href='#'
|
||||||
<FormattedMessage
|
onClick={this.handleLeave}
|
||||||
id='navbar.leave'
|
>
|
||||||
defaultMessage='Leave Channel'
|
<FormattedMessage
|
||||||
/>
|
id='navbar.leave'
|
||||||
</a>
|
defaultMessage='Leave Channel'
|
||||||
</li>
|
/>
|
||||||
);
|
</a>
|
||||||
|
</li>
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var manageMembersOption;
|
var manageMembersOption;
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user