Neue Verwaltung der Gruppenzuordnung 1:n
This commit is contained in:
1 parent
fa02a7ade0
commit
02c017d53d
34 files changed
+1306
-251
No files matched your search
@@ -25,16 +25,44 @@ class GroupModel:
|
||||
def get_by_account_id(account_id, tenant_id):
|
||||
db = get_db()
|
||||
return db.execute(
|
||||
'SELECT * FROM groups WHERE account_id = ? AND tenant_id = ?',
|
||||
'''SELECT g.* FROM groups g
|
||||
JOIN group_accounts ga
|
||||
ON ga.group_id = g.id AND ga.tenant_id = g.tenant_id
|
||||
WHERE ga.account_id = ? AND g.tenant_id = ?''',
|
||||
(account_id, tenant_id)
|
||||
).fetchone()
|
||||
|
||||
|
||||
@staticmethod
|
||||
def create(tenant_id, aliasname, account_id=None, state='offen'):
|
||||
def get_account_ids_for_group(group_id, tenant_id):
|
||||
db = get_db()
|
||||
rows = db.execute(
|
||||
'''SELECT account_id FROM group_accounts
|
||||
WHERE group_id = ? AND tenant_id = ?
|
||||
ORDER BY account_id''',
|
||||
(group_id, tenant_id)
|
||||
).fetchall()
|
||||
return [row['account_id'] for row in rows]
|
||||
|
||||
@staticmethod
|
||||
def get_account_ids_by_group(tenant_id):
|
||||
db = get_db()
|
||||
rows = db.execute(
|
||||
'''SELECT group_id, account_id FROM group_accounts
|
||||
WHERE tenant_id = ?
|
||||
ORDER BY group_id, account_id''',
|
||||
(tenant_id,)
|
||||
).fetchall()
|
||||
result = {}
|
||||
for row in rows:
|
||||
result.setdefault(row['group_id'], []).append(row['account_id'])
|
||||
return result
|
||||
|
||||
@staticmethod
|
||||
def create(tenant_id, aliasname, state='offen'):
|
||||
db = get_db()
|
||||
cursor = db.execute(
|
||||
'INSERT INTO groups (tenant_id, aliasname, account_id, state) VALUES (?, ?, ?, ?)',
|
||||
(tenant_id, aliasname, account_id, state)
|
||||
'INSERT INTO groups (tenant_id, aliasname, state) VALUES (?, ?, ?)',
|
||||
(tenant_id, aliasname, state)
|
||||
)
|
||||
db.commit()
|
||||
return cursor.lastrowid
|
||||
@@ -42,7 +70,7 @@ class GroupModel:
|
||||
@staticmethod
|
||||
def update(group_id, tenant_id, **kwargs):
|
||||
db = get_db()
|
||||
allowed = ['aliasname', 'state', 'account_id', 'last_lat', 'last_lon', 'last_pos_at']
|
||||
allowed = ['aliasname', 'state', 'last_lat', 'last_lon', 'last_pos_at']
|
||||
updates = []
|
||||
values = []
|
||||
for k, v in kwargs.items():
|
||||
@@ -59,5 +87,9 @@ class GroupModel:
|
||||
@staticmethod
|
||||
def delete(group_id, tenant_id):
|
||||
db = get_db()
|
||||
db.execute(
|
||||
'DELETE FROM group_accounts WHERE group_id = ? AND tenant_id = ?',
|
||||
(group_id, tenant_id)
|
||||
)
|
||||
db.execute('DELETE FROM groups WHERE id = ? AND tenant_id = ?', (group_id, tenant_id))
|
||||
db.commit()
|
||||
Reference in new issue
Block a user