Cleaned up the copied project & got the Google authentication working. A lot of work still needs to be done to add content and allow only certain users access.
This commit is contained in:
@@ -1,2 +1,2 @@
|
||||
import "./tasks.js";
|
||||
import "./users.js";
|
||||
import "./records.js";
|
||||
import "./users.js";
|
||||
|
||||
40
imports/api/records.js
Normal file
40
imports/api/records.js
Normal file
@@ -0,0 +1,40 @@
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import { Mongo } from 'meteor/mongo';
|
||||
import { check } from 'meteor/check';
|
||||
|
||||
export const Records = new Mongo.Collection('records');
|
||||
|
||||
if (Meteor.isServer) {
|
||||
// This code only runs on the server
|
||||
Meteor.publish('records', function() {
|
||||
return Records.find({});
|
||||
});
|
||||
}
|
||||
|
||||
Meteor.methods({
|
||||
// 'tasks.setChecked'(taskId, setChecked) {
|
||||
// check(taskId, String);
|
||||
// check(setChecked, Boolean);
|
||||
//
|
||||
// const task = Tasks.findOne(taskId);
|
||||
// if (task.private && task.owner !== this.userId) {
|
||||
// // If the task is private, make sure only the owner can check it off
|
||||
// throw new Meteor.Error('not-authorized');
|
||||
// }
|
||||
//
|
||||
// Tasks.update(taskId, { $set: { checked: setChecked } });
|
||||
// },
|
||||
// 'tasks.setPrivate'(taskId, setToPrivate) {
|
||||
// check(taskId, String);
|
||||
// check(setToPrivate, Boolean);
|
||||
//
|
||||
// const task = Tasks.findOne(taskId);
|
||||
//
|
||||
// // Make sure only the task owner can make a task private
|
||||
// if (task.owner !== this.userId) {
|
||||
// throw new Meteor.Error('not-authorized');
|
||||
// }
|
||||
//
|
||||
// Tasks.update(taskId, { $set: { private: setToPrivate } });
|
||||
// },
|
||||
});
|
||||
@@ -1,71 +0,0 @@
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import { Mongo } from 'meteor/mongo';
|
||||
import { check } from 'meteor/check';
|
||||
|
||||
export const Tasks = new Mongo.Collection('tasks');
|
||||
|
||||
if (Meteor.isServer) {
|
||||
// This code only runs on the server
|
||||
Meteor.publish('tasks', function tasksPublication() {
|
||||
return Tasks.find({
|
||||
$or: [
|
||||
{ private: { $ne: true } },
|
||||
{ owner: this.userId },
|
||||
],
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Meteor.methods({
|
||||
'tasks.insert'(text) {
|
||||
check(text, String);
|
||||
|
||||
// Make sure the user is logged in before inserting a task
|
||||
if (!this.userId) {
|
||||
throw new Meteor.Error('not-authorized');
|
||||
}
|
||||
|
||||
Tasks.insert({
|
||||
text,
|
||||
createdAt: new Date(),
|
||||
owner: this.userId,
|
||||
username: Meteor.users.findOne(this.userId).username,
|
||||
});
|
||||
},
|
||||
'tasks.remove'(taskId) {
|
||||
check(taskId, String);
|
||||
|
||||
const task = Tasks.findOne(taskId);
|
||||
if (task.private && task.owner !== this.userId) {
|
||||
// If the task is private, make sure only the owner can delete it
|
||||
throw new Meteor.Error('not-authorized');
|
||||
}
|
||||
|
||||
Tasks.remove(taskId);
|
||||
},
|
||||
'tasks.setChecked'(taskId, setChecked) {
|
||||
check(taskId, String);
|
||||
check(setChecked, Boolean);
|
||||
|
||||
const task = Tasks.findOne(taskId);
|
||||
if (task.private && task.owner !== this.userId) {
|
||||
// If the task is private, make sure only the owner can check it off
|
||||
throw new Meteor.Error('not-authorized');
|
||||
}
|
||||
|
||||
Tasks.update(taskId, { $set: { checked: setChecked } });
|
||||
},
|
||||
'tasks.setPrivate'(taskId, setToPrivate) {
|
||||
check(taskId, String);
|
||||
check(setToPrivate, Boolean);
|
||||
|
||||
const task = Tasks.findOne(taskId);
|
||||
|
||||
// Make sure only the task owner can make a task private
|
||||
if (task.owner !== this.userId) {
|
||||
throw new Meteor.Error('not-authorized');
|
||||
}
|
||||
|
||||
Tasks.update(taskId, { $set: { private: setToPrivate } });
|
||||
},
|
||||
});
|
||||
@@ -1,41 +0,0 @@
|
||||
/* eslint-env mocha */
|
||||
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import { Random } from 'meteor/random';
|
||||
import { assert } from 'chai';
|
||||
|
||||
import { Tasks } from './tasks.js';
|
||||
|
||||
if (Meteor.isServer) {
|
||||
describe('Tasks', () => {
|
||||
describe('methods', () => {
|
||||
const userId = Random.id();
|
||||
let taskId;
|
||||
|
||||
beforeEach(() => {
|
||||
Tasks.remove({});
|
||||
taskId = Tasks.insert({
|
||||
text: 'test task',
|
||||
createdAt: new Date(),
|
||||
owner: userId,
|
||||
username: 'tmeasday',
|
||||
});
|
||||
});
|
||||
|
||||
it('can delete owned task', () => {
|
||||
// Find the internal implementation of the task method so we can
|
||||
// test it in isolation
|
||||
const deleteTask = Meteor.server.method_handlers['tasks.remove'];
|
||||
|
||||
// Set up a fake method invocation that looks like what the method expects
|
||||
const invocation = { userId };
|
||||
|
||||
// Run the method with `this` set to the fake invocation
|
||||
deleteTask.apply(invocation, [taskId]);
|
||||
|
||||
// Verify that the method does what we expected
|
||||
assert.equal(Tasks.find().count(), 0);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user