group bugs and authorization improvements by codex
This commit is contained in:
@@ -23,7 +23,6 @@ class User(UserMixin, db.Model):
|
||||
return result
|
||||
|
||||
def set_password(self, password):
|
||||
print(f"u:{self.name} > {password}")
|
||||
self.password_hash = generate_password_hash(password)
|
||||
|
||||
def check_password(self, password):
|
||||
@@ -52,6 +51,19 @@ class User(UserMixin, db.Model):
|
||||
shared = Shared.query.filter_by(user_id=self.id, listofitem_id=listofitem_id).first()
|
||||
return True if shared else False
|
||||
|
||||
def owns_list(self, listofitem_id):
|
||||
return ListOfItems.query.filter_by(id=listofitem_id, owner_user_id=self.id).first() is not None
|
||||
|
||||
def can_access_list(self, listofitem_id):
|
||||
listofitem = ListOfItems.query.filter_by(id=listofitem_id, is_active=True).first()
|
||||
if not listofitem:
|
||||
return False
|
||||
return listofitem.owner_user_id == self.id or self.shares_in_list(listofitem_id)
|
||||
|
||||
def can_access_item(self, item_id):
|
||||
item = Item.query.get(item_id)
|
||||
return item is not None and self.can_access_list(item.listofitems_id)
|
||||
|
||||
def set_group_id(self, secret):
|
||||
group = Group.query.filter_by(secret=secret).first()
|
||||
if group:
|
||||
@@ -72,7 +84,6 @@ class ListOfItems(db.Model):
|
||||
result[p] = getattr(self, p)
|
||||
result["pending"] = self.items_left()
|
||||
result["total"] = self.items_total()
|
||||
print(result)
|
||||
return result
|
||||
|
||||
def items_left(self):
|
||||
@@ -108,4 +119,3 @@ class Group(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
updated_at = db.Column(db.TIMESTAMP, default=datetime.now(), onupdate=datetime.now(), nullable=False)
|
||||
secret = db.Column(db.String(128))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user