@@ -86,6 +86,52 @@ def get(project_id):
8686 return {"message" : str (err )}, HTTPStatus .BAD_REQUEST
8787
8888
89+ @cors_preflight ("GET, OPTIONS" )
90+ @API .route ("/project/<string:project_id>/available" , methods = ["GET" , "OPTIONS" ])
91+ class AvailableDocumentsResource (Resource ):
92+ """Resource for fetching inactive (available to add) documents for a project."""
93+
94+ @staticmethod
95+ @ApiHelper .swagger_decorators (API , endpoint_description = "Get available documents for a project" )
96+ @API .response (code = HTTPStatus .OK , model = document_model , description = "Get available documents" )
97+ @API .response (HTTPStatus .BAD_REQUEST , "Bad Request" )
98+ @auth .has_one_of_roles ([EpicConditionRole .VIEW_CONDITIONS .value ])
99+ @cross_origin (origins = allowedorigins ())
100+ def get (project_id ):
101+ """Fetch inactive documents for a project that can be added."""
102+ try :
103+ documents = DocumentService .get_available_documents (project_id )
104+ return DocumentSchema (many = True ).dump (documents ), HTTPStatus .OK
105+ except ValidationError as err :
106+ return {"message" : str (err )}, HTTPStatus .BAD_REQUEST
107+
108+
109+ @cors_preflight ("PATCH, OPTIONS" )
110+ @API .route ("/<string:document_id>/activate" , methods = ["PATCH" , "OPTIONS" ])
111+ class ActivateDocumentResource (Resource ):
112+ """Resource for activating a document."""
113+
114+ @staticmethod
115+ @ApiHelper .swagger_decorators (API , endpoint_description = "Activate a document" )
116+ @API .response (code = HTTPStatus .OK , model = document_model , description = "Activate document" )
117+ @API .response (HTTPStatus .BAD_REQUEST , "Bad Request" )
118+ @auth .has_one_of_roles ([EpicConditionRole .VIEW_CONDITIONS .value ])
119+ @cross_origin (origins = allowedorigins ())
120+ def patch (document_id ):
121+ """Activate a document to make it visible."""
122+ try :
123+ document = DocumentService .activate_document (document_id )
124+ if not document :
125+ return {"message" : "Document not found" }, HTTPStatus .NOT_FOUND
126+ return DocumentSchema ().dump ({
127+ "document_id" : document .document_id ,
128+ "document_label" : document .document_label ,
129+ "is_active" : document .is_active ,
130+ }), HTTPStatus .OK
131+ except ValidationError as err :
132+ return {"message" : str (err )}, HTTPStatus .BAD_REQUEST
133+
134+
89135@cors_preflight ("GET, OPTIONS" )
90136@API .route ("/type" , methods = ["GET" , "OPTIONS" ])
91137class DocumentTypeResource (Resource ):
0 commit comments