Skip to content

Commit

Permalink
ActivityLog items:
Browse files Browse the repository at this point in the history
CREATE_ADDON
EDIT_PROPERTIES
EDIT_DESCRIPTIONS
EDIT_CONTRIBUTIONS
ADD_VERSION
EDIT_VERSION
DELETE_VERSION

TODO notes are in place for items that aren't logged.
  • Loading branch information
davedash committed Nov 12, 2010
1 parent 118123e commit 4bb9602
Show file tree
Hide file tree
Showing 16 changed files with 196 additions and 91 deletions.
16 changes: 12 additions & 4 deletions apps/addons/forms.py
Expand Up @@ -5,13 +5,12 @@

import happyforms

import amo
import captcha.fields
from addons.models import Addon
from amo.utils import slug_validator
from tower import ugettext as _
from translations.widgets import TranslationTextInput, TranslationTextarea, TransTextarea
from translations.fields import TranslatedField, PurifiedField, LinkifiedField

import captcha.fields
from translations.widgets import TranslationTextInput, TranslationTextarea


class AddonFormBasic(happyforms.ModelForm):
Expand Down Expand Up @@ -96,6 +95,15 @@ class Meta:

exclude = ('status', )

def save(self):
desc = self.data.get('description')
if desc and desc != unicode(self.instance.description):
amo.log(amo.LOG.EDIT_DESCRIPTIONS, self.instance)
if self.changed_data:
amo.log(amo.LOG.EDIT_PROPERTIES, self.instance)

super(AddonForm, self).save()


class AbuseForm(happyforms.Form):
recaptcha = captcha.fields.ReCaptchaField(label='')
Expand Down
19 changes: 1 addition & 18 deletions apps/addons/models.py
@@ -1,5 +1,5 @@
import collections
from datetime import date, datetime
from datetime import date
import itertools
import json
import time
Expand All @@ -11,7 +11,6 @@

import caching.base as caching
import commonware.log
import mongoengine
from tower import ugettext_lazy as _

import amo.models
Expand Down Expand Up @@ -952,22 +951,6 @@ class Meta:
db_table = 'appsupport'


class AddonLog(mongoengine.Document):
"""A MongoDB model for logging add-on changes"""

# TODO XXX Schema is in bug 592590
blah = mongoengine.StringField(max_length=500, required=True)
created = mongoengine.DateTimeField(default=datetime.now)

@staticmethod
def log(sender, request, **kw):
# Grab request.user, ask the cls param how to format the record, turn
# objects into (model.__class__, pk) pairs for serialization, store all
# the pieces in mongo (along with the context needed to format the log
# record).
pass


