Skip to content

Commit

Permalink
Don't allow duplicate config backup uploads.
Browse files Browse the repository at this point in the history
  • Loading branch information
schakrava committed Jul 31, 2015
1 parent 7733140 commit d2cd6e3
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions conf/settings.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ MEDIA_URL = ''
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = os.path.join('${buildout:depdir}', 'static')
STATIC_ROOT = 'static'

# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
Expand All @@ -95,7 +95,7 @@ MEDIA_URL = '/media/'

# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
MEDIA_ROOT = os.path.join(STATIC_ROOT, 'config-backups')
MEDIA_ROOT = os.path.join('${buildout:depdir}', 'static')

# Additional locations of static files
#STATICFILES_DIRS = (
Expand Down
2 changes: 1 addition & 1 deletion src/rockstor/storageadmin/models/config_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ConfigBackup(models.Model):
filename = models.CharField(max_length=64)
md5sum = models.CharField(max_length=32, null=True)
size = models.IntegerField(null=True)
config_backup = models.FileField(upload_to='.', null=True)
config_backup = models.FileField(upload_to='config-backups', null=True)

def __unicode__(self):
return "{0}".format(self.filename)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,12 @@ ConfigBackupView = RockstorLayoutView.extend({
xhr.open('POST', '/api/config-backup/file-upload', true);
var _this = this;
xhr.onload = function() {
if (xhr.status < 400) {
if (xhr.status == 200) {
// use jquery here to show success to user
// add to the collection and then rerender
_this.collection.fetch({ reset:true });
} else {
console.log('problem in file upload');
alert(xhr.response);
}
};
xhr.send(formData);
Expand Down
8 changes: 6 additions & 2 deletions src/rockstor/storageadmin/views/config_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def restore_services(ml):
@task()
def restore_config(cbid):
cbo = ConfigBackup.objects.get(id=cbid)
fp = os.path.join(settings.STATIC_ROOT, 'config-backups', cbo.filename)
fp = os.path.join(settings.MEDIA_ROOT, 'config-backups', cbo.filename)
gfo = gzip.open(fp)
lines = gfo.readlines()
sa_ml = json.loads(lines[0])
Expand All @@ -160,7 +160,7 @@ def restore_config(cbid):

class ConfigBackupMixin(object):
serializer_class = ConfigBackupSerializer
cb_dir = os.path.join(settings.STATIC_ROOT, 'config-backups')
cb_dir = os.path.join(settings.MEDIA_ROOT, 'config-backups')

@staticmethod
def _md5sum(fp):
Expand Down Expand Up @@ -273,6 +273,10 @@ def post(self, request, format=None):
with self._handle_exception(request):
filename = request.data['file-name']
file_obj = request.data['file']
if (ConfigBackup.objects.filter(filename=filename).exists()):
msg = ('Config backup(%s) already exists. Uploading a '
'duplicate is not allowed.' % filename)
handle_exception(Exception(msg), request)
cbo = ConfigBackup.objects.create(
filename=filename, config_backup=file_obj
)
Expand Down

0 comments on commit d2cd6e3

Please sign in to comment.