Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added settings for file upload type and size limit #1152

Merged
merged 5 commits into from
Oct 19, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .meteor/versions
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ [email protected]
[email protected]
[email protected]
idorecall:[email protected]
jalik:ufs@0.2.9
jalik:[email protected].0
jalik:ufs@0.3.0
jalik:[email protected].1
jparker:[email protected]
jparker:[email protected]
jparker:[email protected]
Expand Down
2 changes: 2 additions & 0 deletions client/lib/fileUpload.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ readAsArrayBuffer = (file, callback) ->
return

readAsDataURL file.file, (fileContent) ->
return unless fileUploadIsValidContentType file.file.type

text = ''

if file.type is 'audio'
Expand Down
3 changes: 3 additions & 0 deletions client/views/app/room.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@ Template.room.helpers
compactView: ->
return 'compact' if Meteor.user()?.settings?.preferences?.compactView

fileUploadAllowedMediaTypes: ->
return RocketChat.settings.get('FileUpload_MediaTypeWhiteList')

Template.room.events
"touchstart .message": (e, t) ->
message = this._arguments[1]
Expand Down
4 changes: 2 additions & 2 deletions client/views/app/room.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ <h2>
<div style="display: flex">
<div class="file">
<i class="octicon octicon-cloud-upload file"></i>
<input type="file" accept="image/*">
<input type="file" accept="{{fileUploadAllowedMediaTypes}}">
</div>
<div class="input-message-container">
{{> messagePopupConfig getPupupConfig}}
Expand Down Expand Up @@ -152,4 +152,4 @@ <h2>
{{> Template.dynamic template=flexTemplate data=flexData}}
</section>
</div>
</template>
</template>
4 changes: 4 additions & 0 deletions i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@
"Esc_to" : "Esc to",
"False" : "False",
"Favorites" : "Favorites",
"FileUpload" : "File Upload",
"FileUpload_Enabled" : "Enable file upload",
"FileUpload_MaxFileSize" : "Max. size for uploaded files (in bytes)",
"FileUpload_MediaTypeWhiteList" : "Comma-separated Media Type list",
"Follow_social_profiles" : "Follow our social profiles, fork us on github and share your thoughts about the rocket.chat app on our trello board.",
"Forgot_password" : "Forgot your password",
"Fork_it_on_github" : "Fork it on github",
Expand Down
6 changes: 5 additions & 1 deletion i18n/pt.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@
"Esc_to" : "Esc para",
"False" : "Falso",
"Favorites" : "Favoritos",
"FileUpload" : "Upload de Arquivos",
"FileUpload_Enabled" : "Habilitar upload de arquivos",
"FileUpload_MaxFileSize" : "Tamanho máximo dos arquivos (em bytes)",
"FileUpload_MediaTypeWhiteList" : "Lista de tipos de mídia (separados por vírgula)",
"Follow_social_profiles" : "Siga-nos nas redes sociais, faça fork no github e compartilhe suas ideias sobre o app rocket.chat em nosso trello.",
"Forgot_password" : "Esqueceu sua senha",
"Fork_it_on_github" : "Fork it on github",
Expand Down Expand Up @@ -179,7 +183,7 @@
"Message_deleting_not_allowed" : "Exclusão de mensagem não permitido",
"Message_editing_not_allowed" : "Edição de mensagem não permitido",
"Message_editing_blocked" : "Esta mensagem não pode mais ser editada",
"Message_MaxAllowedSize" : "Tamanho máximo de mensagem permitido ",
"Message_MaxAllowedSize" : "Tamanho máximo de mensagem permitido ",
"Message_pinning_not_allowed" : "Não Permitir Fixar Mensagem",
"Message_KeepHistory" : "Manter Histórico de Mensagens",
"Message_removed" : "Mensagem removida",
Expand Down
50 changes: 38 additions & 12 deletions lib/fileUpload.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
if UploadFS?
@fileCollection = new Mongo.Collection 'rocketchat_uploads'

fileCollection.allow
insert: (userId, doc) ->
return userId
Expand All @@ -11,14 +10,41 @@ if UploadFS?
remove: (userId, doc) ->
return userId is doc.userId

