mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-22 14:19:28 +00:00
Support for Incarna v1.1, Customizable API Keys
- Support CAK keys and their spinoffs - Add support for the Employment History data available in CharacterInfo.xml.aspx - Add a Gargoyle flag to disable backend processing when needed - Clean up a few inconsistancies with how the models are handled
This commit is contained in:
@@ -26,6 +26,12 @@ class EVEAccount(EVEAPIModel):
|
||||
default=API_KEYTYPE_UNKNOWN,
|
||||
verbose_name="API Key Type",
|
||||
help_text="Type of API key")
|
||||
api_accessmask = models.IntegerField(default=0,
|
||||
verbose_name="API Key Access Mask",
|
||||
help_text="Describes the level of access this API key gives to the user's data")
|
||||
api_expiry = models.DateTimeField(blank=True, null=True,
|
||||
verbose_name="API Key Expiry Date",
|
||||
help_text="Indicates when the API key will expire.")
|
||||
|
||||
def __unicode__(self):
|
||||
return u"%s" % self.pk
|
||||
@@ -33,10 +39,39 @@ class EVEAccount(EVEAPIModel):
|
||||
def in_corp(self, corpid):
|
||||
return self.character.filter(corporation__id=corpid).count()
|
||||
|
||||
@staticmethod
|
||||
def _mask_check(accessmask, bit):
|
||||
""" Returns a bool indicating if the bit is set in the accessmask """
|
||||
mask = 1 << bit
|
||||
return (accessmask & mask) > 0
|
||||
|
||||
def has_access(self, bit):
|
||||
""" Checks if a specific bit is enabled in the key's access mask """
|
||||
return self._mask_check(self.api_accessmask, bit)
|
||||
|
||||
def check_access(self, accessmask):
|
||||
""" Checks if the account has equal or higher access than the bitmask provided """
|
||||
|
||||
length = 0
|
||||
i = accessmask
|
||||
while i:
|
||||
i >>= 1
|
||||
length += 1
|
||||
|
||||
for bit in range(0, length-1):
|
||||
if self._mask_check(accessmask, bit) and not self.has_access(bit):
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
@property
|
||||
def training(self):
|
||||
return self.characters.filter(eveplayercharacterskill__in_training__gt=0).count()
|
||||
|
||||
@property
|
||||
def is_cak(self):
|
||||
return self.api_keytype in [API_KEYTYPE_CHARACTER, API_KEYTYPE_CORPORATION, API_KEYTYPE_ACCOUNT]
|
||||
|
||||
class Meta:
|
||||
app_label = 'eve_api'
|
||||
verbose_name = 'EVE Account'
|
||||
|
||||
@@ -23,6 +23,30 @@ class EVEPlayerCharacterSkill(models.Model):
|
||||
verbose_name_plural = 'Player Character Skills'
|
||||
|
||||
|
||||
class EVEPlayerCharacterEmploymentHistory(models.Model):
|
||||
"""
|
||||
Player's corporation history
|
||||
"""
|
||||
record_id = models.IntegerField(primary_key=True, verbose_name="Record ID")
|
||||
character = models.ForeignKey('eve_api.EVEPlayerCharacter', related_name='employmenthistory')
|
||||
corporation = models.ForeignKey('eve_api.EVEPlayerCorporation', related_name='+')
|
||||
start_date = models.DateTimeField(blank=False, null=False, verbose_name="Corporation Join Date")
|
||||
|
||||
@property
|
||||
def end_date(self):
|
||||
if self.character.employmenthistory.filter(record_id__gt=self.record_id).count():
|
||||
return self.character.employmenthistory.filter(record_id__gt=self.record_id)[0].start_date
|
||||
return None
|
||||
|
||||
def __unicode__(self):
|
||||
return u'%s - %s - %s' % (self.record_id, self.character, self.corporation)
|
||||
|
||||
class Meta:
|
||||
app_label = 'eve_api'
|
||||
verbose_name = 'Player Character Employment History'
|
||||
verbose_name_plural = 'Player Character Employment Histories'
|
||||
|
||||
|
||||
class EVEPlayerCharacter(EVEAPIModel):
|
||||
"""
|
||||
Represents an individual player character within the game. Not to be
|
||||
|
||||
@@ -47,7 +47,10 @@ class EVEPlayerCorporation(EVEAPIModel):
|
||||
|
||||
@property
|
||||
def director_api_keys(self):
|
||||
return self.directors.filter(eveaccount__isnull=False, eveaccount__api_keytype=API_KEYTYPE_FULL, eveaccount__api_status=API_STATUS_OK)
|
||||
if gargoyle.is_active('eve-cak'):
|
||||
return self.directors.filter(eveaccount__isnull=False, eveaccount__api_keytype__in=[API_KEYTYPE_CORPORATION, API_KEYTYPE_FULL], eveaccount__api_status=API_STATUS_OK)
|
||||
else:
|
||||
return self.directors.filter(eveaccount__isnull=False, eveaccount__api_keytype=API_KEYTYPE_FULL, eveaccount__api_status=API_STATUS_OK)
|
||||
|
||||
@property
|
||||
def api_key_coverage(self):
|
||||
|
||||
Reference in New Issue
Block a user