Refactoring: endpoint naming unifications

This commit is contained in:
Ivan 2024-07-24 23:45:06 +03:00
parent c438b6ac16
commit 95caab2919
8 changed files with 50 additions and 63 deletions

View File

@ -179,7 +179,7 @@ class TestLibraryViewset(EndpointTester):
self.unowned.refresh_from_db() self.unowned.refresh_from_db()
self.assertEqual(self.unowned.location, data['location']) self.assertEqual(self.unowned.location, data['location'])
@decl_endpoint('/api/library/{item}/editors-add', method='patch') @decl_endpoint('/api/library/{item}/add-editor', method='patch')
def test_add_editor(self): def test_add_editor(self):
time_update = self.owned.time_update time_update = self.owned.time_update
@ -203,7 +203,7 @@ class TestLibraryViewset(EndpointTester):
self.assertEqual(set(self.owned.editors()), set([self.user, self.user2])) self.assertEqual(set(self.owned.editors()), set([self.user, self.user2]))
@decl_endpoint('/api/library/{item}/editors-remove', method='patch') @decl_endpoint('/api/library/{item}/remove-editor', method='patch')
def test_remove_editor(self): def test_remove_editor(self):
time_update = self.owned.time_update time_update = self.owned.time_update
@ -230,7 +230,7 @@ class TestLibraryViewset(EndpointTester):
self.assertEqual(self.owned.editors(), [self.user]) self.assertEqual(self.owned.editors(), [self.user])
@decl_endpoint('/api/library/{item}/editors-set', method='patch') @decl_endpoint('/api/library/{item}/set-editors', method='patch')
def test_set_editors(self): def test_set_editors(self):
time_update = self.owned.time_update time_update = self.owned.time_update

View File

