changeset 582:0b9af8de016f annotations

reorganization
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 03 Sep 2026 16:38:12 +0200
parents 921f79004d81
children 4e722446aca7
files ViewerPlugin/Annotations/AnnotationsRestApi.cpp ViewerPlugin/Annotations/AnnotationsWorkspace.cpp ViewerPlugin/Annotations/AnnotationsWorkspace.h ViewerPlugin/Annotations/CachedAnnotationsWorkspace.cpp ViewerPlugin/Annotations/CachedAnnotationsWorkspace.h ViewerPlugin/Annotations/CachedUserFeatures.cpp ViewerPlugin/Annotations/CachedUserFeatures.h ViewerPlugin/Annotations/IAuthenticatedUser.cpp ViewerPlugin/WebApplication/viewer.js
diffstat 9 files changed, 101 insertions(+), 74 deletions(-) [+]
line wrap: on
line diff
--- 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<UserId> users;
-      context.GetWorkspace().ListUsersSharingLayerWith(users, context.GetUser().GetAnnotatingId());
+
+      {
+        std::unique_ptr<AnnotationsWorkspace::UserReader> 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<AnnotationsWorkspace::UserReader> reader(context.CreateUserReader());
-        reader->ListLayersSharedWith(answer, context.GetUser().GetAnnotatingId());
+        reader->ListLayersSharedWithMe(answer, author);
       }
 
       ViewerToolbox::AnswerJson(output, answer);
@@ -546,8 +551,8 @@
       OrthancPlugins::RegisterRestCallback<OrthancWSI::SearchActiveUsers>("/wsi/api/search-active-users", true);
 
       OrthancPlugins::RegisterRestCallback<OrthancWSI::ImportLayer>("/wsi/api/import-layer", true);
-      OrthancPlugins::RegisterRestCallback<OrthancWSI::ListLayersSharedByUser>("/wsi/api/list-shared-layers", true);
-      OrthancPlugins::RegisterRestCallback<OrthancWSI::ListUsersSharingLayers>("/wsi/api/list-sharing-users", true);
+      OrthancPlugins::RegisterRestCallback<OrthancWSI::ListLayersSharedWithMe>("/wsi/api/list-shared-layers", true);
+      OrthancPlugins::RegisterRestCallback<OrthancWSI::ListUsersSharingLayersWithMe>("/wsi/api/list-sharing-users", true);
       OrthancPlugins::RegisterRestCallback<OrthancWSI::RemoveImportedLayer>("/wsi/api/remove-imported-layer", true);
       OrthancPlugins::RegisterRestCallback<OrthancWSI::SaveImportedLayer>("/wsi/api/save-imported-layer", true);
 
--- 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<UserId>& 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<const UserLayer&>(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<UserId>& 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<const UserLayer&>(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<const UserLayer&>(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<const UserLayer&>(iterator.GetLayer());
+
+          if (layer.IsSharedWith(userId_))
+          {
+            Json::Value item;
+            layer.Serialize(item);
+            target.append(item);
+          }
+
+          iterator.Next();
         }
-
-        iterator.Next();
       }
     }
   }
--- 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<UserId>& target,
                            const std::string& query);
 
-    void ListUsersSharingLayerWith(std::set<UserId>& 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<UserId>& target) const;
+
+      void ListLayersSharedWithMe(Json::Value& target,
+                                  const UserId& author) const;
 
       void ListImportedLayers(std::set<UserId>& authors,
                               std::set<std::string>& layerIds) const;
--- 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 <Cache/SharedObjectCache.h>
-
 
 namespace OrthancWSI
 {
-  static Orthanc::SharedObjectCache& GetCache()
+  Orthanc::SharedObjectCache& CachedAnnotationsWorkspace::GetCache()
   {
     static boost::mutex  mutex;
     static std::unique_ptr<Orthanc::SharedObjectCache>  cache;
--- 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 <Cache/SharedObjectCache.h>
+
 #include <boost/shared_ptr.hpp>
 
 
@@ -33,6 +35,8 @@
   class CachedAnnotationsWorkspace : public boost::noncopyable
   {
   private:
+    static Orthanc::SharedObjectCache& GetCache();
+
     boost::shared_ptr<Orthanc::IDynamicObject>  cached_;
 
   public:
--- 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 <Cache/SharedObjectCache.h>
-
 
 namespace OrthancWSI
 {
-  static Orthanc::SharedObjectCache& GetCache()
+  Orthanc::SharedObjectCache& CachedUserFeatures::GetCache()
   {
     static boost::mutex  mutex;
     static std::unique_ptr<Orthanc::SharedObjectCache>  cache;
--- 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 <Cache/SharedObjectCache.h>
+
 #include <boost/shared_ptr.hpp>
 
 
@@ -34,6 +36,8 @@
   class CachedUserFeatures : public boost::noncopyable
   {
   private:
+    static Orthanc::SharedObjectCache& GetCache();
+
     boost::shared_ptr<Orthanc::IDynamicObject>  cached_;
 
   public:
--- 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
         }
       }
     }
--- 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;
         })