class PerformanceAppversions(amo.models.ModelBase):
"""Add-on performance appversions. This table is pretty much the same as
`appversions` but is separate because we need to push the perf stuff now
Expand Down
44 changes: 32 additions & 12 deletions apps/amo/log.py
Expand Up @@ -25,6 +25,7 @@ class EDIT_DESCRIPTIONS:
format = _(u'{user.name} edited addon {addon} description')


# TODO(gkoberger): Log this type
class EDIT_CATEGORIES:
id = 4
format = _(u'{user.name} edited categories for {addon}')
Expand All @@ -49,47 +50,55 @@ class EDIT_CONTRIBUTIONS:
format = _(u'{user.name} edited contributions for {addon}')


# TODO(gkoberger): Log these types when editing statuses
class SET_INACTIVE:
id = 8
format = _(u'{addon} set inactive')
keep = True


# TODO(gkoberger): Log these types when editing statuses
class UNSET_INACTIVE:
id = 9
format = _(u'{user.name} activated addon {addon}')
keep = True


# TODO(davedash): Log these types when pages are present
class SET_PUBLIC_STATS:
id = 10
format = _(u'{user.name} set stats public for {addon}')
keep = True


# TODO(davedash): Log these types when pages are present
class UNSET_PUBLIC_STATS:
id = 11
format = _(u'{user.name} set stats private for {addon}')
keep = True


# TODO(gkoberger): Log these types when editing statuses
class CHANGE_STATUS:
id = 12
# L10n: {0} is the status
format = _(u'{user.name} changed {addon} status to {0}')
keep = True


# TODO(gkoberger): Do this in 604152
class ADD_PREVIEW:
id = 13
format = _(u'{user.name} added preview to {addon}')


# TODO(gkoberger): Do this in 604152
class EDIT_PREVIEW:
id = 14
format = _(u'{user.name} edited preview for {addon}')


# TODO(gkoberger): Do this in 604152
class DELETE_PREVIEW:
id = 15
format = _(u'{user.name} deleted preview from {addon}')
Expand Down Expand Up @@ -128,25 +137,29 @@ class DELETE_FILE_FROM_VERSION:
format = _(u'File {0} deleted from {version} of {addon}')


# TODO(davedash): When editor tools exist
class APPROVE_VERSION:
id = 21
format = _(u'Version {0.version} of {addon} approved')
keep = True


# TODO(davedash): When editor tools exist
class RETAIN_VERSION:
id = 22
format = _(u'{user.name} retained version {0.version} of {addon}')
keep = True


# TODO(davedash): When editor tools exist
class ESCALATE_VERSION:
id = 23
# L10n: {0.version} is the version of an addon.
format = _(u'{user.name} escalated review of {addon} {0.version}')
keep = True


# TODO(davedash): When editor tools exist
class REQUEST_VERSION:
id = 24
# L10n: {0.version} is the version of an addon.
Expand All @@ -155,12 +168,14 @@ class REQUEST_VERSION:
keep = True


# TODO(gkoberger): When he does 606248
class ADD_TAG:
id = 25
# L10n: {0} is the tag name.
format = _(u'{user.name} added tag {0} to {addon}')


# TODO(gkoberger): When he does 606248
class REMOVE_TAG:
id = 26
# L10n: {0} is the tag name.
Expand All @@ -182,6 +197,7 @@ class ADD_REVIEW:
format = _(u'{review} for {addon} written.')


# TODO(davedash): Add these when we do the admin site
class ADD_RECOMMENDED_CATEGORY:
id = 31
# L10n: {0} is a category name.
Expand Down Expand Up @@ -210,7 +226,7 @@ class ADD_APPVERSION:
id = 35
# L10n: {0} is the application, {1.min/max} is the min/max version of the
# app
format = _(u'addon now supports {0} {1.min}-{1.max}')
format = _(u'{addon} {version} now supports {0} {1.min}-{1.max}')


class CHANGE_USER_WITH_ROLE:
Expand Down Expand Up @@ -261,28 +277,32 @@ class CUSTOM_HTML:
LOG_KEEP = (l.id for l in LOGS if hasattr(l, 'keep'))


def log(request, action, arguments=None):
def log(action, *args):
"""
e.g. amo.log(request, amo.LOG.CREATE_ADDON, []),
amo.log(request, amo.LOG.ADD_FILE_TO_VERSION,
(file, version))
e.g. amo.log(amo.LOG.CREATE_ADDON, []),
amo.log(amo.LOG.ADD_FILE_TO_VERSION, file, version)
"""
from devhub.models import ActivityLog, AddonLog, UserLog
from addons.models import Addon
from users.models import UserProfile
from amo import get_user, logger_log

al = ActivityLog(user=request.amo_user, action=action.id)
al.arguments = arguments
user = get_user()

if not user:
logger_log.warning('Activity log called with no user: %s' % action.id)
return

al = ActivityLog(user=user, action=action.id)
al.arguments = args
al.save()

if not isinstance(arguments, (list, tuple)):
arguments = (arguments,)
for arg in arguments:
for arg in args:
if isinstance(arg, Addon):
AddonLog(addon=arg, activity_log=al).save()
elif isinstance(arg, UserProfile):
# Index by any user who is mentioned as an argument.
UserLog(activity_log=al, user=arg).save()

# Index by every request user
UserLog(activity_log=al, user=request.amo_user).save()
# Index by every user
UserLog(activity_log=al, user=user).save()
21 changes: 11 additions & 10 deletions apps/api/handlers.py
Expand Up @@ -83,9 +83,9 @@ def read(self, request):


class AddonsHandler(BaseHandler):
allowed_methods = ('POST', 'PUT', 'DELETE',)
allowed_methods = ('POST', 'PUT', 'DELETE')
model = Addon
fields = ('id', 'name', 'eula', 'guid',)
fields = ('id', 'name', 'eula', 'guid')
exclude = ('highest_status', 'icon_type')

# Custom handler so translated text doesn't look weird
Expand All @@ -102,15 +102,14 @@ def create(self, request):
if not license_form.is_valid():
return _form_error(license_form)

new_file_form = XPIForm(request.POST, request.FILES)
new_file_form = XPIForm(request, request.POST, request.FILES)

if not new_file_form.is_valid():
return _xpi_form_error(new_file_form, request)

license = license_form.save()

a = new_file_form.create_addon(user=request.amo_user,
license=license)
a = new_file_form.create_addon(license=license)
return a

@check_addon_and_version
Expand All @@ -132,7 +131,7 @@ def delete(self, request, addon):
class ApplicationsVersionsHandler(AnonymousBaseHandler):
model = ApplicationsVersions
allowed_methods = ('GET', )
fields = ('application', 'max', 'min',)
fields = ('application', 'max', 'min')

@classmethod
def application(cls, av):
Expand Down Expand Up @@ -168,7 +167,7 @@ class AnonymousVersionsHandler(AnonymousBaseHandler, BaseVersionHandler):
model = Version
allowed_methods = ('GET',)
fields = ('id', 'addon_id', 'created', 'release_notes', 'version',
'license', 'current', 'apps' )
'license', 'current', 'apps')

def read(self, request, addon_id, version_id=None):
if version_id:
Expand All @@ -185,7 +184,7 @@ def read(self, request, addon_id, version_id=None):


class VersionsHandler(BaseHandler, BaseVersionHandler):
allowed_methods = ('POST', 'PUT', 'DELETE', 'GET',)
allowed_methods = ('POST', 'PUT', 'DELETE', 'GET')
model = Version
fields = AnonymousVersionsHandler.fields
exclude = ('approvalnotes', )
Expand All @@ -200,7 +199,8 @@ def create(self, request, addon):
if not license_form.is_valid():
return _form_error(license_form)

new_file_form = XPIForm(request.POST, request.FILES, addon=addon)
new_file_form = XPIForm(request, request.POST, request.FILES,
addon=addon)

if not new_file_form.is_valid():
return _xpi_form_error(new_file_form, request)
Expand All @@ -220,7 +220,8 @@ def update(self, request, addon, version):
else:
license = version.license

new_file_form = XPIForm(request.PUT, request.FILES, version=version)
new_file_form = XPIForm(request, request.PUT, request.FILES,
version=version)

if not new_file_form.is_valid():
return _xpi_form_error(new_file_form, request)
Expand Down

0 comments on commit 4bb9602

Please sign in to comment.