cc1  v2.1
CC1 source code docs
 All Classes Namespaces Files Functions Variables Pages
admin.py
Go to the documentation of this file.
1 # -*- coding: utf-8 -*-
2 # @COPYRIGHT_begin
3 #
4 # Copyright [2010-2014] Institute of Nuclear Physics PAN, Krakow, Poland
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 #
18 # @COPYRIGHT_end
19 
20 ##
21 # @package src.clm.views.admin_cm.admin
22 # @alldecoratedby{src.clm.utils.decorators.admin_cm_log}
23 #
24 from clm.models.cluster import Cluster
25 from clm.models.user import User
26 from clm.utils.cm import CM
27 from clm.utils.decorators import admin_cm_log, cm_request
28 from clm.utils.exception import CLMException
29 
30 
31 @admin_cm_log(log=True, pack=False)
32 @cm_request
33 ##
34 #
35 # @clmview_admin_clm
36 # @cm_request_transparent{admin.add()}
37 #
38 def add(cm_response, **data):
39  if cm_response['status'] == 'ok':
40  try:
41  user = User.get(data['user_id'])
42  user.is_superuser_cm = 1
43  user.save()
44  except:
45  CLMException('cm_admin_add')
46 
47  return cm_response
48 
49 
50 @admin_cm_log(log=True, pack=False)
51 @cm_request
52 ##
53 #
54 # @clmview_admin_clm
55 # @cm_request_transparent{admin.delete()}
56 #
57 def delete(cm_response, **data):
58  is_admin = False
59  for cm_id in [cluster.id for cluster in Cluster.objects.all()]:
60  resp = CM(cm_id).send_request('admin_cm/admin/am_i_admin/', caller_id=data['user_id'])
61  if resp['status'] == 'ok' and resp['data']:
62  is_admin = True
63  break
64  if not is_admin:
65  try:
66  user = User.get(data['user_id'])
67  user.is_superuser_cm = 0
68  user.save()
69  except:
70  CLMException('cm_admin_add')
71 
72  return cm_response
73 
74 
75 @admin_cm_log(log=True, pack=False)
76 @cm_request
77 ##
78 #
79 # @clmview_admin_clm
80 # @cm_request_transparent{admin.change_password()}
81 #
82 def change_password(cm_response, **data):
83  return cm_response
84 
85 
86 @admin_cm_log(log=True, pack=False)
87 @cm_request
88 ##
89 #
90 # @clmview_admin_clm
91 # @cm_request_transparent{admin.list_admins()}
92 #
93 def list_admins(cm_response, **data):
94  return cm_response
95