adds the eventlog table to the database, and the first couple of actions
we gather stats on: 1. new user registrations 2. number of user plugins
This commit is contained in:
Родитель
958b809a6a
Коммит
69997a2246
|
@ -57,7 +57,7 @@ from webob import Request, Response
|
|||
from bespin.config import c
|
||||
from bespin.framework import expose, BadRequest
|
||||
from bespin import vcs, deploy
|
||||
from bespin.database import User, get_project
|
||||
from bespin.database import User, get_project, log_event
|
||||
from bespin.filesystem import NotAuthorized, OverQuota, File, FileNotFound
|
||||
from bespin.utils import send_email_template
|
||||
from bespin import filesystem, queue, plugins
|
||||
|
@ -1043,7 +1043,7 @@ def run_deploy(request, response):
|
|||
taskname="deploy %s" % (project_name)))
|
||||
return response()
|
||||
|
||||
def _plugin_response(response, path=None, plugin_list=None):
|
||||
def _plugin_response(response, path=None, plugin_list=None, log_user=None):
|
||||
response.content_type = "application/json"
|
||||
|
||||
|
||||
|
@ -1053,6 +1053,9 @@ def _plugin_response(response, path=None, plugin_list=None):
|
|||
metadata = dict((plugin.name, plugin.metadata)
|
||||
for plugin in plugin_list)
|
||||
|
||||
if log_user:
|
||||
log_event("userplugin", log_user, len(metadata))
|
||||
|
||||
response.body = simplejson.dumps(metadata)
|
||||
return response()
|
||||
|
||||
|
@ -1098,7 +1101,7 @@ def _get_user_plugin_path(request):
|
|||
@expose(r'^/plugin/register/user$', 'GET', auth=True)
|
||||
def register_user_plugins(request, response):
|
||||
path = _get_user_plugin_path(request)
|
||||
return _plugin_response(response, path)
|
||||
return _plugin_response(response, path, log_user=request.user)
|
||||
|
||||
@expose(r'^/plugin/register/tests$', 'GET', auth=False)
|
||||
def register_test_plugins(request, response):
|
||||
|
|
|
@ -48,7 +48,7 @@ from pathutils import LockError as PULockError, Lock, LockFile
|
|||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy import (Column, PickleType, String, Integer,
|
||||
Boolean, ForeignKey, Binary,
|
||||
DateTime, Text)
|
||||
DateTime, Text, Table)
|
||||
from sqlalchemy.orm import relation
|
||||
from sqlalchemy.exc import DBAPIError
|
||||
from sqlalchemy.schema import UniqueConstraint
|
||||
|
@ -185,6 +185,7 @@ class User(Base):
|
|||
file_location = "/".join(file_location[:levels]) + "/" + file_location
|
||||
|
||||
self.file_location = file_location
|
||||
log_event("newuser", self)
|
||||
|
||||
def __str__(self):
|
||||
return "User[%s id=%s]" % (self.username, self.id)
|
||||
|
@ -748,3 +749,35 @@ class EveryoneSharing(Base):
|
|||
@property
|
||||
def invited_name(self):
|
||||
return 'everyone'
|
||||
|
||||
EventLog = Table('eventlog', Base.metadata,
|
||||
Column('ts', DateTime, default=datetime.now),
|
||||
Column('kind', String(10)),
|
||||
Column('username', String(128), default=None),
|
||||
Column('details', String, default=None),
|
||||
mysql_engine='archive'
|
||||
)
|
||||
|
||||
def log_event(kind, user, details=None):
|
||||
"""Logs an event to the EventLog.
|
||||
|
||||
kind: a 10 character or less string of the event type
|
||||
user: the current user (or None),
|
||||
details: a JSON-encodable object with any details that need to
|
||||
be saved with this event."""
|
||||
if user:
|
||||
username = user.username
|
||||
else:
|
||||
username = None
|
||||
|
||||
if details is not None:
|
||||
details = simplejson.dumps(details)
|
||||
else:
|
||||
details = None
|
||||
|
||||
ins = EventLog.insert().values(kind=kind, username=username,
|
||||
details=details)
|
||||
session = _get_session()
|
||||
conn = session.connection()
|
||||
conn.execute(ins)
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import *
|
||||
from migrate import *
|
||||
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy import (Column, PickleType, String, Integer,
|
||||
Boolean, Binary, Table, ForeignKey,
|
||||
DateTime, func, UniqueConstraint, Text)
|
||||
from sqlalchemy.orm import relation, deferred, mapper, backref
|
||||
from sqlalchemy.exc import DBAPIError
|
||||
from sqlalchemy.orm.exc import NoResultFound
|
||||
|
||||
metadata = MetaData()
|
||||
metadata.bind = migrate_engine
|
||||
|
||||
EventLog = Table('eventlog', Base.metadata,
|
||||
Column('ts', DateTime, default=datetime.now),
|
||||
Column('kind', String(10)),
|
||||
Column('username', String(128), default=None),
|
||||
Column('details', String, default=None),
|
||||
mysql_engine='archive'
|
||||
)
|
||||
|
||||
def upgrade():
|
||||
# Upgrade operations go here. Don't create your own engine; use the engine
|
||||
# named 'migrate_engine' imported from migrate.
|
||||
|
||||
# create_all will check for table existence first
|
||||
metadata.create_all()
|
||||
|
||||
|
||||
def downgrade():
|
||||
# Operations to reverse the above upgrade go here.
|
||||
|
||||
EventLog.drop(bind=migrate_engine)
|
|
@ -40,7 +40,7 @@ from path import path
|
|||
from simplejson import loads
|
||||
|
||||
from bespin import config, plugins, controllers
|
||||
from bespin.database import User, Base
|
||||
from bespin.database import User, Base, EventLog, _get_session
|
||||
from bespin.filesystem import get_project
|
||||
|
||||
from __init__ import BespinTestApp
|
||||
|
@ -212,6 +212,14 @@ def test_user_installed_plugins():
|
|||
assert "BiggerPlugin" in response.body
|
||||
assert "EditablePlugin" in response.body
|
||||
|
||||
data = loads(response.body)
|
||||
assert len(data) == 3
|
||||
s = _get_session()
|
||||
sel = EventLog.select().where(EventLog.c.kind=='userplugin')
|
||||
result = s.connection().execute(sel).fetchall()
|
||||
assert len(result) == 2
|
||||
assert result[-1].details == '3'
|
||||
|
||||
response = app.get("/getscript/file/at/BespinSettings/plugins/MyPlugin.js%3A")
|
||||
assert response.content_type == "text/javascript"
|
||||
assert "someFunction" in response.body
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
import simplejson
|
||||
|
||||
from bespin import config, controllers, auth
|
||||
from bespin.database import User, Base, ConflictError
|
||||
from bespin.database import User, Base, ConflictError, EventLog
|
||||
from bespin.filesystem import get_project
|
||||
|
||||
from bespin.tests import BespinTestApp
|
||||
|
@ -72,6 +72,8 @@ def test_create_new_user():
|
|||
assert len(user.uuid) == 36
|
||||
num_users = s.query(User).count()
|
||||
assert num_users == 1
|
||||
result = s.connection().execute(EventLog.select()).fetchall()
|
||||
assert len(result) == 1
|
||||
|
||||
users = User.find_by_email("bill@bixby.com")
|
||||
assert users[0].username == "BillBixby"
|
||||
|
|
Загрузка…
Ссылка в новой задаче