PLT-1909 Removed the ability to edit system posts (#3013)

* Removed the ability to edit system posts

* Added increased timeout to SpinnerButton unit tests
Этот коммит содержится в:
Harrison Healey
2016-05-17 12:27:03 -04:00
коммит произвёл Christopher Speller
родитель 5580c28e54
Коммит 0fe75cb782
7 изменённых файлов: 28 добавлений и 3 удалений

Просмотреть файл

@@ -919,6 +919,12 @@ func updatePost(c *Context, w http.ResponseWriter, r *http.Request) {
c.Err.StatusCode = http.StatusForbidden c.Err.StatusCode = http.StatusForbidden
return return
} }
if oldPost.IsSystemMessage() {
c.Err = model.NewLocAppError("updatePost", "api.post.update_post.system_message.app_error", nil, "id="+post.Id)
c.Err.StatusCode = http.StatusForbidden
return
}
} }
hashtags, _ := model.ParseHashtags(post.Message) hashtags, _ := model.ParseHashtags(post.Message)

Просмотреть файл

@@ -155,6 +155,17 @@ func TestUpdatePost(t *testing.T) {
t.Fatal("failed to updates") t.Fatal("failed to updates")
} }
} }
post3 := &model.Post{ChannelId: channel1.Id, Message: "a" + model.NewId() + "a", Type: model.POST_JOIN_LEAVE}
rpost3, err := Client.CreatePost(post3)
if err != nil {
t.Fatal(err)
}
up3 := &model.Post{Id: rpost3.Data.(*model.Post).Id, ChannelId: channel1.Id, Message: "a" + model.NewId() + " update post 3"}
if _, err := Client.UpdatePost(up3); err == nil {
t.Fatal("shouldn't have been able to update system message")
}
} }
func TestGetPosts(t *testing.T) { func TestGetPosts(t *testing.T) {

Просмотреть файл

@@ -935,6 +935,10 @@
"id": "api.post.update_post.permissions_details.app_error", "id": "api.post.update_post.permissions_details.app_error",
"translation": "Already deleted id={{.PostId}}" "translation": "Already deleted id={{.PostId}}"
}, },
{
"id": "api.post.update_post.system_message.app_error",
"translation": "Unable to update system message"
},
{ {
"id": "api.post_get_post_by_id.get.app_error", "id": "api.post_get_post_by_id.get.app_error",
"translation": "Unable to get post" "translation": "Unable to get post"

Просмотреть файл

@@ -33,6 +33,7 @@ export default class PostInfo extends React.Component {
var post = this.props.post; var post = this.props.post;
var isOwner = this.props.currentUser.id === post.user_id; var isOwner = this.props.currentUser.id === post.user_id;
var isAdmin = TeamStore.isTeamAdminForCurrentTeam() || UserStore.isSystemAdminForCurrentUser(); var isAdmin = TeamStore.isTeamAdminForCurrentTeam() || UserStore.isSystemAdminForCurrentUser();
const isSystemMessage = post.type.startsWith(Constants.SYSTEM_MESSAGE_PREFIX);
if (post.state === Constants.POST_FAILED || post.state === Constants.POST_LOADING || Utils.isPostEphemeral(post)) { if (post.state === Constants.POST_FAILED || post.state === Constants.POST_LOADING || Utils.isPostEphemeral(post)) {
return ''; return '';
@@ -108,7 +109,7 @@ export default class PostInfo extends React.Component {
); );
} }
if (isOwner) { if (isOwner && !isSystemMessage) {
dropdownContents.push( dropdownContents.push(
<li <li
key='editPost' key='editPost'

Просмотреть файл

@@ -85,6 +85,7 @@ export default class RhsComment extends React.Component {
const isOwner = this.props.currentUser.id === post.user_id; const isOwner = this.props.currentUser.id === post.user_id;
var isAdmin = TeamStore.isTeamAdminForCurrentTeam() || UserStore.isSystemAdminForCurrentUser(); var isAdmin = TeamStore.isTeamAdminForCurrentTeam() || UserStore.isSystemAdminForCurrentUser();
const isSystemMessage = post.type.startsWith(Constants.SYSTEM_MESSAGE_PREFIX);
var dropdownContents = []; var dropdownContents = [];
@@ -107,7 +108,7 @@ export default class RhsComment extends React.Component {
); );
} }
if (isOwner) { if (isOwner && !isSystemMessage) {
dropdownContents.push( dropdownContents.push(
<li <li
role='presentation' role='presentation'

Просмотреть файл

@@ -41,6 +41,7 @@ export default class RhsRootPost extends React.Component {
const user = this.props.user; const user = this.props.user;
var isOwner = this.props.currentUser.id === post.user_id; var isOwner = this.props.currentUser.id === post.user_id;
var isAdmin = TeamStore.isTeamAdminForCurrentTeam() || UserStore.isSystemAdminForCurrentUser(); var isAdmin = TeamStore.isTeamAdminForCurrentTeam() || UserStore.isSystemAdminForCurrentUser();
const isSystemMessage = post.type.startsWith(Constants.SYSTEM_MESSAGE_PREFIX);
var timestamp = UserStore.getProfile(post.user_id).update_at; var timestamp = UserStore.getProfile(post.user_id).update_at;
var channel = ChannelStore.get(post.channel_id); var channel = ChannelStore.get(post.channel_id);
@@ -94,7 +95,7 @@ export default class RhsRootPost extends React.Component {
); );
} }
if (isOwner) { if (isOwner && !isSystemMessage) {
dropdownContents.push( dropdownContents.push(
<li <li
key='rhs-root-edit' key='rhs-root-edit'

Просмотреть файл

@@ -6,6 +6,7 @@ import SpinnerButton from '../components/spinner_button.jsx';
import React from 'react'; import React from 'react';
describe('SpinnerButton', function() { describe('SpinnerButton', function() {
this.timeout(10000);
jsdom(); jsdom();
it('check props', function() { it('check props', function() {