def encode_dataset_user(trans, dataset, user): # encode dataset id as usual # encode user id using the dataset create time as the key dataset_hash = trans.security.encode_id(dataset.id) if user is None: user_hash = 'None' else: security = IdEncodingHelper(id_secret=dataset.create_time) user_hash = security.encode_id(user.id) return dataset_hash, user_hash
def encode_with_security(security: IdEncodingHelper, id: Any): return security.encode_id(id)
def test_decoded_database_id_field(security: IdEncodingHelper): decoded_id = 1 id_model = EncodedIdModel(id=decoded_id) assert id_model.id == security.encode_id(decoded_id)