Source code for gerrit.accounts.emails
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Author: Jialiang Shi
from gerrit.utils.models import BaseModel
[docs]
class GerritAccountEmail(BaseModel):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.entity_name = "email"
self.endpoint = f"/accounts/{self.account_id}/emails/{self.email}"
[docs]
def delete(self):
"""
Deletes an email address of an account.
:return:
"""
self.gerrit.delete(self.endpoint)
[docs]
def set_preferred(self):
"""
Sets an email address as preferred email address for an account.
:return:
"""
self.gerrit.put(self.endpoint + "/preferred")
[docs]
class GerritAccountEmails(object):
def __init__(self, account_id, gerrit):
self.account_id = account_id
self.gerrit = gerrit
self.endpoint = f"/accounts/{self.account_id}/emails"
[docs]
def list(self):
"""
Returns the email addresses that are configured for the specified user.
:return:
"""
result = self.gerrit.get(self.endpoint)
return GerritAccountEmail.parse_list(
result, account_id=self.account_id, gerrit=self.gerrit
)
[docs]
def create(self, email):
"""
Registers a new email address for the user.
:return:
"""
return self.gerrit.put(self.endpoint + f"/{email}")
[docs]
def get(self, email):
"""
Retrieves an email address of a user.
:return:
"""
result = self.gerrit.get(self.endpoint + f"/{email}")
return GerritAccountEmail(
json=result, account_id=self.account_id, gerrit=self.gerrit
)
[docs]
def set_preferred(self, email):
"""
Sets an email address as preferred email address for an account.
:param email: account email
:return:
"""
self.gerrit.put(self.endpoint + f"/{email}/preferred")
[docs]
def delete(self, email):
"""
Deletes an email address of an account.
:param email: account email
:return:
"""
self.gerrit.delete(self.endpoint + f"/{email}")