MCPcopy Create free account
hub / github.com/diffgram/diffgram / user_has_credentials_core

Function user_has_credentials_core

default/methods/user/user_has_credentials.py:59–105  ·  view source on GitHub ↗
(session: object,
                              log: dict,
                              user: User,
                              project: Project,
                              task_template_id: int)

Source from the content-addressed store, hash-verified

57
58
59def user_has_credentials_core(session: object,
60 log: dict,
61 user: User,
62 project: Project,
63 task_template_id: int) -> [dict, dict]:
64 if project is None:
65 log['error']['project_id'] = 'Provide project_id'
66 return None, log
67
68 if user is None:
69 log['error']['user_id'] = 'User does not exist'
70 return None, log
71
72 if task_template_id is None:
73 log['error']['task_template_id'] = 'Provide task_template_id'
74 return None, log
75
76 user_credentials = Credential.get_by_user_id(
77 session = session,
78 user_id = user.id
79 )
80 user_credential_type_id_list = [x.credential_type_id for x in user_credentials]
81
82 task_template = Job.get_by_id(session, task_template_id)
83
84 if task_template is None:
85 log['error']['task_template'] = 'Task Template does not exist'
86 return None, log
87
88 required_credentials_rels = Credential_Type_To_Job.get_by_job_id(
89 session = session,
90 job_id = task_template_id,
91 requires_only = True
92 )
93
94 required_credentials = [x.credential_type for x in required_credentials_rels]
95
96 missing_credentials = []
97 for cred in required_credentials:
98 if cred.id not in user_credential_type_id_list:
99 missing_credentials.append(cred)
100
101 result = {
102 'missing_credentials': [x.serialize_for_list_view() for x in missing_credentials],
103 'has_credentials': len(missing_credentials) == 0
104 }
105 return result, log

Callers 1

api_user_has_credentialsFunction · 0.85

Calls 4

get_by_user_idMethod · 0.45
get_by_idMethod · 0.45
get_by_job_idMethod · 0.45

Tested by

no test coverage detected