Skip to content

Commit

Permalink
[persons] separe functions for bots and persons
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanBldy committed Feb 29, 2024
1 parent 3191147 commit 2a4ada7
Show file tree
Hide file tree
Showing 10 changed files with 219 additions and 58 deletions.
2 changes: 1 addition & 1 deletion gazu/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def remove_asset(asset, force=False, client=default):
path = "data/assets/%s" % asset["id"]
params = {}
if force:
params = {"force": "true"}
params = {"force": True}
return raw.delete(path, params, client=client)


Expand Down
2 changes: 1 addition & 1 deletion gazu/concept.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def remove_concept(concept, force=False, client=default):
path = "data/concepts/%s" % concept["id"]
params = {}
if force:
params = {"force": "true"}
params = {"force": True}
return raw.delete(path, params, client=client)


Expand Down
2 changes: 1 addition & 1 deletion gazu/edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def remove_edit(edit, force=False, client=default):
path = "data/edits/%s" % edit["id"]
params = {}
if force:
params = {"force": "true"}
params = {"force": True}
return raw.delete(path, params, client=client)


Expand Down
2 changes: 1 addition & 1 deletion gazu/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def remove_entity(entity, force=False, client=default):
path = "data/entities/%s" % entity["id"]
params = {}
if force:
params = {"force": "true"}
params = {"force": True}
return raw.delete(path, params, client=client)


Expand Down
119 changes: 102 additions & 17 deletions gazu/person.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ def get_person(id, relations=False, client=default):
dict: Person corresponding to given id.
"""
params = {"id": id}
if relations:
params["relations"] = "true"
if not relations:
params["relations"] = False

return raw.fetch_first("persons", params=params, client=client)

Expand All @@ -105,7 +105,9 @@ def get_person_by_desktop_login(desktop_login, client=default):
dict: Person corresponding to given desktop computer login.
"""
return raw.fetch_first(
"persons", {"desktop_login": desktop_login}, client=client
"persons",
{"desktop_login": desktop_login, "is_bot": False},
client=client,
)


