Skip to content

Commit

Permalink
fix(group): Display note created on newly created group
Browse files Browse the repository at this point in the history
wallix/datapeps.com#386
  • Loading branch information
franxois committed Jun 7, 2019
1 parent 3f6da6e commit d9e3340
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 27 deletions.
29 changes: 19 additions & 10 deletions client/cypress/integration/1-add-new-note_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ describe(`Notes creation ${seed}`, function() {
});

describe(`Notes sharing ${seed}`, function() {
it(`alice.${seed} share a new note, extends share`, function() {
it(`alice.${seed} share a new note`, function() {
cy.visit("/");

cy.login(`alice.${seed}`, password);
Expand Down Expand Up @@ -188,6 +188,7 @@ describe(`Notes sharing ${seed}`, function() {

// Force refresh, status of note should change.
// TODO : remove the need to refresh
cy.wait(2000);
cy.get('[data-test="refresh"]').click();
cy.wait(2000);

Expand Down Expand Up @@ -234,15 +235,7 @@ describe(`Sharing with groups ${seed}`, () => {
});

cy.get('[data-test="save"]').click();
cy.contains(group1name).should("exist");
});

it(`alice ${seed} add a note to the group`, () => {
cy.visit("/");
cy.login(username, password);
// Select the group
cy.contains(group1name).click();
// Create notes

for (let note of notes) {
cy.contains("button", "New Note", {
Expand All @@ -261,6 +254,20 @@ describe(`Sharing with groups ${seed}`, () => {
}
});

it(`alice ${seed} access to the group`, () => {
cy.visit("/");
cy.login(username, password);
// Select the group
cy.contains(group1name).click();
// Create notes

for (let note of notes) {
cy.contains(".panel-body", note.content, { timeout: 30000 }).should(
"exist"
);
}
});

it(`bob ${seed} access to the group`, () => {
cy.visit("/");
cy.login(`bob.${seed}`, password);
Expand Down Expand Up @@ -358,7 +365,9 @@ describe(`Sharing with groups ${seed}`, () => {

cy.wait(5000);

// Don't see the note
cy.contains(notes[0].content).should("exist");

// Don't see the second note
cy.get(".panel-body").should("not.contain", notes[1].content);
});
});
2 changes: 1 addition & 1 deletion client/src/actions/notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function postNote(note, users, groupID) {
const response = await notesService.postNote(note, groupID, users);
note.ID = response.noteID;
await notesService.shareNote(note, users);
const newNote = await notesService.getNote(note.ID);
const newNote = await notesService.getNote(note.ID, groupID);
dispatch(success(newNote));
} catch (error) {
dispatch(failure(error));
Expand Down
28 changes: 14 additions & 14 deletions client/src/components/NoteLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,22 @@ export const NoteLayout = ({
{Content}
{Error && <Alert bsStyle="danger">{Error}</Alert>}
</Panel.Body>
<Panel.Footer className="text-right">
<ButtonGroup>
{group != null ? null : (
<Button onClick={openShareModal} data-test="share">
<Glyphicon
className={Users && Users.length > 1 ? "shared" : "notshared"}
glyph="share"
/>
</Button>
)}
{DeletedAt || (
{DeletedAt || (
<Panel.Footer className="text-right">
<ButtonGroup>
{group != null ? null : (
<Button onClick={openShareModal} data-test="share">
<Glyphicon
className={Users && Users.length > 1 ? "shared" : "notshared"}
glyph="share"
/>
</Button>
)}
<Button bsStyle={style} onClick={() => deleteNote(ID)}>
<Glyphicon glyph="trash" />
</Button>
)}
</ButtonGroup>
</Panel.Footer>
</ButtonGroup>
</Panel.Footer>
)}
</Panel>
);
6 changes: 4 additions & 2 deletions client/src/services/notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ export async function postNote(note, groupID, users) {
return handleResponse(response);
}

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

const response = await fetch(
`${process.env.REACT_APP_API_URL}/auth/notes/${id}`,
`${process.env.REACT_APP_API_URL}/auth${
groupID !== undefined ? `/group/${groupID}` : ""
}/notes/${id}`,
requestOptions
);
const { note } = await handleResponse(response);
Expand Down
1 change: 1 addition & 0 deletions server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func (e *Env) httpEngine() *gin.Engine {
group.PATCH("", e.groupEditHandler)
group.GET("/notes", e.noteGroupListHandler)
group.POST("/notes", e.noteGroupPostHandler)
group.GET("/notes/:noteId", e.noteGroupGetHandler)
group.DELETE("/notes/:noteId", e.noteGroupDeleteHandler)
}

Expand Down
10 changes: 10 additions & 0 deletions server/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,16 @@ func TestGroup(t *testing.T) {
if note0["Title"].(string) != "this is title group" {
t.Fatalf("First note has wrong title: %v", note0["Title"].(string))
}
// Test get of 1 note
// get notes and check length
result, err = getJSON(t, fmt.Sprintf("/auth/group/%v/notes/%v", groupID, note0["ID"]), token1, 200)
if err != nil {
t.Fatalf("Non-expected error: %v", err)
}
newNote0 := result["note"].(map[string]interface{})
if note0["CreatedAt"] != newNote0["CreatedAt"] {
t.Fatalf("Group note is different than before")
}
// user2 can access group 2, not user 3
_, err = getJSON(t, fmt.Sprintf("/auth/group/%v/notes", sharedGroupID), token2, 200)
if err != nil {
Expand Down
18 changes: 18 additions & 0 deletions server/notes.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,24 @@ func (e *Env) noteGroupPostHandler(c *gin.Context) {
})
}

func (e *Env) noteGroupGetHandler(c *gin.Context) {
var group Group
var note Note
groupID := c.Param("id")
noteID := c.Param("noteId")
err := e.db.First(&group, groupID).Error
if err != nil {
c.JSON(http.StatusUnauthorized, gin.H{"err": err})
return
}
err = e.db.Model(&group).Where("notes.id = ?", noteID).Related(&note, "Notes").Error
if err != nil {
c.JSON(http.StatusUnauthorized, gin.H{"err": err})
return
}
c.JSON(http.StatusOK, gin.H{"note": note})
}

func (e *Env) noteGroupListHandler(c *gin.Context) {
var group Group
var notes []Note
Expand Down

0 comments on commit d9e3340

Please sign in to comment.