# HG changeset patch # User Sebastien Jodogne # Date 1788446292 -7200 # Node ID 0b9af8de016f52499d3ea55a6c8ab8828ae43170 # Parent 921f79004d81eac8683500d922e294ec66789e9f reorganization diff -r 921f79004d81 -r 0b9af8de016f ViewerPlugin/Annotations/AnnotationsRestApi.cpp --- a/ViewerPlugin/Annotations/AnnotationsRestApi.cpp Thu Sep 03 15:33:50 2026 +0200 +++ b/ViewerPlugin/Annotations/AnnotationsRestApi.cpp Thu Sep 03 16:38:12 2026 +0200 @@ -82,6 +82,7 @@ Orthanc::ResourceType level = Orthanc::StringToResourceType(levelString.c_str()); AnnotationsWorkspaceId workspaceId(projectId, level, resourceId, frameNumber); + workspace_.reset(new CachedAnnotationsWorkspace(workspaceId)); } @@ -337,9 +338,9 @@ } - void ListUsersSharingLayers(OrthancPluginRestOutput* output, - const char* url, - const OrthancPluginHttpRequest* request) + void ListUsersSharingLayersWithMe(OrthancPluginRestOutput* output, + const char* url, + const OrthancPluginHttpRequest* request) { if (request->method != OrthancPluginHttpMethod_Post) { @@ -350,7 +351,11 @@ AnnotationsCommandContext context(request); std::set users; - context.GetWorkspace().ListUsersSharingLayerWith(users, context.GetUser().GetAnnotatingId()); + + { + std::unique_ptr reader(context.CreateUserReader()); + reader->ListUsersSharingLayersWithMe(users); + } Json::Value answer = Json::arrayValue; @@ -366,7 +371,7 @@ } - void ListLayersSharedByUser(OrthancPluginRestOutput* output, + void ListLayersSharedWithMe(OrthancPluginRestOutput* output, const char* url, const OrthancPluginHttpRequest* request) { @@ -378,12 +383,12 @@ { AnnotationsCommandContext context(request); - const UserId user(context.GetBodyField("user")); + const UserId author(context.GetBodyField("author")); Json::Value answer; { std::unique_ptr reader(context.CreateUserReader()); - reader->ListLayersSharedWith(answer, context.GetUser().GetAnnotatingId()); + reader->ListLayersSharedWithMe(answer, author); } ViewerToolbox::AnswerJson(output, answer); @@ -546,8 +551,8 @@ OrthancPlugins::RegisterRestCallback("/wsi/api/search-active-users", true); OrthancPlugins::RegisterRestCallback("/wsi/api/import-layer", true); - OrthancPlugins::RegisterRestCallback("/wsi/api/list-shared-layers", true); - OrthancPlugins::RegisterRestCallback("/wsi/api/list-sharing-users", true); + OrthancPlugins::RegisterRestCallback("/wsi/api/list-shared-layers", true); + OrthancPlugins::RegisterRestCallback("/wsi/api/list-sharing-users", true); OrthancPlugins::RegisterRestCallback("/wsi/api/remove-imported-layer", true); OrthancPlugins::RegisterRestCallback("/wsi/api/save-imported-layer", true); diff -r 921f79004d81 -r 0b9af8de016f ViewerPlugin/Annotations/AnnotationsWorkspace.cpp --- a/ViewerPlugin/Annotations/AnnotationsWorkspace.cpp Thu Sep 03 15:33:50 2026 +0200 +++ b/ViewerPlugin/Annotations/AnnotationsWorkspace.cpp Thu Sep 03 16:38:12 2026 +0200 @@ -246,10 +246,12 @@ { persistentInfo_.reset(new PersistentInfo(info)); - PersistentInfo::ActiveUsersIterator it(*persistentInfo_); - while (!it.IsDone()) + PersistentInfo::ActiveUsersIterator iterator(*persistentInfo_); + + while (!iterator.IsDone()) { - Load(it.GetUser()); + Load(iterator.GetUser()); + iterator.Next(); } } else @@ -280,48 +282,16 @@ const boost::regex re(query); - PersistentInfo::ActiveUsersIterator it(*persistentInfo_); - while (!it.IsDone()) - { - if (boost::regex_search(it.GetUser().GetName(), re)) - { - target.insert(it.GetUser()); - } - } - } + PersistentInfo::ActiveUsersIterator iterator(*persistentInfo_); - - void AnnotationsWorkspace::ListUsersSharingLayerWith(std::set& target, - const UserId& user) - { - Orthanc::ReaderWriterLock::ReadLock lock(mutex_); - - target.clear(); - - // Loop over all the users in this workspace - for (Content::const_iterator it = content_.begin(); it != content_.end(); ++it) + while (!iterator.IsDone()) { - assert(it->second != NULL); - if (!user.Equals(it->first)) // Don't add self + if (boost::regex_search(iterator.GetUser().GetName(), re)) { - LayersCollection::Iterator iterator(it->second->GetUserLayers()); - - // Loop over all the user layers in this workspace - while (!iterator.IsDone()) - { - const UserLayer& layer = dynamic_cast(iterator.GetLayer()); + target.insert(iterator.GetUser()); + } - if (layer.IsSharedWith(user)) - { - target.insert(it->first); - break; - } - else - { - iterator.Next(); - } - } - } + iterator.Next(); } } @@ -364,27 +334,66 @@ } - void AnnotationsWorkspace::UserReader::ListLayersSharedWith(Json::Value& target, - const UserId& user) const + void AnnotationsWorkspace::UserReader::ListUsersSharingLayersWithMe(std::set& target) const + { + target.clear(); + + // Loop over all the users in this workspace + for (Content::const_iterator it = that_.content_.begin(); it != that_.content_.end(); ++it) + { + assert(it->second != NULL); + + if (!userId_.Equals(it->first)) // Don't add self + { + LayersCollection::Iterator iterator(it->second->GetUserLayers()); + + // Loop over all the layers of this user in this workspace + while (!iterator.IsDone()) + { + const UserLayer& layer = dynamic_cast(iterator.GetLayer()); + + if (layer.IsSharedWith(userId_)) + { + target.insert(it->first); + break; + } + else + { + iterator.Next(); + } + } + } + } + } + + + void AnnotationsWorkspace::UserReader::ListLayersSharedWithMe(Json::Value& target, + const UserId& author) const { target = Json::arrayValue; if (IsValid()) { - LayersCollection::Iterator iterator(userSettings_->GetUserLayers()); + Content::const_iterator found = that_.content_.find(author); - while (!iterator.IsDone()) + if (found != that_.content_.end()) { - const UserLayer& layer = dynamic_cast(iterator.GetLayer()); + assert(found->second != NULL); + LayersCollection::Iterator iterator(found->second->GetUserLayers()); - if (layer.IsSharedWith(user)) + while (!iterator.IsDone()) { - Json::Value item; - layer.Serialize(item); - target.append(item); + const UserLayer& layer = dynamic_cast(iterator.GetLayer()); + + if (layer.IsSharedWith(userId_)) + { + Json::Value item; + layer.Serialize(item); + target.append(item); + } + + iterator.Next(); } - - iterator.Next(); } } } diff -r 921f79004d81 -r 0b9af8de016f ViewerPlugin/Annotations/AnnotationsWorkspace.h --- a/ViewerPlugin/Annotations/AnnotationsWorkspace.h Thu Sep 03 15:33:50 2026 +0200 +++ b/ViewerPlugin/Annotations/AnnotationsWorkspace.h Thu Sep 03 16:38:12 2026 +0200 @@ -72,9 +72,6 @@ void SearchActiveUsers(std::set& target, const std::string& query); - void ListUsersSharingLayerWith(std::set& target, - const UserId& user); - class UserReader : public boost::noncopyable { @@ -97,8 +94,10 @@ void ListLayers(Json::Value& serialized) const; - void ListLayersSharedWith(Json::Value& target, - const UserId& user) const; + void ListUsersSharingLayersWithMe(std::set& target) const; + + void ListLayersSharedWithMe(Json::Value& target, + const UserId& author) const; void ListImportedLayers(std::set& authors, std::set& layerIds) const; diff -r 921f79004d81 -r 0b9af8de016f ViewerPlugin/Annotations/CachedAnnotationsWorkspace.cpp --- a/ViewerPlugin/Annotations/CachedAnnotationsWorkspace.cpp Thu Sep 03 15:33:50 2026 +0200 +++ b/ViewerPlugin/Annotations/CachedAnnotationsWorkspace.cpp Thu Sep 03 16:38:12 2026 +0200 @@ -26,12 +26,10 @@ #include "../ViewerConfiguration.h" -#include - namespace OrthancWSI { - static Orthanc::SharedObjectCache& GetCache() + Orthanc::SharedObjectCache& CachedAnnotationsWorkspace::GetCache() { static boost::mutex mutex; static std::unique_ptr cache; diff -r 921f79004d81 -r 0b9af8de016f ViewerPlugin/Annotations/CachedAnnotationsWorkspace.h --- a/ViewerPlugin/Annotations/CachedAnnotationsWorkspace.h Thu Sep 03 15:33:50 2026 +0200 +++ b/ViewerPlugin/Annotations/CachedAnnotationsWorkspace.h Thu Sep 03 16:38:12 2026 +0200 @@ -25,6 +25,8 @@ #include "AnnotationsWorkspace.h" +#include + #include @@ -33,6 +35,8 @@ class CachedAnnotationsWorkspace : public boost::noncopyable { private: + static Orthanc::SharedObjectCache& GetCache(); + boost::shared_ptr cached_; public: diff -r 921f79004d81 -r 0b9af8de016f ViewerPlugin/Annotations/CachedUserFeatures.cpp --- a/ViewerPlugin/Annotations/CachedUserFeatures.cpp Thu Sep 03 15:33:50 2026 +0200 +++ b/ViewerPlugin/Annotations/CachedUserFeatures.cpp Thu Sep 03 16:38:12 2026 +0200 @@ -26,12 +26,10 @@ #include "../ViewerConfiguration.h" -#include - namespace OrthancWSI { - static Orthanc::SharedObjectCache& GetCache() + Orthanc::SharedObjectCache& CachedUserFeatures::GetCache() { static boost::mutex mutex; static std::unique_ptr cache; diff -r 921f79004d81 -r 0b9af8de016f ViewerPlugin/Annotations/CachedUserFeatures.h --- a/ViewerPlugin/Annotations/CachedUserFeatures.h Thu Sep 03 15:33:50 2026 +0200 +++ b/ViewerPlugin/Annotations/CachedUserFeatures.h Thu Sep 03 16:38:12 2026 +0200 @@ -26,6 +26,8 @@ #include "AnnotationsWorkspaceId.h" #include "UserFeatures.h" +#include + #include @@ -34,6 +36,8 @@ class CachedUserFeatures : public boost::noncopyable { private: + static Orthanc::SharedObjectCache& GetCache(); + boost::shared_ptr cached_; public: diff -r 921f79004d81 -r 0b9af8de016f ViewerPlugin/Annotations/IAuthenticatedUser.cpp --- a/ViewerPlugin/Annotations/IAuthenticatedUser.cpp Thu Sep 03 15:33:50 2026 +0200 +++ b/ViewerPlugin/Annotations/IAuthenticatedUser.cpp Thu Sep 03 16:38:12 2026 +0200 @@ -264,8 +264,18 @@ } else { +#if 0 // TODO - TEST + if (user == "learner@uclouvain.be") + { + return new GenericStandardUser(ProjectRole_Learner, request->headersValues[i]); + } + else + { + return new GenericStandardUser(ProjectRole_Instructor, request->headersValues[i]); + } +#else return new GenericStandardUser(ProjectRole_Instructor, request->headersValues[i]); - //return new GenericStandardUser(ProjectRole_Learner, request->headersValues[i]); +#endif } } } diff -r 921f79004d81 -r 0b9af8de016f ViewerPlugin/WebApplication/viewer.js --- a/ViewerPlugin/WebApplication/viewer.js Thu Sep 03 15:33:50 2026 +0200 +++ b/ViewerPlugin/WebApplication/viewer.js Thu Sep 03 16:38:12 2026 +0200 @@ -1203,7 +1203,7 @@ var that = this; axios.post('../api/list-shared-layers', - this.CreatePostPayload({ 'user': this.importSelectedUser })) + this.CreatePostPayload({ 'author': this.importSelectedUser })) .then(function(response) { that.importAvailableLayers = response.data; })