Mercurial > hg > orthanc
comparison OrthancServer/ServerIndex.cpp @ 272:337c506461d2
protection from rest api
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 07 Dec 2012 18:21:04 +0100 |
parents | e6a4c4329481 |
children | d384af918264 |
comparison
equal
deleted
inserted
replaced
271:98d78841066a | 272:337c506461d2 |
---|---|
866 } | 866 } |
867 | 867 |
868 StandaloneRecycling(); | 868 StandaloneRecycling(); |
869 } | 869 } |
870 | 870 |
871 void ServerIndex::StandaloneRecycling() | 871 void ServerIndex::StandaloneRecycling() |
872 { | 872 { |
873 // WARNING: No mutex here, do not include this as a public method | 873 // WARNING: No mutex here, do not include this as a public method |
874 std::auto_ptr<SQLite::Transaction> t(db_->StartTransaction()); | 874 std::auto_ptr<SQLite::Transaction> t(db_->StartTransaction()); |
875 t->Begin(); | 875 t->Begin(); |
876 Recycle(0, ""); | 876 Recycle(0, ""); |
877 t->Commit(); | 877 t->Commit(); |
878 listener_->CommitFilesToRemove(); | 878 listener_->CommitFilesToRemove(); |
879 } | 879 } |
880 | |
881 | |
882 bool ServerIndex::IsProtectedPatient(const std::string& publicId) | |
883 { | |
884 boost::mutex::scoped_lock lock(mutex_); | |
885 | |
886 // Lookup for the requested resource | |
887 int64_t id; | |
888 ResourceType type; | |
889 if (!db_->LookupResource(publicId, id, type) || | |
890 type != ResourceType_Patient) | |
891 { | |
892 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
893 } | |
894 | |
895 return db_->IsProtectedPatient(id); | |
896 } | |
897 | |
898 | |
899 void ServerIndex::SetProtectedPatient(const std::string& publicId, | |
900 bool isProtected) | |
901 { | |
902 boost::mutex::scoped_lock lock(mutex_); | |
903 | |
904 // Lookup for the requested resource | |
905 int64_t id; | |
906 ResourceType type; | |
907 if (!db_->LookupResource(publicId, id, type) || | |
908 type != ResourceType_Patient) | |
909 { | |
910 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
911 } | |
912 | |
913 // No need for a SQLite::Transaction here, as we only make 1 write to the DB | |
914 db_->SetProtectedPatient(id, isProtected); | |
915 | |
916 if (isProtected) | |
917 LOG(INFO) << "Patient " << publicId << " has been protected"; | |
918 else | |
919 LOG(INFO) << "Patient " << publicId << " has been unprotected"; | |
920 } | |
921 | |
880 } | 922 } |