Meteor.fileStore = new UploadFS.store.GridFS
collection: fileCollection
name: 'rocketchat_uploads'
collectionName: 'rocketchat_uploads'
filter: new UploadFS.Filter
maxSize: 2097152
contentTypes: ['image/*', 'audio/*']
onFinishUpload: ->
console.log arguments
onRead: (fileId, file, req, res) ->
res.setHeader 'content-disposition', 'download'

fileUploadMediaWhiteList = ->
return _.map(RocketChat.settings.get('FileUpload_MediaTypeWhiteList').split(','), (item) -> return item.trim() )

@fileUploadIsValidContentType = (type) ->
list = fileUploadMediaWhiteList()

if _.contains list, type
return true
else
wildCardGlob = '/*'
wildcards = _.filter list, (item) -> return item.indexOf(wildCardGlob) > 0

if _.contains wildcards, type.replace(/(\/.*)$/, wildCardGlob)
return true;

return false;

initFileStore = ->
Meteor.fileStore = new UploadFS.store.GridFS
collection: fileCollection
name: 'rocketchat_uploads'
collectionName: 'rocketchat_uploads'
filter: new UploadFS.Filter
maxSize: RocketChat.settings.get('FileUpload_MaxFileSize')
contentTypes: fileUploadMediaWhiteList()
onFinishUpload: ->
console.log arguments
onRead: (fileId, file, req, res) ->
res.setHeader 'content-disposition', 'download'

if Meteor.isServer
initFileStore()
else
Tracker.autorun (c) ->
if RocketChat.settings.subscription.ready()
initFileStore()
c.stop()
2 changes: 0 additions & 2 deletions packages/rocketchat-lib/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,11 @@ Package.onUse(function(api) {

api.addFiles('settings/lib/settings.coffee');


// CLIENT
api.addFiles('client/Notifications.coffee', 'client');
api.addFiles('client/TabBar.coffee', 'client');
api.addFiles('client/MessageAction.coffee', 'client');

api.addFiles('settings/client/startup.coffee', 'client');
api.addFiles('settings/client/rocketchat.coffee', 'client');

// SERVER
Expand Down
3 changes: 2 additions & 1 deletion packages/rocketchat-lib/settings/client/rocketchat.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@

settingsDict = new ReactiveDict('settings')

RocketChat.settings.subscription = Meteor.subscribe 'settings'
RocketChat.settings.get = (_id) ->
return settingsDict.get(_id)

RocketChat.settings.onload '*', (key, value) ->
return settingsDict.set key, value
return settingsDict.set key, value
2 changes: 0 additions & 2 deletions packages/rocketchat-lib/settings/client/startup.coffee

This file was deleted.

5 changes: 5 additions & 0 deletions packages/rocketchat-lib/settings/server/startup.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ RocketChat.settings.add 'Accounts_OAuth_Twitter', false, { type: 'boolean', grou
RocketChat.settings.add 'Accounts_OAuth_Twitter_id', '', { type: 'string', group: 'Accounts', section: 'Twitter' }
RocketChat.settings.add 'Accounts_OAuth_Twitter_secret', '', { type: 'string', group: 'Accounts', section: 'Twitter' }

RocketChat.settings.addGroup 'FileUpload'
RocketChat.settings.add 'FileUpload_Enabled', true, { type: 'boolean', group: 'FileUpload', public: true }
RocketChat.settings.add 'FileUpload_MaxFileSize', 2097152, { type: 'int', group: 'FileUpload', public: true }
RocketChat.settings.add 'FileUpload_MediaTypeWhiteList', 'image/*', { type: 'string', group: 'FileUpload', public: true }

RocketChat.settings.addGroup 'General'
RocketChat.settings.add 'Site_Url', __meteor_runtime_config__?.ROOT_URL, { type: 'string', group: 'General', i18nDescription: 'Site_Url_Description', public: true }
RocketChat.settings.add 'Site_Name', 'Rocket.Chat', { type: 'string', group: 'General', public: true }
Expand Down