Skip to content

Commit

Permalink
Merge pull request #17 from wallix/fix/new-note-shared-385
Browse files Browse the repository at this point in the history
fix(share): New note appears as shared immediatly after create
  • Loading branch information
BourgerieQuentin authored Jun 12, 2019
2 parents e7dd6c3 + 6ab578f commit a7f2048
Show file tree
Hide file tree
Showing 14 changed files with 301 additions and 112 deletions.
39 changes: 21 additions & 18 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 @@ -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 Expand Up @@ -186,11 +186,6 @@ describe(`Notes sharing ${seed}`, function() {
cy.contains("Save").click();
cy.contains("Save").should("not.exist");

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

// Click on shared button
cy.contains("div.panel-body", encryptedSharedContent, { timeout: 20000 })
.parentsUntil("li")
Expand Down Expand Up @@ -234,15 +229,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 +248,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 +359,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);
});
});
23 changes: 22 additions & 1 deletion client/src/actions/notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,25 @@ function addNote(Title, Content, sharedIds) {
};
}

function shareNote(note, sharers) {
return async dispatch => {
try {
await notesService.shareNote(note, sharers);
const newNote = await notesService.getNote(note.ID);
dispatch(success(newNote));
} catch (error) {
dispatch(failure(error));
}
dispatch(uiActions.closeModal(uiConstants.ShareNoteModal));
};
function success(note) {
return { type: notesConstants.SHARE_SUCCESS, note };
}
function failure(error) {
return { type: notesConstants.SHARE_FAILURE, error };
}
}

function deleteNote(id) {
return async (dispatch, getState) => {
let del = {
Expand Down Expand Up @@ -50,7 +69,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, groupID);
dispatch(success(newNote));
} catch (error) {
dispatch(failure(error));
}
Expand Down Expand Up @@ -107,6 +127,7 @@ function getNotes(group) {

export const noteActions = {
addNote,
shareNote,
deleteNote,
getNotes
};
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>
);
4 changes: 1 addition & 3 deletions client/src/components/ShareNote.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import ShareSelect from "./ShareSelect";

import { uiConstants } from "../constants";
import { noteActions, uiActions } from "../actions";
import { notesService } from "../services";

class ShareNote extends React.Component {
constructor(props, context) {
Expand Down Expand Up @@ -86,8 +85,7 @@ class ShareNote extends React.Component {
const {
payload: { note }
} = this.props;
await notesService.shareNote(note, this.state.sharingList);
this.props.closeModal(uiConstants.ShareNoteModal);
this.props.shareNote(note, this.state.sharingList);
} catch (e) {
console.log(e);
}
Expand Down
2 changes: 2 additions & 0 deletions client/src/constants/notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export const notesConstants = {
POST_REQUEST: "NOTES_POST_REQUEST",
POST_SUCCESS: "NOTES_POST_SUCCESS",
POST_FAILURE: "NOTES_POST_FAILURE",
SHARE_SUCCESS: "NOTES_SHARE_SUCCESS",
SHARE_FAILURE: "NOTES_SHARE_FAILURE",
DEL_FAILURE: "NOTES_DEL_FAILURE",
GET_USERS_LIST: "NOTES_GET_USERS"
};
2 changes: 2 additions & 0 deletions client/src/reducers/notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ export const notes = (state = [], action) => {
switch (action.type) {
case notesConstants.POST_SUCCESS:
return [...state, action.note];
case notesConstants.SHARE_SUCCESS:
return state.map(n => (n.ID === action.note.ID ? action.note : n));
case notesConstants.DELETE_NOTE:
return state.map(note =>
note.ID === action.id
Expand Down
40 changes: 29 additions & 11 deletions client/src/services/notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,22 @@ export async function postNote(note, groupID, users) {
return handleResponse(response);
}

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

const response = await fetch(
`${process.env.REACT_APP_API_URL}/auth${
groupID !== undefined ? `/group/${groupID}` : ""
}/notes/${id}`,
requestOptions
);
const { note } = await handleResponse(response);
return await decryptNote(note);
}

export async function getNotes() {
const requestOptions = {
method: "GET",
Expand Down Expand Up @@ -92,17 +108,19 @@ export async function shareNote(note, sharingList) {
note.resourceID,
sharingList.map(u => getLogin(u, process.env.REACT_APP_DATAPEPS_APP_ID))
);
await sharingList.map(u => {
const requestOptions = {
method: "POST",
headers: authHeader(false)
};

return fetch(
`${process.env.REACT_APP_API_URL}/auth/share/${note.ID}/${u}`,
requestOptions
);
});
await Promise.all(
sharingList.map(async u => {
const requestOptions = {
method: "POST",
headers: authHeader(false)
};

return await fetch(
`${process.env.REACT_APP_API_URL}/auth/share/${note.ID}/${u}`,
requestOptions
);
})
);
}

async function handleNotesResponse(response) {
Expand Down
21 changes: 7 additions & 14 deletions server/go.mod
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
module github.com/wallix/notes/server

go 1.12

require (
github.com/appleboy/gin-jwt v0.0.0-20190107105648-22ee6b104c71
github.com/gin-contrib/cors v0.0.0-20190101123304-5e7acb10687f
github.com/gin-gonic/gin v1.3.0
github.com/jinzhu/gorm v1.9.2
github.com/jinzhu/inflection v0.0.0-20180308033659-04140366298a // indirect
github.com/kr/pty v1.1.3 // indirect
github.com/mattn/go-sqlite3 v1.10.0 // indirect
github.com/stretchr/objx v0.1.1 // indirect
github.com/stretchr/testify v1.3.0 // indirect
github.com/tidwall/gjson v1.1.4 // indirect
github.com/tidwall/match v1.0.1 // indirect
github.com/ugorji/go v1.1.2-0.20181209151446-772ced7fd4c2 // indirect
golang.org/x/net v0.0.0-20190110200230-915654e7eabc // indirect
golang.org/x/sys v0.0.0-20190109145017-48ac38b7c8cb // indirect
github.com/appleboy/gin-jwt/v2 v2.6.2
github.com/gin-contrib/cors v1.3.0
github.com/gin-gonic/gin v1.4.0
github.com/jinzhu/gorm v1.9.8
gopkg.in/dgrijalva/jwt-go.v3 v3.2.0 // indirect
)
Loading

0 comments on commit a7f2048

Please sign in to comment.