@ -186,7 +186,7 @@ class TestRSFormViewset(EndpointTester):
self.assertIn('document.json', zipped_file.namelist()) self.assertIn('document.json', zipped_file.namelist())
@decl_endpoint('/api/rsforms/{item}/cst-create', method='post') @decl_endpoint('/api/rsforms/{item}/create-cst', method='post')
def test_create_constituenta(self): def test_create_constituenta(self):
data = {'alias': 'X3'} data = {'alias': 'X3'}
self.executeForbidden(data=data, item=self.unowned_id) self.executeForbidden(data=data, item=self.unowned_id)
@ -229,7 +229,7 @@ class TestRSFormViewset(EndpointTester):
self.assertEqual(response.data['new_cst']['alias'], data['alias']) self.assertEqual(response.data['new_cst']['alias'], data['alias'])
@decl_endpoint('/api/rsforms/{item}/cst-rename', method='patch') @decl_endpoint('/api/rsforms/{item}/rename-cst', method='patch')
def test_rename_constituenta(self): def test_rename_constituenta(self):
x1 = self.owned.insert_new( x1 = self.owned.insert_new(
alias='X1', alias='X1',
@ -279,7 +279,7 @@ class TestRSFormViewset(EndpointTester):
self.assertEqual(x1.cst_type, CstType.TERM) self.assertEqual(x1.cst_type, CstType.TERM)
@decl_endpoint('/api/rsforms/{item}/cst-substitute', method='patch') @decl_endpoint('/api/rsforms/{item}/substitute', method='patch')
def test_substitute_single(self): def test_substitute_single(self):
x1 = self.owned.insert_new( x1 = self.owned.insert_new(
alias='X1', alias='X1',
@ -316,7 +316,7 @@ class TestRSFormViewset(EndpointTester):
self.assertEqual(d1.term_resolved, 'form1') self.assertEqual(d1.term_resolved, 'form1')
self.assertEqual(d1.definition_formal, 'X2') self.assertEqual(d1.definition_formal, 'X2')
@decl_endpoint('/api/rsforms/{item}/cst-substitute', method='patch') @decl_endpoint('/api/rsforms/{item}/substitute', method='patch')
def test_substitute_multiple(self): def test_substitute_multiple(self):
self.set_params(item=self.owned_id) self.set_params(item=self.owned_id)
x1 = self.owned.insert_new('X1') x1 = self.owned.insert_new('X1')
@ -362,7 +362,7 @@ class TestRSFormViewset(EndpointTester):
self.assertEqual(d3.definition_formal, r'D1 \ D2') self.assertEqual(d3.definition_formal, r'D1 \ D2')
@decl_endpoint('/api/rsforms/{item}/cst-create', method='post') @decl_endpoint('/api/rsforms/{item}/create-cst', method='post')
def test_create_constituenta_data(self): def test_create_constituenta_data(self):
data = { data = {
'alias': 'X3', 'alias': 'X3',
@ -383,7 +383,7 @@ class TestRSFormViewset(EndpointTester):
self.assertEqual(response.data['new_cst']['definition_resolved'], '4') self.assertEqual(response.data['new_cst']['definition_resolved'], '4')
@decl_endpoint('/api/rsforms/{item}/cst-delete-multiple', method='patch') @decl_endpoint('/api/rsforms/{item}/delete-multiple-cst', method='patch')
def test_delete_constituenta(self): def test_delete_constituenta(self):
self.set_params(item=self.owned_id) self.set_params(item=self.owned_id)
@ -407,7 +407,7 @@ class TestRSFormViewset(EndpointTester):
self.executeBadData(data=data, item=self.owned_id) self.executeBadData(data=data, item=self.owned_id)
@decl_endpoint('/api/rsforms/{item}/cst-moveto', method='patch') @decl_endpoint('/api/rsforms/{item}/move-cst', method='patch')
def test_move_constituenta(self): def test_move_constituenta(self):
self.set_params(item=self.owned_id) self.set_params(item=self.owned_id)
@ -473,7 +473,7 @@ class TestRSFormViewset(EndpointTester):
self.assertFalse(Constituenta.objects.filter(pk=x1.pk).exists()) self.assertFalse(Constituenta.objects.filter(pk=x1.pk).exists())
@decl_endpoint('/api/rsforms/{item}/cst-produce-structure', method='patch') @decl_endpoint('/api/rsforms/{item}/produce-structure', method='patch')
def test_produce_structure(self): def test_produce_structure(self):
self.set_params(item=self.owned_id) self.set_params(item=self.owned_id)
x1 = self.owned.insert_new('X1') x1 = self.owned.insert_new('X1')

View File

@ -49,9 +49,9 @@ class LibraryViewSet(viewsets.ModelViewSet):
'set_owner', 'set_owner',
'set_access_policy', 'set_access_policy',
'set_location', 'set_location',
'editors_add', 'add_editor',
'editors_remove', 'remove_editor',
'editors_set' 'set_editors'
]: ]:
access_level = permissions.ItemOwner access_level = permissions.ItemOwner
elif self.action in [ elif self.action in [
@ -220,8 +220,8 @@ class LibraryViewSet(viewsets.ModelViewSet):
c.HTTP_404_NOT_FOUND: None c.HTTP_404_NOT_FOUND: None
} }
) )
@action(detail=True, methods=['patch'], url_path='editors-add') @action(detail=True, methods=['patch'], url_path='add-editor')
def editors_add(self, request: Request, pk): def add_editor(self, request: Request, pk):
''' Endpoint: Add editor for item. ''' ''' Endpoint: Add editor for item. '''
item = self._get_item() item = self._get_item()
serializer = s.UserTargetSerializer(data=request.data) serializer = s.UserTargetSerializer(data=request.data)
@ -240,8 +240,8 @@ class LibraryViewSet(viewsets.ModelViewSet):
c.HTTP_404_NOT_FOUND: None c.HTTP_404_NOT_FOUND: None
} }
) )
@action(detail=True, methods=['patch'], url_path='editors-remove') @action(detail=True, methods=['patch'], url_path='remove-editor')
def editors_remove(self, request: Request, pk): def remove_editor(self, request: Request, pk):
''' Endpoint: Remove editor for item. ''' ''' Endpoint: Remove editor for item. '''
item = self._get_item() item = self._get_item()
serializer = s.UserTargetSerializer(data=request.data) serializer = s.UserTargetSerializer(data=request.data)
@ -260,8 +260,8 @@ class LibraryViewSet(viewsets.ModelViewSet):
c.HTTP_404_NOT_FOUND: None c.HTTP_404_NOT_FOUND: None
} }
) )
@action(detail=True, methods=['patch'], url_path='editors-set') @action(detail=True, methods=['patch'], url_path='set-editors')
def editors_set(self, request: Request, pk): def set_editors(self, request: Request, pk):
''' Endpoint: Set list of editors for item. ''' ''' Endpoint: Set list of editors for item. '''
item = self._get_item() item = self._get_item()
serializer = s.UsersListSerializer(data=request.data) serializer = s.UsersListSerializer(data=request.data)

