Add test log entries to initdb

This commit is contained in:
Joseph Schorr 2013-12-02 19:07:14 -05:00
parent 377d77f52b
commit 91c2ab074a
3 changed files with 36 additions and 3 deletions

View file

@ -1067,9 +1067,9 @@ def list_logs(user_or_organization_name, repository = None):
return joined.where(User.username == user_or_organization_name, LogEntry.datetime >= week_ago).order_by(LogEntry.datetime.desc()) return joined.where(User.username == user_or_organization_name, LogEntry.datetime >= week_ago).order_by(LogEntry.datetime.desc())
def log_action(kind_name, user_or_organization_name, performer=None, repository=None, def log_action(kind_name, user_or_organization_name, performer=None, repository=None,
access_token=None, ip=None, metadata={}): access_token=None, ip=None, metadata={}, datetime=datetime.today()):
kind = LogEntryKind.get(LogEntryKind.name == kind_name) kind = LogEntryKind.get(LogEntryKind.name == kind_name)
account = User.get(User.username == user_or_organization_name) account = User.get(User.username == user_or_organization_name)
entry = LogEntry.create(kind=kind, account=account, performer=performer, entry = LogEntry.create(kind=kind, account=account, performer=performer,
repository=repository, access_token=access_token, ip=ip, repository=repository, access_token=access_token, ip=ip,
metadata_json=json.dumps(metadata)) metadata_json=json.dumps(metadata), datetime=datetime)

View file

@ -247,6 +247,37 @@ def populate_database():
build.status_url = 'http://localhost:5000/test/build/status' build.status_url = 'http://localhost:5000/test/build/status'
build.save() build.save()
today = datetime.today()
week_ago = today - timedelta(6)
six_ago = today - timedelta(5)
four_ago = today - timedelta(4)
model.log_action('org_create_team', org.username, performer=new_user_1, datetime=week_ago,
metadata={'team': 'readers'})
model.log_action('org_set_team_role', org.username, performer=new_user_1, datetime=week_ago,
metadata={'team': 'readers', 'role': 'read'})
model.log_action('create_repo', org.username, performer=new_user_1, repository=org_repo, datetime=week_ago,
metadata={'namespace': org.username, 'name': 'orgrepo'})
model.log_action('change_repo_permission', org.username, performer=new_user_2, repository=org_repo, datetime=six_ago,
metadata={'username': new_user_1.username, 'repo': 'orgrepo', 'role': 'admin'})
model.log_action('change_repo_permission', org.username, performer=new_user_1, repository=org_repo, datetime=six_ago,
metadata={'username': new_user_2.username, 'repo': 'orgrepo', 'role': 'read'})
model.log_action('add_repo_accesstoken', org.username, performer=new_user_1, repository=org_repo, datetime=four_ago,
metadata={'repo': 'orgrepo', 'token': 'deploytoken'})
model.log_action('push_repo', org.username, performer=new_user_2, repository=org_repo, datetime=today,
metadata={'username': new_user_2.username, 'repo': 'orgrepo'})
model.log_action('pull_repo', org.username, performer=new_user_2, repository=org_repo, datetime=today,
metadata={'username': new_user_2.username, 'repo': 'orgrepo'})
model.log_action('pull_repo', org.username, repository=org_repo, datetime=today,
metadata={'token': 'sometoken', 'token_code': 'somecode', 'repo': 'orgrepo'})
if __name__ == '__main__': if __name__ == '__main__':
logging.basicConfig(**app.config['LOGGING_CONFIG']) logging.basicConfig(**app.config['LOGGING_CONFIG'])

View file

@ -819,7 +819,9 @@ quayApp.directive('logsView', function () {
'robot': 'wrench' 'robot': 'wrench'
}; };
log.metadata['_ip'] = log.ip; if (log.ip) {
log.metadata['_ip'] = log.ip;
}
var description = logDescriptions[log.kind] || logTitles[log.kind] || log.kind; var description = logDescriptions[log.kind] || logTitles[log.kind] || log.kind;
if (typeof description != 'string') { if (typeof description != 'string') {