blob: efc08c67cbb3a8f3cf152251b4c4ca32c5b0a429 [file] [log] [blame]
Siobhan Tullycf04fb62014-01-11 11:25:57 -05001from core.models import User,Site,Service,SingletonModel,PlCoreBase
2import os
3from django.db import models
4from django.forms.models import model_to_dict
5from bitfield import BitField
6
7# Create your models here.
8
9class SyndicateService(SingletonModel,Service):
10 class Meta:
11 app_label = "syndicate"
12 verbose_name = "Syndicate Service"
13 verbose_name_plural = "Syndicate Service"
14
15 def __unicode__(self): return u'Syndicate Service'
16
17class SyndicateUser(models.Model):
18
19 user = models.ForeignKey(User)
20 is_admin = models.BooleanField(default=False, help_text="Indicates this user has Administrative purposes for the Syndicate Service")
21 max_volumes = models.PositiveIntegerField(help_text="Maximum number of Volumes this user may create.", default=1)
22 max_UGs = models.PositiveIntegerField(help_text="Maximum number of User Gateways this user may create.", default=500)
23 max_RGs = models.PositiveIntegerField(help_text="Maximum number of Replica Gateways this user may create.", default=500)
24 max_AGs = models.PositiveIntegerField(help_text="Maximum number of Aquisition Gateways this user may create.", default=10)
25
26 def __unicode__(self): return self.user.email
27
28class Volume(models.Model):
29 name = models.CharField(max_length=64, help_text="Human-readable, searchable name of the Volume")
30 owner_id = models.ForeignKey(SyndicateUser, verbose_name='Owner')
31 description = models.TextField(null=True, blank=True,max_length=130, help_text="Human-readable description of what this Volume is used for.")
32 blocksize = models.PositiveIntegerField(help_text="Number of bytes per block.")
33 private = models.BooleanField(default=True, help_text="Indicates if the Volume is visible to users other than the Volume Owner and Syndicate Administrators.")
34 archive = models.BooleanField(default=True, help_text="Indicates if this Volume is read-only, and only an Aquisition Gateway owned by the Volume owner (or Syndicate admin) can write to it.")
35 metadata_public_key = models.TextField(null=True, blank=True, max_length=1024, help_text="Public key Gateways will use to verify the authenticity of metadata from this Volume")
36 metadata_private_key = models.TextField(null=True, blank=True, max_length=1024, help_text="Private key the Volume should use to sign metadata served to Gateways")
37 api_public_key = models.TextField(null=True, blank=True, max_length=1024, help_text="Public key used to verify writes to these fields from Volume owner")
38
39 file_quota = models.IntegerField(help_text='Maximum number of files and directories allowed in this Volume (-1 means "unlimited")')
40
41 default_gateway_caps = BitField(flags=('GATEWAY_CAP_READ_DATA','GATEWAY_CAP_READ_METADATA', 'GATEWAY_CAP_WRITE_DATA', 'GATEWAY_CAP_WRITE_METADATA', 'GATEWAY_CAP_COORDINATE'), verbose_name='Default Gateway Capabilities')
42 #default_gateway_caps = models.PositiveIntegerField(verbose_name='Default Gateway Capabilities')
43 #default_gateway_caps2 = models.CharField(max_length=32,null=True,default = "readonly", verbose_name='Default Gateway Capabilities')
44
45 def __unicode__(self): return self.name
46
47class VolumeAccessRight(models.Model):
48 owner_id = models.ForeignKey(SyndicateUser, verbose_name='user')
49 volume = models.ForeignKey(Volume)
50 gateway_caps = BitField(flags=('GATEWAY_CAP_READ_DATA','GATEWAY_CAP_READ_METADATA', 'GATEWAY_CAP_WRITE_DATA', 'GATEWAY_CAP_WRITE_METADATA', 'GATEWAY_CAP_COORDINATE'), verbose_name='Gateway Capabilities')
51 #gateway_caps = models.PositiveIntegerField(verbose_name='Gateway Capabilities')
52 #gateway_caps2 = models.CharField(max_length=32, default='readonly',null=True,verbose_name='Default Gateway Capabilities')
53
54 def __unicode__(self): return self.owner_id.user.email
55
56class VolumeAccessRequest(models.Model):
57 owner_id = models.ForeignKey(SyndicateUser, verbose_name='user')
58 volume = models.ForeignKey(Volume)
59 message = models.TextField(null=True, blank=True, max_length=1024, help_text="Description of why the user wants access to the volume.")
60 gateway_caps = BitField(flags=('GATEWAY_CAP_READ_DATA','GATEWAY_CAP_READ_METADATA', 'GATEWAY_CAP_WRITE_DATA', 'GATEWAY_CAP_WRITE_METADATA', 'GATEWAY_CAP_COORDINATE'), verbose_name='Gateway Capabilities')
61 #gateway_caps = models.PositiveIntegerField(verbose_name='Gateway Capabilities')
62 #gateway_caps2 = models.CharField(max_length=32,default='readonly',null=True,verbose_name='Default Gateway Capabilities')
63
64 def __unicode__(self): return self.owner_id.user.email