Expand All @@ -118,7 +120,9 @@ def get_person_by_email(email, client=default):
Returns:
dict: Person corresponding to given email.
"""
return raw.fetch_first("persons", {"email": email}, client=client)
return raw.fetch_first(
"persons", {"email": email, "is_bot": False}, client=client
)


@cache
Expand All @@ -137,16 +141,19 @@ def get_person_by_full_name(
if first_name is not None and last_name is not None:
return raw.fetch_first(
"persons",
{"first_name": first_name, "last_name": last_name},
{
"first_name": first_name,
"last_name": last_name,
"is_bot": False,
},
client=client,
)
else:
return raw.fetch_first(
"persons",
{"full_name": full_name},
{"full_name": full_name, "is_bot": False},
client=client,
)
return None


@cache
Expand Down Expand Up @@ -184,26 +191,25 @@ def new_person(
desktop_login="",
departments=[],
password=None,
is_bot=False,
expiration_date=None,
active=True,
contract_type="open-ended",
client=default,
):
"""
Create a new person based on given parameters. His/her password will is
set automatically to default.
Args:
first_name (str):
last_name (str):
email (str):
phone (str):
first_name (str): the first name of the person.
last_name (str): the last name of the person.
email (str): the email of the person.
phone (str): the phone number of the person.
role (str): user, manager, admin (wich match CG artist, Supervisor
and studio manager)
desktop_login (str): The login the users uses to log on its computer.
departments (list): The departments for the person.
password (str): The password for the person.
is_bot (bool): Whether the person is a bot or not.
expiration_date (str): The expiration date for the person.
active (bool): Whether the person is active or not.
Returns:
dict: Created person.
"""
Expand All @@ -220,8 +226,8 @@ def new_person(
"desktop_login": desktop_login,
"departments": normalize_list_of_models_for_links(departments),
"password": password,
"is_bot": is_bot,
"expiration_date": expiration_date,
"active": active,
"contract_type": contract_type,
},
client=client,
)
Expand Down Expand Up @@ -252,6 +258,85 @@ def update_person(person, client=default):
)


def remove_person(person, force=False, client=default):
"""
Remove given person from database.
Args:
person (dict): Person to remove.
"""
person = normalize_model_parameter(person)
path = "data/persons/%s" % person["id"]
params = {}
if force:
params = {"force": True}
return raw.delete(path, params, client=client)


def new_bot(
name,
email,
role="user",
departments=[],
active=True,
expiration_date=None,
client=default,
):
"""
Create a new bot based on given parameters. His access token will be in the
return dict.
Args:
name (str): the name of the bot.
email (str): the email of the bot.
role (str): user, manager, admin (wich match CG artist, Supervisor
and studio manager)
departments (list): The departments for the person.
active (bool): Whether the person is active or not.
expiration_date (str): The expiration date for the bot.
Returns:
dict: Created bot.
"""
bot = raw.post(
"data/persons",
{
"first_name": name,
"last_name": "",
"email": email,
"role": role,
"departments": normalize_list_of_models_for_links(departments),
"active": active,
"expiration_date": expiration_date,
"is_bot": True,
},
client=client,
)
return bot


def update_bot(bot, client=default):
"""
Update a bot.
Args:
bot (dict): The bot dict that needs to be upgraded.
Returns:
dict: The updated bot.
"""
return update_person(bot, client=client)


def remove_bot(bot, force=False, client=default):
"""
Remove given bot from database.
Args:
bot (dict): Bot to remove.
"""
return remove_person(bot, force=force, client=client)


def set_avatar(person, file_path, client=default):
"""
Upload picture and set it as avatar for given person.
Expand Down
2 changes: 1 addition & 1 deletion gazu/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ def remove_metadata_descriptor(
metadata_descriptor = normalize_model_parameter(metadata_descriptor_id)
params = {}
if force:
params = {"force": "true"}
params = {"force": True}
return raw.delete(
"data/projects/%s/metadata-descriptors/%s"
% (project["id"], metadata_descriptor["id"]),
Expand Down
6 changes: 3 additions & 3 deletions gazu/shot.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ def remove_shot(shot, force=False, client=default):
path = "data/shots/%s" % shot["id"]
params = {}
if force:
params = {"force": "true"}
params = {"force": True}
return raw.delete(path, params, client=client)


Expand Down Expand Up @@ -532,7 +532,7 @@ def remove_episode(episode, force=False, client=default):
path = "data/episodes/%s" % episode["id"]
params = {}
if force:
params = {"force": "true"}
params = {"force": True}
return raw.delete(path, params=params, client=client)


Expand All @@ -547,7 +547,7 @@ def remove_sequence(sequence, force=False, client=default):
path = "data/sequences/%s" % sequence["id"]
params = {}
if force:
params = {"force": "true"}
params = {"force": True}
return raw.delete(path, params=params, client=client)


Expand Down
26 changes: 13 additions & 13 deletions gazu/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def all_tasks_for_shot(shot, relations=False, client=default):
shot = normalize_model_parameter(shot)
params = {}
if relations:
params = {"relations": "true"}
params = {"relations": True}
tasks = raw.fetch_all("shots/%s/tasks" % shot["id"], params, client=client)
return sort_by_name(tasks)

Expand All @@ -97,7 +97,7 @@ def all_tasks_for_concept(concept, relations=False, client=default):
concept = normalize_model_parameter(concept)
params = {}
if relations:
params = {"relations": "true"}
params = {"relations": True}
tasks = raw.fetch_all(
"concepts/%s/tasks" % concept["id"], params, client=client
)
Expand All @@ -116,7 +116,7 @@ def all_tasks_for_edit(edit, relations=False, client=default):
edit = normalize_model_parameter(edit)
params = {}
if relations:
params = {"relations": "true"}
params = {"relations": True}
tasks = raw.fetch_all("edits/%s/tasks" % edit["id"], params, client=client)
return sort_by_name(tasks)

Expand All @@ -133,7 +133,7 @@ def all_tasks_for_sequence(sequence, relations=False, client=default):
sequence = normalize_model_parameter(sequence)
params = {}
if relations:
params = {"relations": "true"}
params = {"relations": True}
path = "sequences/%s/tasks" % sequence["id"]
tasks = raw.fetch_all(path, params, client=client)
return sort_by_name(tasks)
Expand All @@ -151,7 +151,7 @@ def all_tasks_for_scene(scene, relations=False, client=default):
scene = normalize_model_parameter(scene)
params = {}
if relations:
params = {"relations": "true"}
params = {"relations": True}
path = "scenes/%s/tasks" % scene["id"]
tasks = raw.fetch_all(path, params, client=client)
return sort_by_name(tasks)
Expand All @@ -169,7 +169,7 @@ def all_tasks_for_asset(asset, relations=False, client=default):
asset = normalize_model_parameter(asset)
params = {}
if relations:
params = {"relations": "true"}
params = {"relations": True}
path = "assets/%s/tasks" % asset["id"]
tasks = raw.fetch_all(path, params, client=client)
return sort_by_name(tasks)
Expand All @@ -183,7 +183,7 @@ def all_tasks_for_episode(episode, relations=False, client=default):
episode = normalize_model_parameter(episode)
params = {}
if relations:
params = {"relations": "true"}
params = {"relations": True}
path = "episodes/%s/tasks" % episode["id"]
tasks = raw.fetch_all(path, params, client=client)
return sort_by_name(tasks)
Expand All @@ -197,7 +197,7 @@ def all_shot_tasks_for_sequence(sequence, relations=False, client=default):
sequence = normalize_model_parameter(sequence)
params = {}
if relations:
params = {"relations": "true"}
params = {"relations": True}
path = "sequences/%s/shot-tasks" % sequence["id"]
tasks = raw.fetch_all(path, params, client=client)
return sort_by_name(tasks)
Expand All @@ -211,7 +211,7 @@ def all_shot_tasks_for_episode(episode, relations=False, client=default):
episode = normalize_model_parameter(episode)
params = {}
if relations:
params = {"relations": "true"}
params = {"relations": True}
path = "episodes/%s/shot-tasks" % episode["id"]
tasks = raw.fetch_all(path, params, client=client)
return sort_by_name(tasks)
Expand All @@ -225,7 +225,7 @@ def all_assets_tasks_for_episode(episode, relations=False, client=default):
episode = normalize_model_parameter(episode)
params = {}
if relations:
params = {"relations": "true"}
params = {"relations": True}
path = "episodes/%s/asset-tasks" % episode["id"]
tasks = raw.fetch_all(path, params, client=client)
return sort_by_name(tasks)
Expand Down Expand Up @@ -562,7 +562,7 @@ def remove_task_type(task_type, client=default):
task_type = normalize_model_parameter(task_type)
return raw.delete(
"data/task-types/%s" % task_type["id"],
{"force": "true"},
{"force": True},
client=client,
)

Expand All @@ -577,7 +577,7 @@ def remove_task_status(task_status, client=default):
task_status = normalize_model_parameter(task_status)
return raw.delete(
"data/task-status/%s" % task_status["id"],
{"force": "true"},
{"force": True},
client=client,
)

Expand Down Expand Up @@ -649,7 +649,7 @@ def remove_task(task, client=default):
task (str / dict): The task dict or the task ID.
"""
task = normalize_model_parameter(task)
raw.delete("data/tasks/%s" % task["id"], {"force": "true"}, client=client)
raw.delete("data/tasks/%s" % task["id"], {"force": True}, client=client)


def start_task(task, started_task_status=None, client=default):
Expand Down
Loading

0 comments on commit 2a4ada7

Please sign in to comment.