From 3c93326cf13ec4572a960220da6a2b23eccb34ee Mon Sep 17 00:00:00 2001 From: Zachary Huff Date: Thu, 22 Oct 2015 03:27:33 -0400 Subject: [PATCH] Add network link to user --- pritunl/user/user.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/pritunl/user/user.py b/pritunl/user/user.py index f1b1a6ce2..073db1947 100644 --- a/pritunl/user/user.py +++ b/pritunl/user/user.py @@ -644,3 +644,33 @@ def send_key_email(self, key_link_domain): text_email, html_email, ) + + def add_network_link(self, network): + network = str(ipaddress.IPNetwork(network)) + + self.net_link_collection.update({ + 'user_id': self.id, + 'org_id': self.org_id, + 'network': network, + }, { + 'user_id': self.id, + 'org_id': self.org_id, + 'network': network, + }, upsert=True) + + def remove_network_link(self, network): + self.net_link_collection.remove({ + 'user_id': self.id, + 'org_id': self.org_id, + 'network': network, + }) + + def get_network_links(self): + links = [] + + for doc in self.net_link_collection.find({ + 'user_id': self.id, + }): + links.append(doc['network']) + + return links