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.cm.models.admin
22 #
23 from django.db import models
24 
25 from cm.models.user import User
26 from cm.utils.exception import CMException
27 
28 
29 ##
30 #
31 # @model{ADMIN}
32 #
33 # Each Cluster may be managed by individual CM Admin, separable from overall
34 # cloud's Admin. This class is for Cluster Manager's Admin.
35 #
36 class Admin(models.Model):
37  user = models.OneToOneField(User, primary_key=True)
38  password = models.CharField(max_length=256)
39 
40  class Meta:
41  app_label = 'cm'
42 
43  # method for printing object instance
44  def __unicode__(self):
45  return str(self.user)
46 
47  @staticmethod
48  ##
49  #
50  # Method checks, whether user \c user_id is superuser.
51  # Otherwise it throws CMException 'user_permission'.
52  #
53  # @parameter{user_id,int} id of the user
54  #
55  # @returns{int} 1, if successful
56  #
57  # @raises{user_permission,CMException}
58  #
59  def superuser(user_id):
60  try:
61  Admin.objects.get(pk=user_id)
62  # if get find no instance throws exception
63  except:
64  raise CMException('user_permission')
65  return 1
66 
67  @staticmethod
68  ##
69  #
70  # Checks for *CM admin's password* correctness.
71  #
72  # @parameter{admin_id,int} id of the admin whose password is checked
73  # @parameter{password_par,string} password to check
74  #
75  # @raises{user_permission,CMException}
76  #
77  def check_password(admin_id, password_par):
78  if Admin.objects.filter(user__exact=admin_id).filter(password__exact=password_par).exists():
79  pass
80  else:
81  raise CMException('user_permission')
82