mirror of
https://github.com/openSUSE/osc.git
synced 2024-11-10 06:46:15 +01:00
Merge pull request #1567 from dmach/person-register-search
Add 'person register' and 'person search' commands
This commit is contained in:
commit
a010e99c34
12
osc/commands/person.py
Normal file
12
osc/commands/person.py
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import osc.commandline
|
||||||
|
|
||||||
|
|
||||||
|
class PersonCommand(osc.commandline.OscCommand):
|
||||||
|
"""
|
||||||
|
Manage persons
|
||||||
|
"""
|
||||||
|
|
||||||
|
name = "person"
|
||||||
|
|
||||||
|
def run(self, args):
|
||||||
|
pass
|
58
osc/commands/person_register.py
Normal file
58
osc/commands/person_register.py
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
import osc.commandline
|
||||||
|
|
||||||
|
|
||||||
|
class PersonRegisterCommand(osc.commandline.OscCommand):
|
||||||
|
"""
|
||||||
|
Register a new person (user)
|
||||||
|
"""
|
||||||
|
|
||||||
|
name = "register"
|
||||||
|
parent = "PersonCommand"
|
||||||
|
|
||||||
|
def init_arguments(self):
|
||||||
|
self.add_argument(
|
||||||
|
"--login",
|
||||||
|
required=True,
|
||||||
|
help="Login.",
|
||||||
|
)
|
||||||
|
self.add_argument(
|
||||||
|
"--realname",
|
||||||
|
required=True,
|
||||||
|
help="Real name of the person.",
|
||||||
|
)
|
||||||
|
self.add_argument(
|
||||||
|
"--email",
|
||||||
|
required=True,
|
||||||
|
help="Email address.",
|
||||||
|
)
|
||||||
|
self.add_argument(
|
||||||
|
"--password",
|
||||||
|
help="Password. An interactive prompt is shown if password is not specified.",
|
||||||
|
)
|
||||||
|
self.add_argument(
|
||||||
|
"--note",
|
||||||
|
help="Any notes about the person.",
|
||||||
|
)
|
||||||
|
self.add_argument(
|
||||||
|
"--state",
|
||||||
|
help="State of the account. Defaults to 'unconfirmed'.",
|
||||||
|
)
|
||||||
|
|
||||||
|
def run(self, args):
|
||||||
|
from osc import obs_api
|
||||||
|
from osc.util.helper import raw_input
|
||||||
|
|
||||||
|
if args.password:
|
||||||
|
password = args.password
|
||||||
|
else:
|
||||||
|
password = raw_input(f"Enter password for {args.login}@{args.apiurl}: ")
|
||||||
|
|
||||||
|
obs_api.Person.cmd_register(
|
||||||
|
args.apiurl,
|
||||||
|
login=args.login,
|
||||||
|
realname=args.realname,
|
||||||
|
email=args.email,
|
||||||
|
password=password,
|
||||||
|
note=args.note,
|
||||||
|
state=args.state,
|
||||||
|
)
|
51
osc/commands/person_search.py
Normal file
51
osc/commands/person_search.py
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
import osc.commandline
|
||||||
|
|
||||||
|
|
||||||
|
class PersonSearchCommand(osc.commandline.OscCommand):
|
||||||
|
"""
|
||||||
|
Search a person (user)
|
||||||
|
"""
|
||||||
|
|
||||||
|
name = "search"
|
||||||
|
parent = "PersonCommand"
|
||||||
|
|
||||||
|
def init_arguments(self):
|
||||||
|
self.add_argument(
|
||||||
|
"--login",
|
||||||
|
help="Search by a login.",
|
||||||
|
)
|
||||||
|
self.add_argument(
|
||||||
|
"--login-contains",
|
||||||
|
metavar="SUBSTR",
|
||||||
|
help="Search by a substring in a login.",
|
||||||
|
)
|
||||||
|
self.add_argument(
|
||||||
|
"--realname-contains",
|
||||||
|
metavar="SUBSTR",
|
||||||
|
help="Search by a substring in a realname.",
|
||||||
|
)
|
||||||
|
self.add_argument(
|
||||||
|
"--email",
|
||||||
|
help="Search by an email address.",
|
||||||
|
)
|
||||||
|
self.add_argument(
|
||||||
|
"--email-contains",
|
||||||
|
metavar="SUBSTR",
|
||||||
|
help="Search by a substring in an email address.",
|
||||||
|
)
|
||||||
|
|
||||||
|
def run(self, args):
|
||||||
|
from .. import obs_api
|
||||||
|
|
||||||
|
persons = obs_api.Person.search(
|
||||||
|
args.apiurl,
|
||||||
|
login=args.login,
|
||||||
|
login__contains=args.login_contains,
|
||||||
|
realname__contains=args.realname_contains,
|
||||||
|
email=args.email,
|
||||||
|
email__contains=args.email_contains,
|
||||||
|
)
|
||||||
|
|
||||||
|
for person in persons:
|
||||||
|
print(person.to_human_readable_string())
|
||||||
|
print()
|
@ -2,6 +2,7 @@ from ..util.models import * # pylint: disable=wildcard-import,unused-wildcard-i
|
|||||||
from .enums import BoolString
|
from .enums import BoolString
|
||||||
from .person_owner import PersonOwner
|
from .person_owner import PersonOwner
|
||||||
from .person_watchlist import PersonWatchlist
|
from .person_watchlist import PersonWatchlist
|
||||||
|
from .status import Status
|
||||||
|
|
||||||
|
|
||||||
class Person(XmlModel):
|
class Person(XmlModel):
|
||||||
@ -32,6 +33,19 @@ class Person(XmlModel):
|
|||||||
ignore_auth_services: Optional[BoolString] = Field(
|
ignore_auth_services: Optional[BoolString] = Field(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def to_human_readable_string(self) -> str:
|
||||||
|
"""
|
||||||
|
Render the object as a human readable string.
|
||||||
|
"""
|
||||||
|
from ..output import KeyValueTable
|
||||||
|
|
||||||
|
table = KeyValueTable()
|
||||||
|
table.add("Login", self.login, color="bold")
|
||||||
|
table.add("Real name", self.realname)
|
||||||
|
table.add("Email", self.email)
|
||||||
|
table.add("State", self.state)
|
||||||
|
return f"{table}"
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_api(cls, apiurl: str, username: str):
|
def from_api(cls, apiurl: str, username: str):
|
||||||
url_path = ["person", username]
|
url_path = ["person", username]
|
||||||
@ -69,3 +83,45 @@ class Person(XmlModel):
|
|||||||
for node in root:
|
for node in root:
|
||||||
result.append(cls.from_xml(node, apiurl=apiurl))
|
result.append(cls.from_xml(node, apiurl=apiurl))
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def cmd_register(
|
||||||
|
cls,
|
||||||
|
apiurl: str,
|
||||||
|
*,
|
||||||
|
login: str,
|
||||||
|
realname: str,
|
||||||
|
email: str,
|
||||||
|
password: str,
|
||||||
|
note: Optional[str] = None,
|
||||||
|
state: Optional[str] = "confirmed",
|
||||||
|
):
|
||||||
|
person = UnregisteredPerson(login=login, realname=realname, email=email, password=password, note=note, state=state)
|
||||||
|
url_path = ["person"]
|
||||||
|
url_query = {
|
||||||
|
"cmd": "register",
|
||||||
|
}
|
||||||
|
response = cls.xml_request("POST", apiurl, url_path, url_query, data=person.to_string())
|
||||||
|
return Status.from_file(response, apiurl=apiurl)
|
||||||
|
|
||||||
|
|
||||||
|
class UnregisteredPerson(XmlModel):
|
||||||
|
XML_TAG = "unregisteredperson"
|
||||||
|
|
||||||
|
login: str = Field(
|
||||||
|
)
|
||||||
|
|
||||||
|
realname: str = Field(
|
||||||
|
)
|
||||||
|
|
||||||
|
email: str = Field(
|
||||||
|
)
|
||||||
|
|
||||||
|
password: str = Field(
|
||||||
|
)
|
||||||
|
|
||||||
|
note: Optional[str] = Field(
|
||||||
|
)
|
||||||
|
|
||||||
|
state: Optional[str] = Field(
|
||||||
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user