Skip to content
This repository was archived by the owner on Nov 15, 2024. It is now read-only.

Commit dd529a2

Browse files
authored
NR-270545 Not possible to make a post when 'ShowGrok' feature is off (#448)
- Mostly fix formatting to match existing formatting style - Only real code change is `this.useId = existingPost.id;` in post_post_request.js
1 parent 3bd3752 commit dd529a2

File tree

2 files changed

+51
-50
lines changed

2 files changed

+51
-50
lines changed

api_server/modules/posts/post_creator.js

Lines changed: 49 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -168,57 +168,58 @@ class PostCreator extends ModelCreator {
168168
// creating a code error
169169
this.creatingCodeError = true;
170170
} else if (this.attributes.errorGuid) { // New style where we just associate NR error via error entity guid
171-
this.request.log("errorGuid in request - looking up existing post");
172-
let existingPost = await this.data.posts.getOneByQuery(
173-
{ errorGuid: this.attributes.errorGuid, deactivated: false },
174-
{ hint: PostIndexes.byErrorGuid }
171+
this.request.log('errorGuid in request - looking up existing post');
172+
let existingPost = await this.data.posts.getOneByQuery(
173+
{ errorGuid: this.attributes.errorGuid, deactivated: false },
174+
{ hint: PostIndexes.byErrorGuid }
175+
);
176+
if (!existingPost) {
177+
// Check for a legacy codeError
178+
this.request.log('looking for a legacy codeError');
179+
const legacyCodeError = await this.data.codeErrors.getOneByQuery(
180+
{ objectId: this.attributes.errorGuid, deactivated: false },
181+
{ hint: CodeErrorIndexes.byObjectId}
175182
);
176-
if (!existingPost) {
177-
// Check for a legacy codeError
178-
this.request.log("looking for a legacy codeError");
179-
const legacyCodeError = await this.data.codeErrors.getOneByQuery(
180-
{ objectId: this.attributes.errorGuid, deactivated: false },
181-
{ hint: CodeErrorIndexes.byObjectId}
182-
);
183-
if (legacyCodeError) {
184-
this.request.log("found a legacy codeError");
185-
// need to update the post with the errorGuid and not create a stream (suppressSave will get set later based on existingPost)
186-
const legacyPostId = legacyCodeError.get('postId');
187-
const legacyPost = await this.data.posts.getById(legacyPostId);
188-
if (legacyPost.get('deactivated') !== true) {
189-
legacyPost.attributes.errorGuid = this.attributes.errorGuid;
190-
// legacyPost.set('errorGuid', this.attributes.errorGuid);
191-
const op = {
192-
$set: {
193-
errorGuid: this.attributes.errorGuid,
194-
modifiedAt: Date.now()
195-
}
196-
};
197-
this.transforms.postUpdate = await new ModelSaver({
198-
request: this.request,
199-
collection: this.data.posts,
200-
id: legacyPostId
201-
}).save(op);
202-
this.request.log(
203-
`updated post ${legacyPostId} with errorGuid ${this.attributes.errorGuid} for legacy codeError ${legacyCodeError.get('id')}`
204-
);
205-
existingPost = legacyPost;
206-
} else {
207-
this.request.log(`skipping deactivated legacy post ${legacyPostId}`);
208-
}
183+
if (legacyCodeError) {
184+
this.request.log('found a legacy codeError');
185+
// need to update the post with the errorGuid and not create a stream (suppressSave will get set later based on existingPost)
186+
const legacyPostId = legacyCodeError.get('postId');
187+
const legacyPost = await this.data.posts.getById(legacyPostId);
188+
if (legacyPost.get('deactivated') !== true) {
189+
legacyPost.attributes.errorGuid = this.attributes.errorGuid;
190+
// legacyPost.set('errorGuid', this.attributes.errorGuid);
191+
const op = {
192+
$set: {
193+
errorGuid: this.attributes.errorGuid,
194+
modifiedAt: Date.now()
195+
}
196+
};
197+
this.transforms.postUpdate = await new ModelSaver({
198+
request: this.request,
199+
collection: this.data.posts,
200+
id: legacyPostId
201+
}).save(op);
202+
this.request.log(
203+
`updated post ${legacyPostId} with errorGuid ${this.attributes.errorGuid} for legacy codeError ${legacyCodeError.get('id')}`
204+
);
205+
existingPost = legacyPost;
206+
} else {
207+
this.request.log(`skipping deactivated legacy post ${legacyPostId}`);
209208
}
210209
}
211-
if (existingPost) {
212-
this.request.log(`errorGuid in request - found post, suppressing save, attributes: ${JSON.stringify(existingPost.attributes)}`);
213-
this.suppressSave = true;
214-
this.creatingCodeError = false;
215-
this.attributes = existingPost.attributes;
216-
} else {
217-
this.request.log(`errorGuid in request - did not find post, creating stream with accountId ${this.attributes.accountId}`);
218-
this.creatingCodeError = true;
219-
await this.createStream();
220-
}
221-
} else if (this.attributes.parentPostId) {
210+
}
211+
if (existingPost) {
212+
this.request.log(`errorGuid in request - found post, suppressing save, attributes: ${JSON.stringify(existingPost.attributes)}`);
213+
this.suppressSave = true;
214+
this.useId = existingPost.id;
215+
this.creatingCodeError = false;
216+
this.attributes = existingPost.attributes;
217+
} else {
218+
this.request.log(`errorGuid in request - did not find post, creating stream with accountId ${this.attributes.accountId}`);
219+
this.creatingCodeError = true;
220+
await this.createStream();
221+
}
222+
} else if (this.attributes.parentPostId) {
222223
// is the parent a code error?
223224
this.parentPost = await this.data.posts.getById(this.attributes.parentPostId);
224225
if (!this.parentPost) {

api_server/modules/posts/post_post_request.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
'use strict';
44

5-
const GrokClient = require("../../lib/grok/grok_client");
5+
const GrokClient = require('../../lib/grok/grok_client');
66
const PostRequest = require(process.env.CSSVC_BACKEND_ROOT + '/api_server/lib/util/restful/post_request');
77

88
class PostPostRequest extends PostRequest {
@@ -53,7 +53,7 @@ class PostPostRequest extends PostRequest {
5353
}
5454

5555
const post = await this.data.posts.getById(this.request.body.parentPostId);
56-
this.log("PostPostRequest - handleResponse - reinitializeGrok - looking up codeError");
56+
this.log('PostPostRequest - handleResponse - reinitializeGrok - looking up codeError');
5757
const codeError = await this.data.codeErrors.getById(post.get('codeErrorId'));
5858

5959
// When we force a reinitialization on a Code Error with Grok, we need to return

0 commit comments

Comments
 (0)