Skip to content

Commit

Permalink
fix(share): New note appears as shared immediatly after create
Browse files Browse the repository at this point in the history
wallix/datapeps.com#385
  • Loading branch information
franxois committed Jun 6, 2019
1 parent e7dd6c3 commit 3f6da6e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
6 changes: 3 additions & 3 deletions client/cypress/integration/1-add-new-note_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ describe(`Notes sharing ${seed}`, function() {
);

// New note should appear and use .shared css class
cy.contains("div.panel-body", encryptedSharedContent, {
timeout: 20000
}).should("exist");
cy.contains("div.panel-body", encryptedSharedContent, { timeout: 20000 })
.parentsUntil("li")
.find(".shared");
});

it(`charlie.${seed} find his notes`, function() {
Expand Down
3 changes: 2 additions & 1 deletion client/src/actions/notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ function postNote(note, users, groupID) {
const response = await notesService.postNote(note, groupID, users);
note.ID = response.noteID;
await notesService.shareNote(note, users);
dispatch(success(note));
const newNote = await notesService.getNote(note.ID);
dispatch(success(newNote));
} catch (error) {
dispatch(failure(error));
}
Expand Down
14 changes: 14 additions & 0 deletions client/src/services/notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@ export async function postNote(note, groupID, users) {
return handleResponse(response);
}

export async function getNote(id) {
const requestOptions = {
method: "GET",
headers: authHeader(false)
};

const response = await fetch(
`${process.env.REACT_APP_API_URL}/auth/notes/${id}`,
requestOptions
);
const { note } = await handleResponse(response);
return await decryptNote(note);
}

export async function getNotes() {
const requestOptions = {
method: "GET",
Expand Down
2 changes: 1 addition & 1 deletion server/notes.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (e *Env) noteGetHandler(c *gin.Context) {
c.JSON(http.StatusForbidden, gin.H{"err": err})
return
}
err = e.db.Model(&user).Where("note_id = ?", noteID).Related(&note, "Notes").Error
err = e.db.Preload("Users").Model(&user).Where("note_id = ?", noteID).Related(&note, "Notes").Error
if err != nil {
c.JSON(http.StatusForbidden, gin.H{"err": err})
return
Expand Down

0 comments on commit 3f6da6e

Please sign in to comment.