summaryrefslogtreecommitdiffstats
path: root/collections/avatars.js
diff options
context:
space:
mode:
authorMaxime Quandalle <maxime@quandalle.com>2015-06-08 11:47:06 +0200
committerMaxime Quandalle <maxime@quandalle.com>2015-06-09 15:57:45 +0200
commit46cc69153482a6138e1057ece9cec836dd95451e (patch)
tree79a22f159d20dfca8af4b50877ed40a335233763 /collections/avatars.js
parent98d7278d08dabc9e1da5dcd9a9bb968ab369520e (diff)
downloadwekan-46cc69153482a6138e1057ece9cec836dd95451e.tar.gz
wekan-46cc69153482a6138e1057ece9cec836dd95451e.tar.bz2
wekan-46cc69153482a6138e1057ece9cec836dd95451e.zip
Re-factor the avatar system and support avatar uploads
The user is now able to upload an avatar, and pick one in a list. This functionality should eventually be abstracted in a community package but we still need to work on a great public API. We rely on collectionFS to manage uploaded avatars. We also removed bengott:avatar which was trying to solve the wrong problem (namely displaying the avatar, which is as simple as displaying an image), and not a avatar system as it should be. Gravatar support is coming (back) soon. We may also want to have a list of default fun avatars the user can choose instead of uploading its own one.
Diffstat (limited to 'collections/avatars.js')
-rw-r--r--collections/avatars.js27
1 files changed, 27 insertions, 0 deletions
diff --git a/collections/avatars.js b/collections/avatars.js
new file mode 100644
index 00000000..5ca074ee
--- /dev/null
+++ b/collections/avatars.js
@@ -0,0 +1,27 @@
+Avatars = new FS.Collection('avatars', {
+ stores: [
+ new FS.Store.GridFS('avatars')
+ ],
+ filter: {
+ maxSize: 32000,
+ allow: {
+ contentTypes: ['image/*']
+ }
+ }
+});
+
+var isOwner = function(userId, file) {
+ return userId && userId === file.userId;
+};
+
+Avatars.allow({
+ insert: isOwner,
+ update: isOwner,
+ remove: isOwner,
+ download: function() { return true; },
+ fetch: ['userId']
+});
+
+Avatars.files.before.insert(function(userId, doc) {
+ doc.userId = userId;
+});