diff --git a/app/coffee/modules/common/attachments.coffee b/app/coffee/modules/common/attachments.coffee
index fb36ccde..05951831 100644
--- a/app/coffee/modules/common/attachments.coffee
+++ b/app/coffee/modules/common/attachments.coffee
@@ -72,10 +72,12 @@ class AttachmentsController extends taiga.Controller
@.attachments.push(data)
@rootscope.$broadcast("attachment:create")
- promise = promise.then null, (data) ->
+ promise = promise.then null, (data) =>
+ @scope.$emit("attachments:size-error") if data.status == 413
index = @.uploadingAttachments.indexOf(attachment)
@.uploadingAttachments.splice(index, 1)
- @confirm.notify("error", null, "We have not been able to upload '#{attachment.name}'.")
+ @confirm.notify("error", "We have not been able to upload '#{attachment.name}'.
+ #{data.data._error_message}")
return @q.reject(data)
return promise
@@ -109,7 +111,8 @@ class AttachmentsController extends taiga.Controller
@.updateCounters()
@rootscope.$broadcast("attachment:edit")
- onError = =>
+ onError = (response) =>
+ $scope.$emit("attachments:size-error") if response.status == 413
@confirm.notify("error")
return @q.reject()
@@ -151,7 +154,7 @@ class AttachmentsController extends taiga.Controller
return not item.is_deprecated
-AttachmentsDirective = ($confirm) ->
+AttachmentsDirective = ($config, $confirm) ->
template = _.template("""
""")
-
link = ($scope, $el, $attrs, $ctrls) ->
$ctrl = $ctrls[0]
$model = $ctrls[1]
@@ -223,6 +228,12 @@ AttachmentsDirective = ($confirm) ->
$ctrl.reorderAttachment(attachment, newIndex)
$ctrl.saveAttachments()
+ showSizeInfo = ->
+ $el.find(".size-info").removeClass("hidden")
+
+ $scope.$on "attachments:size-error", ->
+ showSizeInfo()
+
$el.on "change", ".attachments-header input", (event) ->
files = _.toArray(event.target.files)
return if files.length < 1
@@ -250,7 +261,16 @@ AttachmentsDirective = ($confirm) ->
$el.off()
templateFn = ($el, $attrs) ->
- return template({type: $attrs.type})
+ maxFileSize = $config.get("maxUploadFileSize", null)
+ maxFileSize = sizeFormat(maxFileSize) if maxFileSize
+ maxFileSizeMsg = if maxFileSize then "Maximum upload size is #{maxFileSize}" else "" # TODO: i18n
+
+ ctx = {
+ type: $attrs.type
+ maxFileSize: maxFileSize
+ maxFileSizeMsg: maxFileSizeMsg
+ }
+ return template(ctx)
return {
require: ["tgAttachments", "ngModel"]
@@ -262,7 +282,7 @@ AttachmentsDirective = ($confirm) ->
template: templateFn
}
-module.directive("tgAttachments", ["$tgConfirm", AttachmentsDirective])
+module.directive("tgAttachments", ["$tgConfig", "$tgConfirm", AttachmentsDirective])
AttachmentDirective = ->
diff --git a/app/coffee/modules/resources/attachments.coffee b/app/coffee/modules/resources/attachments.coffee
index f56e82fd..f5ab0421 100644
--- a/app/coffee/modules/resources/attachments.coffee
+++ b/app/coffee/modules/resources/attachments.coffee
@@ -24,7 +24,7 @@ taiga = @.taiga
sizeFormat = @.taiga.sizeFormat
-resourceProvider = ($rootScope, $urls, $model, $repo, $auth, $q) ->
+resourceProvider = ($rootScope, $config, $urls, $model, $repo, $auth, $q) ->
service = {}
service.list = (urlName, objectId, projectId) ->
@@ -38,6 +38,16 @@ resourceProvider = ($rootScope, $urls, $model, $repo, $auth, $q) ->
defered.reject(null)
return defered.promise
+ maxFileSize = $config.get("maxUploadFileSize", null)
+ if maxFileSize and file.size > maxFileSize
+ response = {
+ status: 413,
+ data: _error_message: "'#{file.name}' (#{sizeFormat(file.size)}) is too heavy for our oompa
+ loompas, try it with a smaller than {#{sizeFormat(maxFileSize)})"
+ }
+ defered.reject(response)
+ return defered.promise
+
uploadProgress = (evt) =>
$rootScope.$apply =>
file.status = "in-progress"
@@ -83,5 +93,5 @@ resourceProvider = ($rootScope, $urls, $model, $repo, $auth, $q) ->
module = angular.module("taigaResources")
-module.factory("$tgAttachmentsResourcesProvider", ["$rootScope", "$tgUrls", "$tgModel", "$tgRepo", "$tgAuth",
- "$q", resourceProvider])
+module.factory("$tgAttachmentsResourcesProvider", ["$rootScope", "$tgConfig", "$tgUrls", "$tgModel", "$tgRepo",
+ "$tgAuth", "$q", resourceProvider])
diff --git a/app/coffee/modules/resources/user-settings.coffee b/app/coffee/modules/resources/user-settings.coffee
index c9bfe0b5..aa03b1c2 100644
--- a/app/coffee/modules/resources/user-settings.coffee
+++ b/app/coffee/modules/resources/user-settings.coffee
@@ -21,13 +21,26 @@
taiga = @.taiga
+sizeFormat = @.taiga.sizeFormat
-resourceProvider = ($repo, $http, $urls) ->
+
+resourceProvider = ($config, $repo, $http, $urls, $q) ->
service = {}
- service.changeAvatar = (attachmentModel) ->
+ service.changeAvatar = (file) ->
+ maxFileSize = $config.get("maxUploadFileSize", null)
+ if maxFileSize and file.size > maxFileSize
+ response = {
+ status: 413,
+ data: _error_message: "'#{file.name}' (#{sizeFormat(file.size)}) is too heavy for our oompa
+ loompas, try it with a smaller than {#{sizeFormat(maxFileSize)})"
+ }
+ defered = $q.defer()
+ defered.reject(response)
+ return defered.promise
+
data = new FormData()
- data.append('avatar', attachmentModel)
+ data.append('avatar', file)
options = {
transformRequest: angular.identity,
headers: {'Content-Type': undefined}
@@ -52,4 +65,5 @@ resourceProvider = ($repo, $http, $urls) ->
module = angular.module("taigaResources")
-module.factory("$tgUserSettingsResourcesProvider", ["$tgRepo", "$tgHttp", "$tgUrls", resourceProvider])
+module.factory("$tgUserSettingsResourcesProvider", ["$tgConfig", "$tgRepo", "$tgHttp", "$tgUrls", "$q",
+ resourceProvider])
diff --git a/app/coffee/modules/user-settings/main.coffee b/app/coffee/modules/user-settings/main.coffee
index dddf70f0..c356df27 100644
--- a/app/coffee/modules/user-settings/main.coffee
+++ b/app/coffee/modules/user-settings/main.coffee
@@ -21,6 +21,7 @@
taiga = @.taiga
mixOf = @.taiga.mixOf
+sizeFormat = @.taiga.sizeFormat
module = angular.module("taigaUserSettings")
@@ -32,6 +33,7 @@ class UserSettingsController extends mixOf(taiga.Controller, taiga.PageMixin)
@.$inject = [
"$scope",
"$rootScope",
+ "$tgConfig",
"$tgRepo",
"$tgConfirm",
"$tgResources",
@@ -42,11 +44,15 @@ class UserSettingsController extends mixOf(taiga.Controller, taiga.PageMixin)
"$tgAuth"
]
- constructor: (@scope, @rootscope, @repo, @confirm, @rs, @params, @q, @location, @navUrls, @auth) ->
+ constructor: (@scope, @rootscope, @config, @repo, @confirm, @rs, @params, @q, @location, @navUrls, @auth) ->
@scope.sectionName = "User Profile" #i18n
@scope.project = {}
@scope.user = @auth.getUser()
+ maxFileSize = @config.get("maxUploadFileSize", null)
+ if maxFileSize
+ @scope.maxFileSizeMsg = "[Max, size: #{sizeFormat(maxFileSize)}" # TODO: i18n
+
promise = @.loadInitialData()
promise.then null, @.onInitialDataError.bind(@)
@@ -111,6 +117,9 @@ module.directive("tgUserProfile", ["$tgConfirm", "$tgAuth", "$tgRepo", UserProf
UserAvatarDirective = ($auth, $model, $rs, $confirm) ->
link = ($scope, $el, $attrs) ->
+ showSizeInfo = ->
+ $el.find(".size-info").removeClass("hidden")
+
onSuccess = (response) ->
user = $model.make_model("users", response.data)
$auth.setUser(user)
@@ -120,6 +129,7 @@ UserAvatarDirective = ($auth, $model, $rs, $confirm) ->
$confirm.notify('success')
onError = (response) ->
+ showSizeInfo() if response.status == 413
$el.find('.overlay').hide()
$confirm.notify('error', response.data._error_message)
diff --git a/app/partials/user-profile.jade b/app/partials/user-profile.jade
index 2b4289e5..d675501e 100644
--- a/app/partials/user-profile.jade
+++ b/app/partials/user-profile.jade
@@ -25,8 +25,8 @@ block content
input(type="file", id="avatar-field", class="hidden",
tg-avatar-model="avatarAttachment")
p The image will be cropped to 80x80px.
- span.hidden Maximum upload size is 700Kb
- a.button.button-green.change(title="Maximum upload size is 700Kb") Change
+ span.size-info.hidden(tg-bo-html="maxFileSizeMsg")
+ a.button.button-green.change(tg-bo-title="'Change photo. ' + maxFileSizeMsg") Change
a.use-gravatar Use gravatar image
div.data
diff --git a/conf/main.example.json b/conf/main.example.json
index b71f9e52..5d382492 100644
--- a/conf/main.example.json
+++ b/conf/main.example.json
@@ -5,5 +5,6 @@
"publicRegisterEnabled": true,
"feedbackEnabled": true,
"privacyPolicyUrl": null,
- "termsOfServiceUrl": null
+ "termsOfServiceUrl": null,
+ "maxUploadFileSize": null
}