Skip to content

Commit

Permalink
Merge branch 'timestamps-for-links'
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Kats committed Feb 25, 2021
2 parents e56eb2c + e5edfe7 commit 21750d1
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -5,7 +5,7 @@ python:
- "3.9"
matrix:
include:
- python: "3.9.2"
- python: "3.9"
dist: focal
sudo: true
install:
Expand Down
8 changes: 5 additions & 3 deletions passzero/backend.py
@@ -1,6 +1,8 @@
from datetime import datetime
from typing import Any, Dict, List, Optional, Tuple

from sqlalchemy import func, and_
from sqlalchemy import and_, func
from sqlalchemy.orm.exc import NoResultFound
from sqlalchemy.orm.session import Session
from sqlalchemy.sql.expression import asc

Expand All @@ -11,11 +13,9 @@
from passzero.models import (ApiToken, AuthToken, DecryptedDocument,
EncryptedDocument, Entry, Entry_v2, Entry_v3,
Entry_v4, Entry_v5, Link, Service, User)
from sqlalchemy.orm.exc import NoResultFound

from .utils import base64_encode


UPDATE_LIMIT = 60


Expand Down Expand Up @@ -307,6 +307,8 @@ def edit_link(session: Session, link_id: int, user_key: str, edited_link: dict,
link.contents = l2.contents
# update metadata
link.kdf_salt = l2.kdf_salt
# keep created_at but change modified_at
link.modified_at = datetime.utcnow()
# and save `links`; discard l2
session.commit()
return link
Expand Down
7 changes: 7 additions & 0 deletions passzero/models/links.py
Expand Up @@ -2,6 +2,8 @@
This class provides the model for all links
"""

from datetime import datetime

import msgpack
import nacl.pwhash
import nacl.secret
Expand Down Expand Up @@ -59,6 +61,10 @@ class Link(db.Model):
# metadata fields are not encrypted
version = db.Column(db.Integer, nullable=False)
kdf_salt = db.Column(db.LargeBinary, nullable=False)
# set when the link is created, then not modified on edits
created_at = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
# changed each time the link is edited
modified_at = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)

__mapper_args__ = {
"polymorphic_identity": 1,
Expand Down Expand Up @@ -120,3 +126,4 @@ def encrypt(self, master_key: str, dec_link: dict) -> None:
self.kdf_salt = kdf_salt
self.version = 1
# NOTE: do not use ID from dec_link
# NOTE: do not use created_at from dec_link
4 changes: 2 additions & 2 deletions typescript/links-bundle/App.tsx
Expand Up @@ -192,11 +192,11 @@ class App extends Component<IProps, IState> {
const link = this.state.links[i];
let linkElem = null;
if (link.is_encrypted) {
linkElem = <EncryptedLink link={ (link as IEncryptedLink) } index={ i }
linkElem = <EncryptedLink link={ (link as IEncryptedLink) } key={ `enc-link-${link.id}` } index={ i }
onDecrypt={ this.handleDecrypt }
onDelete={ this.handleDelete }/>;
} else {
linkElem = <DecryptedLink link={ (link as IDecryptedLink) } index={ i }
linkElem = <DecryptedLink link={ (link as IDecryptedLink) } key={ `dec-link-${link.id}` } index={ i }
onDelete={ this.handleDelete }/>;
}
linkElems.push(linkElem);
Expand Down

0 comments on commit 21750d1

Please sign in to comment.