Skip to content

Commit

Permalink
Merge pull request #75 from mizzao/modules
Browse files Browse the repository at this point in the history
Use npm dependencies and module system
  • Loading branch information
DavidSichau authored Jul 6, 2016
2 parents 749f813 + b4bc6b5 commit 388fa34
Show file tree
Hide file tree
Showing 32 changed files with 756 additions and 693 deletions.
6 changes: 0 additions & 6 deletions .gitmodules

This file was deleted.

7 changes: 7 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
## vNEXT

## v0.9.0 unreleased

* dependencies are imported as npm modules
* Code is rewritten in ecmascript
* used module system to reduce globals
* removed the authentication system, as it added no real security

## v0.8.0

* supports Meteor 1.3
Expand Down
74 changes: 1 addition & 73 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,77 +82,7 @@ You can also use `db.type` of `none` to have all documents and operations in mem

### Meteor User-Accounts Integration

In case you are using Mongo to mirror the internal sharejs DB with an external Meteor collection as in the user-accounts demo app (find it [here](https://github.com/kbdaitch/meteor-documents-demo) deployed on [meteor](http://documents-users.meteor.com)), both authorization and authentication are available using the [ShareJS auth mechanism](https://github.com/share/ShareJS/wiki/User-access-control).

The use of this feature becomes effective if you store addional metadata such as owners and invites in the document collection like [here](https://github.com/kbdaitch/meteor-documents-demo/blob/master/client/client.coffee#L22) in the demo app.

Your settings file should look like the following:

```js
{
"sharejs": {
"options": {
"accounts_auth": {
"authorize": {
"collection": "documents",
"token_validations": {
"or": {
"invitedUsers": "is_in_array",
"userId": "is_equal"
}
},
"apply_on": [
"read",
"update",
"create",
"delete"
]
},
"authenticate": {
"collection": "users",
"token_validations": {
"_id": "is_equal"
}
}
}
}
}
}
```

All authorize and authenticate settings are under their respective categories. Please note that both of them are completely optional, however once present, they must have at least a field called `collection`.

* `sharejs.options.accounts_auth.authorize`
* `sharejs.options.accounts_auth.authenticate`

The sub-categories for both define the allowed operations and validation.

* `collection`: database collection to fetch the document/user metadata from.
* `token_validations`: contains the boolean logic and supports the keywords `is_equal`, `isnt_equal`, `is_in_array` and `isnt_in_array`. Both `or` and `and` logical operators can be used, provided at any one level of JSON, there is only one or none of them.
* `apply_on`: you can select operations from [here](https://github.com/share/ShareJS/wiki/User-access-control#actions) `Type` column except `connect` which is reserved for authentication.

### Validations

All validations are run against the token. The client-side of sharejs auth would use `Meteor.userId()` for the token. So, for a returned document from database, the following will check for equality of `userId` and token or presence of token in `invitedUsers`.

```js
"token_validations": {
"or": {
"userId": "is_equal",
"invitedUsers": "is_in_array"
}
}
```

### Authentication

Usually, the presence of the user in the collection is sufficient for allowing the connection to sharejs. However, criteria such as the following can also be used.

```js
"token_validations": {
"_id": "is_equal"
}
```
The Authorization was removed in version 0.9.0, because the current implementation did not added any security as `Meteor.userId` is not a secret token.

## Advanced

Expand All @@ -161,9 +91,7 @@ You can access the [ShareJS Server API](https://github.com/share/ShareJS/wiki/Se
## Notes

- When using the default mongo driver, you must not use collections called `docs` or `ops`. [These are used by ShareJS](https://github.com/share/ShareJS/blob/v0.6.2/src/server/db/mongo.coffee).
- When not using accounts integration, ShareJS is agnostic to the Meteor users, and doesn't keep track of who did what op. The document ids are used for access.
- It's best to create a `Meteor.Collection` for your documents which generates good unique ids to connect to ShareJS with. Use these to render the templates above. See the [demo](demo) for examples.
- Importing ace dependencies is somewhat unsatisfactory. Waiting for improvements to Meteor package management system.

Please submit pull requests for better features and cooperation!

Expand Down
6 changes: 4 additions & 2 deletions demo/.meteor/packages
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
autopublish
insecure
standard-app-packages
coffeescript
stylus
mizzao:sharejs-ace
mizzao:sharejs
mizzao:sharejs-codemirror
mizzao:sharejs-ace
twbs:bootstrap
standard-minifiers
modules
ecmascript
7 changes: 3 additions & 4 deletions demo/.meteor/versions
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ [email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
Expand All @@ -39,9 +38,9 @@ [email protected]
[email protected]
[email protected]
[email protected]
mizzao:sharejs@0.8.0
mizzao:sharejs-ace@1.3.0
mizzao:sharejs-codemirror@4.12.1
mizzao:sharejs@0.9.0
mizzao:sharejs-ace@1.4.0
mizzao:sharejs-codemirror@5.14.2
[email protected]
[email protected]
[email protected]
Expand Down
69 changes: 0 additions & 69 deletions demo/client/client.coffee

This file was deleted.

106 changes: 106 additions & 0 deletions demo/client/client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@


Template.docList.helpers({
documents: function() {
return Documents.find();
}
});

Template.docList.events = {
"click button": function() {
return Documents.insert({
title: "untitled"
}, function(err, id) {
if (!id) {
return;
}
return Session.set("document", id);
});
}
};

Template.docItem.helpers({
current: function() {
return Session.equals("document", this._id);
}
});

Template.docItem.events = {
"click a": function(e) {
e.preventDefault();
return Session.set("document", this._id);
}
};

Session.setDefault("editorType", "ace");

Template.docTitle.helpers({
title: function() {
var ref;
return (ref = Documents.findOne(this + "")) != null ? ref.title : void 0;
},
editorType: function(type) {
return Session.equals("editorType", type);
}
});

Template.editor.helpers({
docid: function() {
return Session.get("document");
}
});

Template.editor.events = {
"keydown input[name=title]": function(e) {
var id;
if (e.keyCode !== 13) {
return;
}
e.preventDefault();
$(e.target).blur();
id = Session.get("document");
return Documents.update(id, {
title: e.target.value
});
},
"click button": function(e) {
var id;
e.preventDefault();
id = Session.get("document");
Session.set("document", null);
return Meteor.call("deleteDocument", id);
},
"change input[name=editor]": function(e) {
return Session.set("editorType", e.target.value);
}
};

Template.editor.helpers({
textarea: function() {
return Session.equals("editorType", "textarea");
},
cm: function() {
return Session.equals("editorType", "cm");
},
ace: function() {
return Session.equals("editorType", "ace");
},
configAce: function() {
return function(ace) {
ace.setTheme('ace/theme/monokai');
ace.setShowPrintMargin(false);
return ace.getSession().setUseWrapMode(true);
};
},
configCM: function() {
return function(cm) {
cm.setOption("theme", "default");
cm.setOption("lineNumbers", true);
cm.setOption("lineWrapping", true);
cm.setOption("smartIndent", true);
return cm.setOption("indentWithTabs", true);
};
}
});


1 change: 1 addition & 0 deletions demo/client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
{{> docList}}
</div>
<div class="col-xs-9 editor-container full-height">
<script src="https://cdn.jsdelivr.net/ace/1.2.3/min/ace.js" type="text/javascript" charset="utf-8"></script>
{{> editor}}
</div>
</div>
Expand Down
6 changes: 0 additions & 6 deletions demo/index.coffee

This file was deleted.

17 changes: 17 additions & 0 deletions demo/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
*
* Created by dsichau on 11.05.16.
*/

import {ShareJS} from 'meteor/mizzao:sharejs';

this.Documents = new Meteor.Collection("documents");

Meteor.methods({
deleteDocument(id){
Documents.remove(id);
if(Meteor.isServer) {
ShareJS.model.delete(id);
}
}
});
23 changes: 0 additions & 23 deletions settings-example.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,6 @@
"db": {
"type": "mongo",
"opsCollectionPerDoc": false
},
"accounts_auth": {
"authorize": {
"collection": "documents",
"token_validations": {
"or": {
"invitedUsers": "is_in_array",
"userId": "is_equal"
}
},
"apply_on": [
"read",
"update",
"create",
"delete"
]
},
"authenticate": {
"collection": "users",
"token_validations": {
"_id": "is_equal"
}
}
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions sharejs-ace/History.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## v1.4.0

* Ace is added as npm dependencie

## v1.3.0

* Support of Meteor 1.3
Expand Down
1 change: 0 additions & 1 deletion sharejs-ace/ace-builds
Submodule ace-builds deleted from 4c1551
Loading

0 comments on commit 388fa34

Please sign in to comment.