]> git.ipfire.org Git - ipfire.org.git/commitdiff
people: Show list of recently created user accounts
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 15 Aug 2019 13:36:01 +0000 (14:36 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 15 Aug 2019 13:36:01 +0000 (14:36 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/backend/accounts.py
src/templates/people/modules/accounts-new.html [new file with mode: 0644]
src/templates/people/users.html
src/web/__init__.py
src/web/people.py

index 12cf7e16e9b7b1851d390d863f1b0d2012b9f3b5..6518dd8320998f90aa384cfb4b58e7180a1dbbfe 100644 (file)
@@ -238,6 +238,7 @@ templates_peopledir = $(templatesdir)/people
 
 templates_people_modules_DATA = \
        src/templates/people/modules/accounts-list.html \
+       src/templates/people/modules/accounts-new.html \
        src/templates/people/modules/cdr.html \
        src/templates/people/modules/channels.html \
        src/templates/people/modules/mos.html \
index d68e273986ed9ebe9f394e55b67ad5023790a715..1b59882c5962b38fc778451acbfb87ac6b7cfc94 100644 (file)
@@ -54,7 +54,8 @@ class Accounts(Object):
                logging.info("Successfully authenticated as %s" % self.ldap.whoami_s())
 
        def _query(self, query, attrlist=None, limit=0, search_base=None):
-               logging.debug("Performing LDAP query: %s" % query)
+               logging.debug("Performing LDAP query (%s): %s" \
+                       % (search_base or self.search_base, query))
 
                t = time.time()
 
@@ -78,7 +79,8 @@ class Accounts(Object):
                """
                        Fetches all attributes for the given distinguished name
                """
-               results = self._query("(objectClass=*)", search_base=dn, limit=1)
+               results = self._query("(objectClass=*)", search_base=dn, limit=1,
+                       attrlist=("*", "createTimestamp", "modifyTimestamp"))
 
                for dn, attrs in results:
                        return attrs
@@ -94,6 +96,11 @@ class Accounts(Object):
 
                return Account(self.backend, dn, attrs)
 
+       def get_created_after(self, ts):
+               t = ts.strftime("%Y%m%d%H%M%SZ")
+
+               return self._search("(&(objectClass=person)(createTimestamp>=%s))" % t)
+
        def search(self, query):
                # Search for exact matches
                accounts = self._search(
@@ -322,6 +329,12 @@ class Account(Object):
                for value in self._get_strings(key):
                        yield phonenumbers.parse(value, None)
 
+       def _get_timestamp(self, key):
+               value = self._get_string(key)
+
+               # Parse the timestamp value and returns a datetime object
+               return datetime.datetime.strptime(value, "%Y%m%d%H%M%SZ")
+
        def _modify(self, modlist):
                logging.debug("Modifying %s: %s" % (self.dn, modlist))
 
@@ -540,6 +553,16 @@ class Account(Object):
 
                return groups
 
+       # Created/Modified at
+
+       @property
+       def created_at(self):
+               return self._get_timestamp("createTimestamp")
+
+       @property
+       def modified_at(self):
+               return self._get_timestamp("modifyTimestamp")
+
        # Address
 
        @property
diff --git a/src/templates/people/modules/accounts-new.html b/src/templates/people/modules/accounts-new.html
new file mode 100644 (file)
index 0000000..5898cb7
--- /dev/null
@@ -0,0 +1,5 @@
+{% if accounts %}
+    <h3>{{ _("Recently Created Accounts") }}</h3>
+
+    {% module AccountsList(accounts) %}
+{% end %}
index 512c820144e6e235f6e3d2cf0caaf5721283c8cb..f88410292bb4ad83de19cfc80315a9de80b2c9c2 100644 (file)
@@ -7,7 +7,7 @@
                <div class="col col-md-8">
                        <h1>{{ _("Users") }}</h1>
 
-                       {% module AccountsList() %}
+                       {% module NewAccounts() %}
                </div>
        </div>
 {% end block %}
index af11c98f059916cd4d9499ab05518e16471af2d2..2a1b96f01ef7945a6bd9da90323929bcf0489c31 100644 (file)
@@ -77,6 +77,7 @@ class Application(tornado.web.Application):
                                "CDR"                  : people.CDRModule,
                                "Channels"             : people.ChannelsModule,
                                "MOS"                  : people.MOSModule,
+                               "NewAccounts"          : people.NewAccountsModule,
                                "Password"             : people.PasswordModule,
                                "Registrations"        : people.RegistrationsModule,
                                "SIPStatus"            : people.SIPStatusModule,
index 581ba12097d889b072032b46cd122943c99c89c9..cfbeef01f00630ef1dcd1de61bf28233f574568c 100644 (file)
@@ -358,6 +358,19 @@ class UserPasswdHandler(auth.CacheMixin, base.BaseHandler):
                self.redirect("/users/%s" % account.uid)
 
 
+class NewAccountsModule(ui_modules.UIModule):
+       def render(self, days=14):
+               t = datetime.datetime.utcnow() - datetime.timedelta(days=days)
+
+               # Fetch all accounts created after t
+               accounts = self.backend.accounts.get_created_after(t)
+
+               accounts.sort(key=lambda a: a.created_at, reverse=True)
+
+               return self.render_string("people/modules/accounts-new.html",
+                       accounts=accounts, t=t)
+
+
 class AccountsListModule(ui_modules.UIModule):
        def render(self, accounts=None):
                if accounts is None: