From 31ffed9323b8044b6340331ea4b57ac4c887290b Mon Sep 17 00:00:00 2001 From: James Valleroy Date: Wed, 20 Nov 2013 20:45:17 -0500 Subject: [PATCH 1/3] Remove users database and folder. The user db will be generated in firstboot. --- Makefile | 11 +++-------- data/users.sqlite3.distrib | Bin 3072 -> 0 bytes data/users/admin | 1 - 3 files changed, 3 insertions(+), 9 deletions(-) delete mode 100644 data/users.sqlite3.distrib delete mode 100644 data/users/admin diff --git a/Makefile b/Makefile index 3e36fc88e..36e1da9b6 100644 --- a/Makefile +++ b/Makefile @@ -12,8 +12,8 @@ ALL_BUT_GZ=$(subst $(wildcard *.tar.gz),,$(wildcard *)) DATADIR=/usr/share/plinth PYDIR=$(DATADIR)/python/plinth -## Catch-all tagets -default: config dirs template css docs dbs +## Catch-all targets +default: config dirs template css docs all: default predepend: @@ -34,7 +34,7 @@ install: default apache-install freedombox-setup-install cp share/init.d/plinth $(DESTDIR)/etc/init.d install plinth $(DESTDIR)/usr/bin/ mkdir -p $(DESTDIR)/var/lib/plinth/cherrypy_sessions $(DESTDIR)/var/log/plinth $(DESTDIR)/var/run - cp -r data/* $(DESTDIR)/var/lib/plinth + mkdir -p $(DESTDIR)/var/lib/plinth/data rm -f $(DESTDIR)/var/lib/plinth/users/sqlite3.distrib freedombox-setup-install: @@ -47,11 +47,6 @@ uninstall: rm -f $(DESTDIR)/usr/bin/plinth $(DESTDIR)/etc/init.d/plinth \ $(DESTDIR)/usr/share/man/man1/plinth.1.gz $(DESTDIR)/var/run/plinth.pid -dbs: data/users.sqlite3 - -data/users.sqlite3: data/users.sqlite3.distrib - cp data/users.sqlite3.distrib data/users.sqlite3 - dirs: @mkdir -p data/cherrypy_sessions diff --git a/data/users.sqlite3.distrib b/data/users.sqlite3.distrib deleted file mode 100644 index 2d805a1537d2501e6dddf3302a83dd69935d620c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3072 zcmeHH!Ab)$5KT6vV4>%|#`R*M!dkUjL9l9Xy{Ns3l(ajwi@TdP$!bMBh{t}Nzu-rB z@?etfLMiwKX2>L&H}fXsL2`TDj}_1f7b#Qp096pi=$ul7kf)t!FAeLB@zU1!CAPVG zXzy#gPJWO_mWV9L=VpP6odQk)tH2em`o522#YPE8#YHiBmp8rcphpMYi++zjT!21AK{Er Date: Wed, 20 Nov 2013 21:29:28 -0500 Subject: [PATCH 2/3] Remove old cfg.users_dir. Remove old UserStore class. --- cfg.py | 3 +- modules/installed/lib/user_store.py | 108 ---------------------------- plinth.sample.config | 3 +- 3 files changed, 3 insertions(+), 111 deletions(-) diff --git a/cfg.py b/cfg.py index e45f56807..408d3df3d 100644 --- a/cfg.py +++ b/cfg.py @@ -28,7 +28,6 @@ store_file = get_item(parser, 'Path', 'store_file') user_db = get_item(parser, 'Path', 'user_db') status_log_file = get_item(parser, 'Path', 'status_log_file') access_log_file = get_item(parser, 'Path', 'access_log_file') -users_dir = get_item(parser, 'Path', 'users_dir') pidfile = get_item(parser, 'Path', 'pidfile') host = get_item(parser, 'Network', 'host') port = int(get_item(parser, 'Network', 'port')) @@ -38,3 +37,5 @@ main_menu = Menu() if store_file.endswith(".sqlite3"): store_file = os.path.splitext(store_file)[0] +if user_db.endswith(".sqlite3"): + user_db = os.path.splitext(user_db)[0] diff --git a/modules/installed/lib/user_store.py b/modules/installed/lib/user_store.py index a6ba6c20f..595e83893 100644 --- a/modules/installed/lib/user_store.py +++ b/modules/installed/lib/user_store.py @@ -11,7 +11,6 @@ from withsqlite.withsqlite import sqlite_db class UserStore(UserStoreModule, sqlite_db): def __init__(self): - self.data_dir = cfg.users_dir self.db_file = cfg.user_db sqlite_db.__init__(self, self.db_file, autocommit=True, check_same_thread=False) self.__enter__() @@ -64,110 +63,3 @@ class UserStore(UserStoreModule, sqlite_db): def set(self,username=None,user=None): sqlite_db.__setitem__(self,username, user) - -class UserStoreOld(): -#class UserStore(UserStoreModule): - """The user storage is on disk. Rather than slurp the entire - thing, we read from the disk as needed. Writes are immediate, - though. - - TODO: file locking""" - def __init__(self): - self.data_dir = cfg.users_dir - self.users = {} - def sanitize(username): - """Return username with nonalphanumeric/underscore chars - removed. - - TODO: allow international chars in usernames.""" - pass - def attr(self, key, username): - """Return field from username's record. If key does not - exist, don't raise attribute error, just return None. - - User defaults to current. If no current user and none - specified, return none.""" - try: - return self.get(username)[key] - except AttributeError: - return None - - def current(self, name=False): - """Return current user, if there is one, else None. - If name = True, return the username instead of the user.""" - try: - username = cherrypy.session.get(cfg.session_key) - if name: - return username - else: - return self.get(username) - except AttributeError: - return None - - def expert(self, username=None): - """Return True if user username is an expert, else False. - - If username is None, use the current user. If no such user exists, return False.""" - user = self.get(username) - if not user: - return False - return 'expert' in user['groups'] - - def get(self, username=None, reload=False): - """Returns a user instance with the user's info or else None if the user couldn't be found. - - If reload is true, reload from disk, regardless of dict's contents - - If username is None, try current user. If no current user, return None. - - TODO: implement user_store.get reload""" - - if not username: - username = self.current(name=True) - - try: - return self.users[username] - except KeyError: - try: - IF = open(os.path.join(self.data_dir, username), "r") - except IOError: - return None - data = IF.read() - IF.close() - - # We cache the result, and since we assume a system with - # relatively few users and small user data files, we never - # expire those results. If we revisit that assumption, we - # might need some cache expiry. - self.users[username] = User(json.loads(data)) - - return self.users[username] - def exists(self, username): - """Return True if username exists, else False.""" - return username in self.users or os.path.exists(os.path.join(cfg.users_dir, username)) - def get_all(self): - "Returns a list of all the user objects" - usernames = os.listdir(self.data_dir) - for name in usernames: - self.get(name) - return self.users - def set(self, user): - """Set the user data, both in memory and as needed in storage.""" - OF = open(os.path.join(self.data_dir, user['username']), 'w') - OF.write(json.dumps(user)) - OF.close() - def remove(self, user): - """Delete the user from storage and RAM. User can be a user instance or a username.""" - try: - name = user['name'] - except TypeError: - if isinstance(user, basestring): - name = user - else: - raise TypeError - os.unlink(os.path.join(cfg.users_dir, name)) - try: - del self.users[name] - except KeyError: - pass - cfg.log.info("%s deleted %s" % (cherrypy.session.get(cfg.session_key), name)) diff --git a/plinth.sample.config b/plinth.sample.config index 98d85878e..bbd023a23 100644 --- a/plinth.sample.config +++ b/plinth.sample.config @@ -9,12 +9,11 @@ data_dir = %(file_root)s/data log_dir = %(data_dir)s pid_dir = %(data_dir)s python_root = %(file_root)s -users_dir = %(data_dir)s/users server_dir = plinth/ # file locations store_file = %(data_dir)s/store.sqlite3 -user_db = %(users_dir)s +user_db = %(data_dir)s/users.sqlite3 status_log_file = %(log_dir)s/status.log access_log_file = %(log_dir)s/access.log pidfile = %(pid_dir)s/pidfile.pid From 2eb4f8bf1af29a161155835a841519a31b514fe3 Mon Sep 17 00:00:00 2001 From: James Valleroy Date: Wed, 20 Nov 2013 21:37:03 -0500 Subject: [PATCH 3/3] Fix add/edit links in users module. --- modules/installed/system/users.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/installed/system/users.py b/modules/installed/system/users.py index eaf51ae71..b2a7d2578 100644 --- a/modules/installed/system/users.py +++ b/modules/installed/system/users.py @@ -18,7 +18,8 @@ class users(PagePlugin): @cherrypy.expose @require() def index(self): - return self.fill_template(title="Manage Users and Groups", sidebar_right="""Add User
Edit Users""") + sidebar_right = 'Add User
Edit Users' + return self.fill_template(title="Manage Users and Groups", sidebar_right=sidebar_right) class add(FormPlugin, PagePlugin): url = ["/sys/users/add"] @@ -75,7 +76,7 @@ class edit(FormPlugin, PagePlugin): user = User(uname[1]) add_form.html('  %s     ' % add_form.get_checkbox(name=user['username']) + - '%s (%s)
' % + '%s (%s)
' % (user['username'], user['name'], user['username'])) add_form.submit(label=_("Delete User"), name="delete") return add_form.render()