Exemple #1
0
        public ActionResult EditNote(Guid noteId, string text, bool?isShared)
        {
            try
            {
                var employer = CurrentEmployer;

                // Get the note.

                var note = _candidateNotesQuery.GetNote(employer, noteId);
                if (note == null)
                {
                    return(JsonNotFound("note"));
                }

                // Update the text.

                if (text != null && text != note.Text)
                {
                    note.Text = text;
                    _candidateNotesCommand.UpdateNote(employer, note);
                }

                // Updated the shared status.

                if (isShared != null)
                {
                    if (isShared.Value)
                    {
                        _candidateNotesCommand.ShareNote(employer, note);
                    }
                    else
                    {
                        _candidateNotesCommand.UnshareNote(employer, note);
                    }
                }

                return(Json(new JsonNoteModel
                {
                    Note = new NoteModel
                    {
                        Id = note.Id,
                        Text = text,
                        IsShared = isShared == null ? note.IsShared : isShared.Value,
                        UpdatedTime = note.UpdatedTime,
                        CreatedBy = note.RecruiterId == employer.Id ? null : _employersQuery.GetEmployer(note.RecruiterId).FullName,
                        CanUpdate = _candidateNotesCommand.CanUpdateNote(employer, note),
                        CanDelete = _candidateNotesCommand.CanDeleteNote(employer, note),
                    }
                }));
            }
            catch (UserException ex)
            {
                ModelState.AddModelError(ex, new StandardErrorHandler());
            }

            return(Json(new JsonResponseModel()));
        }
        public void TestOrganisationSharedNotes()
        {
            var member      = _membersCommand.CreateTestMember(1);
            var noteCreator = _employersCommand.CreateTestEmployer(1, _organisationsCommand.CreateTestOrganisation(1));

            var organisation = noteCreator.Organisation;
            var noteReader   = _employersCommand.CreateTestEmployer(2, organisation);

            // Create a private and a shared.

            var note1 = CreateNote(1, noteCreator, member.Id, false);

            NoteCreationDelay();
            var note2 = CreateNote(2, noteCreator, member.Id, true);

            AssertNotes(noteCreator, member.Id, new[] { note2, note1 }, new CandidateNote[0]);
            AssertNotes(noteReader, member.Id, new[] { note2 }, new[] { note1 });
            AssertHasNotes(noteCreator, member.Id);
            AssertHasNotes(noteReader, member.Id);

            // The creator leaves the company, so they cannot access their own shared notes.

            var otherOrganisation = new Organisation {
                Name = "OtherOrganisation"
            };

            _organisationsCommand.CreateOrganisation(otherOrganisation);

            noteCreator.Organisation = otherOrganisation;
            _employersCommand.UpdateEmployer(noteCreator);

            AssertNotes(noteCreator, member.Id, new[] { note1 }, new[] { note2 });
            AssertNotes(noteReader, member.Id, new[] { note2 }, new[] { note1 });
            AssertHasNotes(noteCreator, member.Id);
            AssertHasNotes(noteReader, member.Id);

            // Create a private while not part of the company.

            var note3 = CreateNote(3, noteCreator, member.Id, false);

            AssertNotes(noteCreator, member.Id, new[] { note3, note1 }, new[] { note2 });
            AssertNotes(noteReader, member.Id, new[] { note2 }, new[] { note3, note1 });
            AssertHasNotes(noteCreator, member.Id);
            AssertHasNotes(noteReader, member.Id);

            // Join again so can see original notes.

            noteCreator.Organisation = organisation;
            _employersCommand.UpdateEmployer(noteCreator);

            AssertNotes(noteCreator, member.Id, new[] { note3, note2, note1 }, new CandidateNote[0]);
            AssertNotes(noteReader, member.Id, new[] { note2 }, new[] { note3, note1 });
            AssertHasNotes(noteCreator, member.Id);
            AssertHasNotes(noteReader, member.Id);

            // Change the latest to shared, so now the second employer can see it.

            _candidateNotesCommand.ShareNote(noteCreator, note3);

            AssertNotes(noteCreator, member.Id, new[] { note3, note2, note1 }, new CandidateNote[0]);
            AssertNotes(noteReader, member.Id, new[] { note3, note2 }, new[] { note1 });
            AssertHasNotes(noteCreator, member.Id);
            AssertHasNotes(noteReader, member.Id);

            // Make that one private once again.

            _candidateNotesCommand.UnshareNote(noteCreator, note3);

            AssertNotes(noteCreator, member.Id, new[] { note3, note2, note1 }, new CandidateNote[0]);
            AssertNotes(noteReader, member.Id, new[] { note2 }, new[] { note3, note1 });
            AssertHasNotes(noteCreator, member.Id);
            AssertHasNotes(noteReader, member.Id);
        }