Skip to content

Commit

Permalink
Merge pull request #6 from smallhacks/dev
Browse files Browse the repository at this point in the history
Merge from Dev
  • Loading branch information
smallhacks authored Aug 22, 2018
2 parents 1b8157d + 4b80631 commit ec913cf
Show file tree
Hide file tree
Showing 16 changed files with 118 additions and 73 deletions.
4 changes: 3 additions & 1 deletion src/client/templates/space/live_feed/live_feed.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<template name="liveFeed">
{{> liveFeedPostSubmit}}
{{#if liveFeedAddPost}}
{{> liveFeedPostSubmit}}
{{/if}}
{{#if newMessages}}
<div class="text-center mb-2">
<button type="button" class="btn btn-outline-primary live-feed--refresh">{{newMessages}} {{_ 'live-feed--notification-panel'}}</button>
Expand Down
5 changes: 4 additions & 1 deletion src/client/templates/space/live_feed/live_feed.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,11 @@ Template.liveFeed.events({

Template.liveFeed.helpers({

liveFeedAddPost: function() {
return Template.parentData(1).space.permissions.liveFeedAddPost || Template.parentData(1).space.userId === Meteor.userId() || Roles.userIsInRole(Meteor.userId(), ['admin']) === true;
},
liveFeedPosts: function() {
return Posts.find({spaceId:Session.get('spaceId'), type:"liveFeed"},{sort: {submitted: -1}});
return Posts.find({type:"liveFeed"},{sort: {submitted: -1}});
},
newMessages: function() { // Check if server posts > client posts (if reactive is on)

Expand Down
2 changes: 1 addition & 1 deletion src/client/templates/space/live_feed/live_feed_post.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ <h6 class="card-title">{{author}}<small class="text-muted ml-1">• {{livestamp
<div class="border border-top-0 rounded-bottom mb-4 p-2 bg-light small">
{{#each comments}}
<div class="border-bottom mb-2 p-1">
{{#if commentEditAllowed}}
{{#if ownComment}}
<a href="#" class="float-right text-secondary" data-toggle="modal" data-target="#live-feed-post--delete-comment-{{this.id}}">x</a>
{{> liveFeedDeleteComment}}
{{/if}}
Expand Down
23 changes: 9 additions & 14 deletions src/client/templates/space/live_feed/live_feed_post.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@ Template.liveFeedPost.helpers({
ownPost:function() {
if (Session.get(Template.parentData().space._id).author === this.author || Template.parentData().space.userId === Meteor.userId() || Roles.userIsInRole(Meteor.userId(), ['admin']) === true)
return true
else
return false
},
ownComment: function() {
if (Session.get(Template.parentData(2).space._id).author === this.author || Template.parentData(2).space.userId === Meteor.userId() || Roles.userIsInRole(Meteor.userId(), ['admin']) === true) {
return true
}
else
return false
},
image: function() {
if (this.fileId && $.inArray(this.fileExt, imageExtensions) != -1)
Expand All @@ -109,20 +118,6 @@ Template.liveFeedPost.helpers({
filePath: function() {
return escape(this.filePath);
},
commentEditAllowed: function() {
if (Template.parentData(2).space.postEditPermissions !== undefined) {
if (Template.parentData(2).space.postEditPermissions === "all" || (Template.parentData(2).space.postEditPermissions === "own" && Session.get(Template.parentData(2).space._id).author === this.author) || Template.parentData(2).space.userId === Meteor.userId() || Roles.userIsInRole(Meteor.userId(), ['admin']) === true)
return true
else
return false
}
else {
if (Session.get(Template.parentData(2).space._id).author === this.author || Template.parentData(2).space.userId === Meteor.userId() || Roles.userIsInRole(Meteor.userId(), ['admin']) === true)
return true
else
return false
}
},
likes: function() {
if (this.likes)
return this.likes.length;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
{{#each categories}}
<option {{selectedOption name}}>{{name}}</option>
{{/each}}
<option style="color:red" value="add-category">{{_ 'live-feed-post-submit--add-category'}}</option>
{{#if liveFeedAddCategory}}
<option style="color:red" value="add-category">{{_ 'live-feed-post-submit--add-category'}}</option>
{{/if}}
</select>
</div>
</div>
Expand Down
6 changes: 3 additions & 3 deletions src/client/templates/space/live_feed/live_feed_post_submit.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ Template.liveFeedPostSubmit.helpers({
if (Session.get('liveFeedCategory') == option)
return 'selected'
},
permissionAddCategories: function(template) {
if (this.space.permissions.addCategories || Roles.userIsInRole(Meteor.userId(), ['admin']) || Meteor.userId() == this.space.userId)
liveFeedAddCategory: function(template) {
if (this.space.permissions.liveFeedAddCategory || Roles.userIsInRole(Meteor.userId(), ['admin']) || Meteor.userId() == this.space.userId)
return true
else
return false
Expand All @@ -175,5 +175,5 @@ Template.liveFeedPostSubmit.helpers({
spaceId: this.space._id,
type: "liveFeed"
}
}
},
});
16 changes: 1 addition & 15 deletions src/client/templates/space/resources/resources_post.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,5 @@ Template.resourcesPost.helpers({
},
filePath: function() {
return escape(this.filePath);
},
commentEditAllowed: function() {
if (Template.parentData(2).space.postEditPermissions !== undefined) {
if (Template.parentData(2).space.postEditPermissions === "all" || (Template.parentData(2).space.postEditPermissions === "own" && Session.get(Template.parentData(2).space._id).author === this.author) || Template.parentData(2).space.userId === Meteor.userId() || Roles.userIsInRole(Meteor.userId(), ['admin']) === true)
return true
else
return false
}
else {
if (Session.get(Template.parentData(2).space._id).author === this.author || Template.parentData(2).space.userId === Meteor.userId() || Roles.userIsInRole(Meteor.userId(), ['admin']) === true)
return true
else
return false
}
},
}
});
17 changes: 0 additions & 17 deletions src/client/templates/space/settings/general_settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,6 @@ Template.generalSettings.events({
else
Session.set('isReactive',true);
},
'click .space-edit--activate-comments': function(e) {
e.preventDefault();

if (this.space.commentsAllowed)
Spaces.update(this.space._id, {$set: {commentsAllowed:false}}, function(error) {
if (error)
alert(TAPi18n.__('error-message')+error.message);
});
else
Spaces.update(this.space._id, {$set: {commentsAllowed:true}}, function(error) {
if (error)
alert(TAPi18n.__('error-message')+error.message);
});
},
'click .space-edit--activate-create-user': function(e) {
e.preventDefault();

Expand Down Expand Up @@ -175,9 +161,6 @@ Template.generalSettings.helpers({
isReactive: function() {
return Session.get('isReactive')
},
commentsAreAllowed: function() {
return this.space.commentsAllowed
},
createUserIsAllowed: function() {
return this.space.createUserAllowed
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ <h6 class="mb-3 mt-4">Permissions</h6>
{{#if isBox}}
<a href="#" class="list-group-item list-group-item-action d-flex permissions-settings--public"><span>Public Space<p class="small text-secondary">Allows anyone to access the contents and interact within this Space without needing an Access Code.</p></span><span class="ml-auto">{{#if space.permissions.public}}<i class="far fa-check-square"></i>{{else}}<i class="far fa-square"></i>{{/if}}</span></a>
{{/if}}
<a href="#" class="list-group-item list-group-item-action d-flex permissions-settings--addCategories"><span>Users can add categories in Live Feed</span><span class="ml-auto">{{#if space.permissions.addCategories}}<i class="far fa-check-square"></i>{{else}}<i class="far fa-square"></i>{{/if}}</span></a>
<a href="#" class="list-group-item list-group-item-action d-flex permissions-settings--liveFeedAddCategory"><span>Users can add categories in Live Feed</span><span class="ml-auto">{{#if space.permissions.liveFeedAddCategory}}<i class="far fa-check-square"></i>{{else}}<i class="far fa-square"></i>{{/if}}</span></a>
<a href="#" class="list-group-item list-group-item-action d-flex permissions-settings--liveFeedAddPost"><span>Users can add posts in Live Feed</span><span class="ml-auto">{{#if space.permissions.liveFeedAddPost}}<i class="far fa-check-square"></i>{{else}}<i class="far fa-square"></i>{{/if}}</span></a>
</div>
</template>
38 changes: 30 additions & 8 deletions src/client/templates/space/settings/permissions_settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,63 @@ Template.permissionsSettings.events({

if (this.space.permissions)
if (this.space.permissions.public) {
Spaces.update(this.space._id, {$set: {permissions:{public:false}}}, function(error) {
Spaces.update(this.space._id, {$set: {"permissions.public":false}}, function(error) {
if (error)
alert(TAPi18n.__('error-message')+error.message);
});
}
else {
Spaces.update(this.space._id, {$set: {permissions:{public:true}}}, function(error) {
Spaces.update(this.space._id, {$set: {"permissions.public":true}}, function(error) {
if (error)
alert(TAPi18n.__('error-message')+error.message);
});
}
else
Spaces.update(this.space._id, {$set: {permissions:{public:true}}}, function(error) {
Spaces.update(this.space._id, {$set: {"permissions.public":true}}, function(error) {
if (error)
alert(TAPi18n.__('error-message')+error.message);
});
},
'click .permissions-settings--addCategories': function(e) {
'click .permissions-settings--liveFeedAddCategory': function(e) {
e.preventDefault();

if (this.space.permissions)
if (this.space.permissions.addCategories) {
Spaces.update(this.space._id, {$set: {permissions:{addCategories:false}}}, function(error) {
if (this.space.permissions.liveFeedAddCategory) {
Spaces.update(this.space._id, {$set: {"permissions.liveFeedAddCategory":false}}, function(error) {
if (error)
alert(TAPi18n.__('error-message')+error.message);
});
}
else {
Spaces.update(this.space._id, {$set: {permissions:{addCategories:true}}}, function(error) {
Spaces.update(this.space._id, {$set: {"permissions.liveFeedAddCategory":true}}, function(error) {
if (error)
alert(TAPi18n.__('error-message')+error.message);
});
}
else
Spaces.update(this.space._id, {$set: {permissions:{addCategories:true}}}, function(error) {
Spaces.update(this.space._id, {$set: {"permissions.liveFeedAddCategory":true}}, function(error) {
if (error)
alert(TAPi18n.__('error-message')+error.message);
});
},
'click .permissions-settings--liveFeedAddPost': function(e) {
e.preventDefault();

if (this.space.permissions)
if (this.space.permissions.liveFeedAddPost) {
Spaces.update(this.space._id, {$set: {"permissions.liveFeedAddPost":false}}, function(error) {
if (error)
alert(TAPi18n.__('error-message')+error.message);
});
}
else {
Spaces.update(this.space._id, {$set: {"permissions.liveFeedAddPost":true}}, function(error) {
if (error)
alert(TAPi18n.__('error-message')+error.message);
});
}
else
Spaces.update(this.space._id, {$set: {"permissions.liveFeedAddPost":true}}, function(error) {
if (error)
alert(TAPi18n.__('error-message')+error.message);
});
Expand Down
4 changes: 2 additions & 2 deletions src/client/templates/space/space_sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<li class="align-middle nav-item sidebar-item w-100 small">
<a class="align-bottom nav-link space-sidebar--filter-live-feed-category pl-1 py-1 text-nowrap text-dark filter-live-feed-category {{selectedLiveFeedCategory}} pl-4 py-2 py-lg-2" data-category="{{name}}" href="#"><span class="align-bottom pl-1" data-category="{{name}}">{{name}}</span>
<span class="align-baseline text-secondary small ml-1" data-category="{{name}}">{{nRefs}}</span>
{{#if permissionAddCategories}}
{{#if ownSpace}}
<a class="align-middle space-sidebar--live-feed-category-edit small ml-2" data-category="{{name}}">
<i class="align-middle fas fa-pencil-alt" data-category="{{name}}"></i>
</a>
Expand All @@ -34,7 +34,7 @@
</li>
{{/each}}
<div class="pl-3 ml-2 mt-1">
{{#if permissionAddCategories}}
{{#if liveFeedAddCategory}}
<a href="#" class="small pt-1 pl-1 font-weight-light" data-toggle="modal" data-target="#liveFeedCategorySubmit">
<span class="pl-1"><i class="fas fa-plus"></i> {{_ 'space-sidebar--add-category'}}</span>
</a>
Expand Down
10 changes: 8 additions & 2 deletions src/client/templates/space/space_sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,14 @@ Template.spaceSidebar.helpers({
resources: function() {
return this.space.resources
},
permissionAddCategories: function() {
if (this.space.permissions.addCategories || Roles.userIsInRole(Meteor.userId(), ['admin']) || Meteor.userId() == this.space.userId)
ownSpace: function() {
if (Meteor.userId() == Template.parentData(2).space.userId || Roles.userIsInRole(Meteor.userId(), ['admin']))
return true
else
return false
},
liveFeedAddCategory: function() {
if (this.space.permissions.liveFeedAddCategory || Roles.userIsInRole(Meteor.userId(), ['admin']) || Meteor.userId() == this.space.userId)
return true
else
return false
Expand Down
6 changes: 2 additions & 4 deletions src/lib/collections/spaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,12 @@ if(Meteor.isServer) {
submitted: new Date(),
visible: true,
codePanel: true,
guestWrite: true,
commentsAllowed:true,
postEditPermissions:"own",
createUserAllowed:true,
liveFeed:true,
lessons:false,
resources:true,
permissions:{public:false}
liveFeedComments:true,
permissions:{public:false, liveFeedAddPost:true, liveFeedAddCategory:false}
});

var spaceId = Spaces.insert(space);
Expand Down
2 changes: 1 addition & 1 deletion src/private/version.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "1.24"
"version": "1.26c"
}
49 changes: 48 additions & 1 deletion src/server/db_updates.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,59 @@ if (Posts.find({type:"home"}) != 0) {
console.log('Checking if categories without "type" attribute exist and updating if so');
if (Categories.find({type:{$exists:false}}).count() > 0) {
console.log('There are categories without "type" attribute');
Categories.update({type:{$exists:false}},{$set:{"type":"liveFeed"}}, function(err) { // Before v1.2, categories was only available for liveFeed
Categories.update({type:{$exists:false}},{$set:{"type":"liveFeed"}}, function(err,res) { // Before v1.2, categories was only available for liveFeed
if (err) {
console.log('Error when updating categories without "type" attribute : '+error.message);
}
else {
console.log('All categories without "order" attribute have been updated.');
console.log(res);
}
});
}


// As of v1.25
// Check if spaces have permissions attributes
console.log('Checking if spaces without "permissions" attribute exist and updating if so');
if (Spaces.find({"permissions":{$exists:false}}).count() > 0) {
console.log('There are spaces without "permissions" attribute');
Spaces.update({"permissions":{$exists:false}},{$set:{"permissions":{"public":false,"liveFeedAddPost":true,"liveFeedAddCategory":false}}}, function(err,res) {
if (err) {
console.log('Error when updating spaces without "permissions" attribute : '+error.message);
}
else {
console.log('All spaces without "permissions" attribute have been updated.');
console.log(res);
}
});
} else {
//Check if spaces have permissions.liveFeedAddPost attributes
console.log('Checking if spaces without "permissions.liveFeedAddPost" attribute exist and updating if so');
if (Spaces.find({"permissions.liveFeedAddPost":{$exists:false}}).count() > 0) {
console.log('There are spaces without "permissions.liveFeedAddPost" attribute');
Spaces.update({"permissions.liveFeedAddPost":{$exists:false}},{$set:{"permissions.liveFeedAddPost":"own"}}, function(err,res) {
if (err) {
console.log('Error when updating spaces without "permissions.liveFeedAddPost" attribute : '+error.message);
}
else {
console.log('All spaces without "permissions.liveFeedAddPost" attribute have been updated.');
console.log(res);
}
});
}
//Check if spaces have permissions.liveFeedAddCategory attributes
console.log('Checking if spaces without "permissions.liveFeedAddCategory" attribute exist and updating if so');
if (Spaces.find({"permissions.liveFeedAddCategory":{$exists:false}}).count() > 0) {
console.log('There are spaces without "permissions.liveFeedAddCategory" attribute');
Spaces.update({"permissions.liveFeedAddCategory":{$exists:false}},{$set:{"permissions.liveFeedAddCategory":false}}, function(err,res) {
if (err) {
console.log('Error when updating spaces without "permissions.liveFeedAddCategory" attribute : '+error.message);
}
else {
console.log('All spaces without "permissions.liveFeedAddCategory" attribute have been updated:');
console.log(res);
}
});
}
}
2 changes: 1 addition & 1 deletion src/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"mailPassword": "",
"mailServer": "",
"public" : {
"isBox": "true",
"isBox": "false",
"prefix": "XX",
"ga": {
"id": ""
Expand Down

0 comments on commit ec913cf

Please sign in to comment.