1
1
from django .shortcuts import render
2
2
from rest_framework import status
3
3
from rest_framework .response import Response
4
- from rest_framework import status
5
4
from rest_framework .views import APIView
6
5
from rest_framework .parsers import MultiPartParser
7
6
from rest_framework .permissions import IsAuthenticated
8
- from .serializers import *
9
- from .models import *
10
- from . import responses
11
7
from rest_framework .decorators import api_view , permission_classes
12
8
from drf_yasg .utils import swagger_auto_schema
13
9
from drf_yasg import openapi
14
10
from utils .swagger import set_example
15
11
from org .custom_model_field import Permissions
12
+ from .serializers import *
13
+ from .models import *
14
+ from . import responses
16
15
17
16
18
17
class OrgView (APIView ):
@@ -29,11 +28,11 @@ class OrgView(APIView):
29
28
)
30
29
def post (self , request ):
31
30
"""
32
- 1. when a Organisation is created Admin and Volunteer
31
+ 1. when a Organisation is created Admin and Volunteer
33
32
groups are also automatically created for that org.
34
33
2. Admin group has all the permissions available.
35
- 3. Volunteer group has no permissions but when a user
36
- joins that org without invite link he/she will be
34
+ 3. Volunteer group has no permissions but when a user
35
+ joins that org without invite link he/she will be
37
36
put into volunteer group.
38
37
4. The creator of the org will be automatically put into Admin group.
39
38
"""
@@ -173,3 +172,95 @@ def GetGroup(request, org_id):
173
172
return Response (response_object , status .HTTP_200_OK )
174
173
else :
175
174
return Response ({"detail" : "You are not authorised to view this." }, status .HTTP_403_FORBIDDEN )
175
+
176
+
177
+ class GroupDetailsView (APIView ):
178
+ '''
179
+ This is to provide details of a particular
180
+ group of an organisation to authorised
181
+ members.
182
+ '''
183
+
184
+ permission_classes = [IsAuthenticated ]
185
+
186
+ @swagger_auto_schema (
187
+ operation_id = 'group_details' ,
188
+ operation_description = "Authenticated and permitted users receive\
189
+ desired group details here" ,
190
+ responses = {
191
+ '200' : set_example (responses .group_details_200 ),
192
+ '404' : set_example (responses .org_not_present_404 ),
193
+ '401' : set_example (responses .user_not_present_401 ),
194
+ '403' : set_example (responses .user_unauthorized_403 ),
195
+ '400' : set_example (responses .group_not_present_400 ),
196
+ },
197
+ )
198
+
199
+ def get (self , request , org_id , group_id ):
200
+
201
+ try :
202
+ org = Org .objects .get (id = org_id )
203
+ except Org .DoesNotExist :
204
+ return Response (
205
+ {"message" :"This organisation does not exist" },
206
+ status .HTTP_404_NOT_FOUND
207
+ )
208
+
209
+ try :
210
+ group = Group .objects .get (
211
+ id = group_id ,
212
+ org = org
213
+ )
214
+ except Group .DoesNotExist :
215
+ return Response (
216
+ {"message" :"This group does not exist" },
217
+ status .HTTP_400_BAD_REQUEST
218
+ )
219
+
220
+ try :
221
+ member = Member .objects .get (
222
+ user = request .user ,
223
+ org = org
224
+ )
225
+ except Member .DoesNotExist :
226
+ return Response (
227
+ {"detail" :"You are not a member of this organisation" },
228
+ status .HTTP_401_UNAUTHORIZED
229
+ )
230
+
231
+ if member .group .perm_obj .permissions [Permissions .IS_STAFF ]:
232
+ return Response (
233
+ {
234
+ "id" : group_id ,
235
+ "name" : group .name ,
236
+ "role" : group .role ,
237
+ "permissions" : {
238
+
239
+ "Is Admin" :{
240
+ 'value' : group .perm_obj .permissions [Permissions .IS_ADMIN ],
241
+ 'perm_int' : Permissions .IS_ADMIN ,
242
+ },
243
+ "Is Staff" :{
244
+ 'value' : group .perm_obj .permissions [Permissions .IS_STAFF ],
245
+ 'perm_int' : Permissions .IS_STAFF ,
246
+ },
247
+ "Can create tasks" :{
248
+ 'value' : group .perm_obj .permissions [Permissions .CAN_CREATE_TASKS ],
249
+ 'perm_int' : Permissions .CAN_CREATE_TASKS ,
250
+ },
251
+ "Can reply to queries" :{
252
+ 'value' : group .perm_obj .permissions [Permissions .CAN_REPLY_TO_QUERIES ],
253
+ 'perm_int' : Permissions .CAN_REPLY_TO_QUERIES ,
254
+ },
255
+ "Can review proofs" :{
256
+ 'value' : group .perm_obj .permissions [Permissions .CAN_CREATE_TASKS ],
257
+ 'perm_int' : Permissions .CAN_REVIEW_PROOFS ,
258
+ }
259
+ }
260
+ },
261
+ status .HTTP_200_OK
262
+ )
263
+ return Response (
264
+ {"message" :"You do not have the required permissions." },
265
+ status .HTTP_403_FORBIDDEN
266
+ )
0 commit comments