View File

@ -35,11 +35,14 @@ class RSFormViewSet(viewsets.GenericViewSet, generics.ListAPIView, generics.Retr
''' Determine permission class. ''' ''' Determine permission class. '''
if self.action in [ if self.action in [
'load_trs', 'load_trs',
'create_cst',
'delete_multiple_cst',
'rename_cst',
'move_cst',
'substitute',
'restore_order',
'reset_aliases', 'reset_aliases',
'cst_create', 'produce_structure'
'cst_delete_multiple',
'cst_rename',
'cst_substitute'
]: ]:
permission_list = [permissions.ItemEditor] permission_list = [permissions.ItemEditor]
elif self.action in [ elif self.action in [
@ -65,8 +68,8 @@ class RSFormViewSet(viewsets.GenericViewSet, generics.ListAPIView, generics.Retr
c.HTTP_404_NOT_FOUND: None c.HTTP_404_NOT_FOUND: None
} }
) )
@action(detail=True, methods=['post'], url_path='cst-create') @action(detail=True, methods=['post'], url_path='create-cst')
def cst_create(self, request: Request, pk): def create_cst(self, request: Request, pk):
''' Create new constituenta. ''' ''' Create new constituenta. '''
schema = self._get_schema() schema = self._get_schema()
serializer = s.CstCreateSerializer(data=request.data) serializer = s.CstCreateSerializer(data=request.data)
@ -103,7 +106,7 @@ class RSFormViewSet(viewsets.GenericViewSet, generics.ListAPIView, generics.Retr
c.HTTP_404_NOT_FOUND: None c.HTTP_404_NOT_FOUND: None
} }
) )
@action(detail=True, methods=['patch'], url_path='cst-produce-structure') @action(detail=True, methods=['patch'], url_path='produce-structure')
def produce_structure(self, request: Request, pk): def produce_structure(self, request: Request, pk):
''' Produce a term for every element of the target constituenta typification. ''' ''' Produce a term for every element of the target constituenta typification. '''
schema = self._get_schema() schema = self._get_schema()
@ -140,8 +143,8 @@ class RSFormViewSet(viewsets.GenericViewSet, generics.ListAPIView, generics.Retr
c.HTTP_404_NOT_FOUND: None c.HTTP_404_NOT_FOUND: None
} }
) )
@action(detail=True, methods=['patch'], url_path='cst-rename') @action(detail=True, methods=['patch'], url_path='rename-cst')
def cst_rename(self, request: Request, pk): def rename_cst(self, request: Request, pk):
''' Rename constituenta possibly changing type. ''' ''' Rename constituenta possibly changing type. '''
schema = self._get_schema() schema = self._get_schema()
serializer = s.CstRenameSerializer(data=request.data, context={'schema': schema}) serializer = s.CstRenameSerializer(data=request.data, context={'schema': schema})
@ -178,8 +181,8 @@ class RSFormViewSet(viewsets.GenericViewSet, generics.ListAPIView, generics.Retr
c.HTTP_404_NOT_FOUND: None c.HTTP_404_NOT_FOUND: None
} }
) )
@action(detail=True, methods=['patch'], url_path='cst-substitute') @action(detail=True, methods=['patch'], url_path='substitute')
def cst_substitute(self, request: Request, pk): def substitute(self, request: Request, pk):
''' Substitute occurrences of constituenta with another one. ''' ''' Substitute occurrences of constituenta with another one. '''
schema = self._get_schema() schema = self._get_schema()
serializer = s.CstSubstituteSerializer( serializer = s.CstSubstituteSerializer(
@ -210,8 +213,8 @@ class RSFormViewSet(viewsets.GenericViewSet, generics.ListAPIView, generics.Retr
c.HTTP_404_NOT_FOUND: None c.HTTP_404_NOT_FOUND: None
} }
) )
@action(detail=True, methods=['patch'], url_path='cst-delete-multiple') @action(detail=True, methods=['patch'], url_path='delete-multiple-cst')
def cst_delete_multiple(self, request: Request, pk): def delete_multiple_cst(self, request: Request, pk):
''' Endpoint: Delete multiple constituents. ''' ''' Endpoint: Delete multiple constituents. '''
schema = self._get_schema() schema = self._get_schema()
serializer = s.CstListSerializer( serializer = s.CstListSerializer(
@ -237,8 +240,8 @@ class RSFormViewSet(viewsets.GenericViewSet, generics.ListAPIView, generics.Retr
c.HTTP_404_NOT_FOUND: None c.HTTP_404_NOT_FOUND: None
} }
) )
@action(detail=True, methods=['patch'], url_path='cst-moveto') @action(detail=True, methods=['patch'], url_path='move-cst')
def cst_moveto(self, request: Request, pk): def move_cst(self, request: Request, pk):
''' Endpoint: Move multiple constituents. ''' ''' Endpoint: Move multiple constituents. '''
schema = self._get_schema() schema = self._get_schema()
serializer = s.CstMoveSerializer( serializer = s.CstMoveSerializer(

View File

@ -24,7 +24,6 @@ import {
} from './apiTransport'; } from './apiTransport';
export function getLibrary(request: FrontPull<ILibraryItem[]>) { export function getLibrary(request: FrontPull<ILibraryItem[]>) {
// title: 'Available LibraryItems list',
AxiosGet({ AxiosGet({
endpoint: '/api/library/active', endpoint: '/api/library/active',
request: request request: request
@ -32,7 +31,6 @@ export function getLibrary(request: FrontPull<ILibraryItem[]>) {
} }
export function getAdminLibrary(request: FrontPull<ILibraryItem[]>) { export function getAdminLibrary(request: FrontPull<ILibraryItem[]>) {
// title: 'All LibraryItems list',
AxiosGet({ AxiosGet({
endpoint: '/api/library/all', endpoint: '/api/library/all',
request: request request: request
@ -95,23 +93,9 @@ export function patchSetLocation(target: string, request: FrontPush<ITargetLocat
}); });
} }
export function patchEditorsAdd(target: string, request: FrontPush<ITargetUser>) { export function patchSetEditors(target: string, request: FrontPush<ITargetUsers>) {
AxiosPatch({ AxiosPatch({
endpoint: `/api/library/${target}/editors-add`, endpoint: `/api/library/${target}/set-editors`,
request: request
});
}
export function patchEditorsRemove(target: string, request: FrontPush<ITargetUser>) {
AxiosPatch({
endpoint: `/api/library/${target}/editors-remove`,
request: request
});
}
export function patchEditorsSet(target: string, request: FrontPush<ITargetUsers>) {
AxiosPatch({
endpoint: `/api/library/${target}/editors-set`,
request: request request: request
}); });
} }

View File

@ -64,42 +64,42 @@ export function getTRSFile(target: string, version: string, request: FrontPull<B
export function postCreateConstituenta(schema: string, request: FrontExchange<ICstCreateData, ICstCreatedResponse>) { export function postCreateConstituenta(schema: string, request: FrontExchange<ICstCreateData, ICstCreatedResponse>) {
AxiosPost({ AxiosPost({
endpoint: `/api/rsforms/${schema}/cst-create`, endpoint: `/api/rsforms/${schema}/create-cst`,
request: request request: request
}); });
} }
export function patchDeleteConstituenta(schema: string, request: FrontExchange<IConstituentaList, IRSFormData>) { export function patchDeleteConstituenta(schema: string, request: FrontExchange<IConstituentaList, IRSFormData>) {
AxiosPatch({ AxiosPatch({
endpoint: `/api/rsforms/${schema}/cst-delete-multiple`, endpoint: `/api/rsforms/${schema}/delete-multiple-cst`,
request: request request: request
}); });
} }
export function patchRenameConstituenta(schema: string, request: FrontExchange<ICstRenameData, ICstCreatedResponse>) { export function patchRenameConstituenta(schema: string, request: FrontExchange<ICstRenameData, ICstCreatedResponse>) {
AxiosPatch({ AxiosPatch({
endpoint: `/api/rsforms/${schema}/cst-rename`, endpoint: `/api/rsforms/${schema}/rename-cst`,
request: request request: request
}); });
} }
export function patchProduceStructure(schema: string, request: FrontExchange<ITargetCst, IProduceStructureResponse>) { export function patchProduceStructure(schema: string, request: FrontExchange<ITargetCst, IProduceStructureResponse>) {
AxiosPatch({ AxiosPatch({
endpoint: `/api/rsforms/${schema}/cst-produce-structure`, endpoint: `/api/rsforms/${schema}/produce-structure`,
request: request request: request
}); });
} }
export function patchSubstituteConstituents(schema: string, request: FrontExchange<ICstSubstituteData, IRSFormData>) { export function patchSubstituteConstituents(schema: string, request: FrontExchange<ICstSubstituteData, IRSFormData>) {
AxiosPatch({ AxiosPatch({
endpoint: `/api/rsforms/${schema}/cst-substitute`, endpoint: `/api/rsforms/${schema}/substitute`,
request: request request: request
}); });
} }
export function patchMoveConstituenta(schema: string, request: FrontExchange<ICstMovetoData, IRSFormData>) { export function patchMoveConstituenta(schema: string, request: FrontExchange<ICstMovetoData, IRSFormData>) {
AxiosPatch({ AxiosPatch({
endpoint: `/api/rsforms/${schema}/cst-moveto`, endpoint: `/api/rsforms/${schema}/move-cst`,
request: request request: request
}); });
} }

View File

@ -5,9 +5,9 @@ import { createContext, useCallback, useContext, useMemo, useState } from 'react
import { DataCallback } from '@/backend/apiTransport'; import { DataCallback } from '@/backend/apiTransport';
import { import {
deleteUnsubscribe, deleteUnsubscribe,
patchEditorsSet,
patchLibraryItem, patchLibraryItem,
patchSetAccessPolicy, patchSetAccessPolicy,
patchSetEditors,
patchSetLocation, patchSetLocation,
patchSetOwner, patchSetOwner,
postSubscribe postSubscribe
@ -236,7 +236,7 @@ export const OssState = ({ itemID, children }: OssStateProps) => {
return; return;
} }
setProcessingError(undefined); setProcessingError(undefined);
patchEditorsSet(itemID, { patchSetEditors(itemID, {
data: { data: {
users: newEditors users: newEditors
}, },

View File

@ -6,9 +6,9 @@ import { DataCallback } from '@/backend/apiTransport';
import { patchConstituenta } from '@/backend/constituents'; import { patchConstituenta } from '@/backend/constituents';
import { import {
deleteUnsubscribe, deleteUnsubscribe,
patchEditorsSet,
patchLibraryItem, patchLibraryItem,
patchSetAccessPolicy, patchSetAccessPolicy,
patchSetEditors,
patchSetLocation, patchSetLocation,
patchSetOwner, patchSetOwner,
postSubscribe postSubscribe
@ -309,7 +309,7 @@ export const RSFormState = ({ itemID, versionID, children }: RSFormStateProps) =
return; return;
} }
setProcessingError(undefined); setProcessingError(undefined);
patchEditorsSet(itemID, { patchSetEditors(itemID, {
data: { data: {
users: newEditors users: newEditors
}, },