{"action":"created","comment":{"url":"https://api.github.com/repos/HabitRPG/habitrpg/pulls/comments/75361295","id":75361295,"diff_hunk":"@@ -760,6 +770,168 @@ schema.methods.leave = async function leaveGroup (user, keep = 'keep-all') {\n   return await Bluebird.all(promises);\n };\n \n+schema.methods.updateTask = async function updateTask (taskToSync) {\n+  let group = this;\n+  let listOfPromises = [];\n+\n+  let usersToSync = await User.find({_id: { $in: taskToSync.assignedUsers} });\n+\n+  usersToSync.forEach(function syncAssignedUser (user) {\n+    listOfPromises.push(group.syncTask(taskToSync, user));\n+  });\n+\n+  return Bluebird.all(listOfPromises);\n+};\n+\n+schema.methods.syncTask = async function groupSyncTask (taskToSync, user) {\n+  let group = this;\n+  let toSave = [];\n+\n+  if (taskToSync.assignedUsers.indexOf(user._id) === -1) {\n+    taskToSync.assignedUsers.push(user._id);\n+  }\n+\n+  // Sync tags\n+  let userTags = user.tags;\n+  let i = _.findIndex(userTags, {id: group._id});\n+\n+  if (i !== -1) {\n+    if (userTags[i].name !== group.name) {\n+      // update the name - it's been changed since\n+      userTags[i].name = group.name;\n+    }\n+  } else {\n+    userTags.push({\n+      id: group._id,\n+      name: group.name,\n+    });\n+  }\n+\n+  let findQuery = {\n+    linkedTaskId: taskToSync._id,\n+    userId: user._id,\n+    'group.id': group._id,\n+  };\n+\n+  let matchingTask = await Tasks.Task.findOne(findQuery).exec();\n+\n+  if (!matchingTask) { // If the task is new, create it\n+    matchingTask = new Tasks[taskToSync.type](Tasks.Task.sanitize(syncableAttrs(taskToSync)));\n+    matchingTask.group.id = taskToSync.group.id;\n+    matchingTask.userId = user._id;\n+    matchingTask.linkedTaskId = taskToSync._id;\n+    user.tasksOrder[`${taskToSync.type}s`].push(matchingTask._id);\n+  } else {\n+    _.merge(matchingTask, syncableAttrs(taskToSync));\n+    // Make sure the task is in user.tasksOrder\n+    let orderList = user.tasksOrder[`${taskToSync.type}s`];\n+    if (orderList.indexOf(matchingTask._id) === -1 && (matchingTask.type !== 'todo' || !matchingTask.completed)) orderList.push(matchingTask._id);\n+  }\n+\n+  if (!matchingTask.notes) matchingTask.notes = taskToSync.notes; // don't override the notes, but provide it if not provided\n+  if (matchingTask.tags.indexOf(group._id) === -1) matchingTask.tags.push(group._id); // add tag if missing\n+\n+  toSave.push(matchingTask.save(), taskToSync.save(), user.save());\n+  return Bluebird.all(toSave);\n+};\n+\n+schema.methods.unlinkTask = async function groupUnlinkTask (unlinkingTask, user, keep) {\n+  let findQuery = {\n+    linkedTaskId: unlinkingTask._id,\n+    userId: user._id,\n+  };\n+\n+  let assignedUserIndex = unlinkingTask.assignedUsers.indexOf(user._id);\n+  unlinkingTask.assignedUsers.splice(assignedUserIndex, 1);\n+\n+  if (keep === 'keep-all') {\n+    await Tasks.Task.update(findQuery, {\n+      $unset: {'group.id': ''},","path":"website/server/models/group.js","position":119,"original_position":119,"commit_id":"06e9119ce105277fef3b74372e4602804a9d76cb","original_commit_id":"06e9119ce105277fef3b74372e4602804a9d76cb","user":{"login":"TheHollidayInn","id":1253400,"avatar_url":"https://avatars.githubusercontent.com/u/1253400?v=3","gravatar_id":"","url":"https://api.github.com/users/TheHollidayInn","html_url":"https://github.com/TheHollidayInn","followers_url":"https://api.github.com/users/TheHollidayInn/followers","following_url":"https://api.github.com/users/TheHollidayInn/following{/other_user}","gists_url":"https://api.github.com/users/TheHollidayInn/gists{/gist_id}","starred_url":"https://api.github.com/users/TheHollidayInn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TheHollidayInn/subscriptions","organizations_url":"https://api.github.com/users/TheHollidayInn/orgs","repos_url":"https://api.github.com/users/TheHollidayInn/repos","events_url":"https://api.github.com/users/TheHollidayInn/events{/privacy}","received_events_url":"https://api.github.com/users/TheHollidayInn/received_events","type":"User","site_admin":false},"body":"Yea, I just copied from the Challenge function before, no worries. ","created_at":"2016-08-18T18:21:26Z","updated_at":"2016-08-18T18:21:26Z","html_url":"https://github.com/HabitRPG/habitrpg/pull/7887#discussion_r75361295","pull_request_url":"https://api.github.com/repos/HabitRPG/habitrpg/pulls/7887","_links":{"self":{"href":"https://api.github.com/repos/HabitRPG/habitrpg/pulls/comments/75361295"},"html":{"href":"https://github.com/HabitRPG/habitrpg/pull/7887#discussion_r75361295"},"pull_request":{"href":"https://api.github.com/repos/HabitRPG/habitrpg/pulls/7887"}}},"pull_request":{"url":"https://api.github.com/repos/HabitRPG/habitrpg/pulls/7887","id":80720897,"html_url":"https://github.com/HabitRPG/habitrpg/pull/7887","diff_url":"https://github.com/HabitRPG/habitrpg/pull/7887.diff","patch_url":"https://github.com/HabitRPG/habitrpg/pull/7887.patch","issue_url":"https://api.github.com/repos/HabitRPG/habitrpg/issues/7887","number":7887,"state":"open","locked":false,"title":"Groups assign tasks","user":{"login":"TheHollidayInn","id":1253400,"avatar_url":"https://avatars.githubusercontent.com/u/1253400?v=3","gravatar_id":"","url":"https://api.github.com/users/TheHollidayInn","html_url":"https://github.com/TheHollidayInn","followers_url":"https://api.github.com/users/TheHollidayInn/followers","following_url":"https://api.github.com/users/TheHollidayInn/following{/other_user}","gists_url":"https://api.github.com/users/TheHollidayInn/gists{/gist_id}","starred_url":"https://api.github.com/users/TheHollidayInn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TheHollidayInn/subscriptions","organizations_url":"https://api.github.com/users/TheHollidayInn/orgs","repos_url":"https://api.github.com/users/TheHollidayInn/repos","events_url":"https://api.github.com/users/TheHollidayInn/events{/privacy}","received_events_url":"https://api.github.com/users/TheHollidayInn/received_events","type":"User","site_admin":false},"body":"[//]: # (Note: See http://habitica.wikia.com/wiki/Using_Habitica_Git#Pull_Request for more info)\r\n\r\n[//]: # (Put Issue # or URL here, if applicable. This will automatically close the issue if your PR is merged in)\r\nFixes put_issue_url_here\r\n\r\n### Changes\r\n[//]: # (Describe the changes that were made in detail here. Include pictures if necessary)\r\n\r\nThis depends on #7785.\r\n\r\nThis adds the ability for a guild leader to assign and unassign users.\r\n\r\nThis will also create a separate task for assigned users and sync the task when it is updated or deleted.\r\n\r\n\r\n[//]: # (Put User ID in here - found in Settings -> API)\r\n----\r\nUUID: \r\n","created_at":"2016-08-10T01:19:11Z","updated_at":"2016-08-18T18:21:26Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3fc0b3982d98d84ce9594a3cea6f03861b5b4f17","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/HabitRPG/habitrpg/pulls/7887/commits","review_comments_url":"https://api.github.com/repos/HabitRPG/habitrpg/pulls/7887/comments","review_comment_url":"https://api.github.com/repos/HabitRPG/habitrpg/pulls/comments{/number}","comments_url":"https://api.github.com/repos/HabitRPG/habitrpg/issues/7887/comments","statuses_url":"https://api.github.com/repos/HabitRPG/habitrpg/statuses/06e9119ce105277fef3b74372e4602804a9d76cb","head":{"label":"TheHollidayInn:groups-assign-tasks","ref":"groups-assign-tasks","sha":"06e9119ce105277fef3b74372e4602804a9d76cb","user":{"login":"TheHollidayInn","id":1253400,"avatar_url":"https://avatars.githubusercontent.com/u/1253400?v=3","gravatar_id":"","url":"https://api.github.com/users/TheHollidayInn","html_url":"https://github.com/TheHollidayInn","followers_url":"https://api.github.com/users/TheHollidayInn/followers","following_url":"https://api.github.com/users/TheHollidayInn/following{/other_user}","gists_url":"https://api.github.com/users/TheHollidayInn/gists{/gist_id}","starred_url":"https://api.github.com/users/TheHollidayInn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TheHollidayInn/subscriptions","organizations_url":"https://api.github.com/users/TheHollidayInn/orgs","repos_url":"https://api.github.com/users/TheHollidayInn/repos","events_url":"https://api.github.com/users/TheHollidayInn/events{/privacy}","received_events_url":"https://api.github.com/users/TheHollidayInn/received_events","type":"User","site_admin":false},"repo":{"id":31106714,"name":"habitrpg","full_name":"TheHollidayInn/habitrpg","owner":{"login":"TheHollidayInn","id":1253400,"avatar_url":"https://avatars.githubusercontent.com/u/1253400?v=3","gravatar_id":"","url":"https://api.github.com/users/TheHollidayInn","html_url":"https://github.com/TheHollidayInn","followers_url":"https://api.github.com/users/TheHollidayInn/followers","following_url":"https://api.github.com/users/TheHollidayInn/following{/other_user}","gists_url":"https://api.github.com/users/TheHollidayInn/gists{/gist_id}","starred_url":"https://api.github.com/users/TheHollidayInn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TheHollidayInn/subscriptions","organizations_url":"https://api.github.com/users/TheHollidayInn/orgs","repos_url":"https://api.github.com/users/TheHollidayInn/repos","events_url":"https://api.github.com/users/TheHollidayInn/events{/privacy}","received_events_url":"https://api.github.com/users/TheHollidayInn/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/TheHollidayInn/habitrpg","description":"A habit tracker app which treats your goals like a Role Playing Game.","fork":true,"url":"https://api.github.com/repos/TheHollidayInn/habitrpg","forks_url":"https://api.github.com/repos/TheHollidayInn/habitrpg/forks","keys_url":"https://api.github.com/repos/TheHollidayInn/habitrpg/keys{/key_id}","collaborators_url":"https://api.github.com/repos/TheHollidayInn/habitrpg/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/TheHollidayInn/habitrpg/teams","hooks_url":"https://api.github.com/repos/TheHollidayInn/habitrpg/hooks","issue_events_url":"https://api.github.com/repos/TheHollidayInn/habitrpg/issues/events{/number}","events_url":"https://api.github.com/repos/TheHollidayInn/habitrpg/events","assignees_url":"https://api.github.com/repos/TheHollidayInn/habitrpg/assignees{/user}","branches_url":"https://api.github.com/repos/TheHollidayInn/habitrpg/branches{/branch}","tags_url":"https://api.github.com/repos/TheHollidayInn/habitrpg/tags","blobs_url":"https://api.github.com/repos/TheHollidayInn/habitrpg/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/TheHollidayInn/habitrpg/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/TheHollidayInn/habitrpg/git/refs{/sha}","trees_url":"https://api.github.com/repos/TheHollidayInn/habitrpg/git/trees{/sha}","statuses_url":"https://api.github.com/repos/TheHollidayInn/habitrpg/statuses/{sha}","languages_url":"https://api.github.com/repos/TheHollidayInn/habitrpg/languages","stargazers_url":"https://api.github.com/repos/TheHollidayInn/habitrpg/stargazers","contributors_url":"https://api.github.com/repos/TheHollidayInn/habitrpg/contributors","subscribers_url":"https://api.github.com/repos/TheHollidayInn/habitrpg/subscribers","subscription_url":"https://api.github.com/repos/TheHollidayInn/habitrpg/subscription","commits_url":"https://api.github.com/repos/TheHollidayInn/habitrpg/commits{/sha}","git_commits_url":"https://api.github.com/repos/TheHollidayInn/habitrpg/git/commits{/sha}","comments_url":"https://api.github.com/repos/TheHollidayInn/habitrpg/comments{/number}","issue_comment_url":"https://api.github.com/repos/TheHollidayInn/habitrpg/issues/comments{/number}","contents_url":"https://api.github.com/repos/TheHollidayInn/habitrpg/contents/{+path}","compare_url":"https://api.github.com/repos/TheHollidayInn/habitrpg/compare/{base}...{head}","merges_url":"https://api.github.com/repos/TheHollidayInn/habitrpg/merges","archive_url":"https://api.github.com/repos/TheHollidayInn/habitrpg/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/TheHollidayInn/habitrpg/downloads","issues_url":"https://api.github.com/repos/TheHollidayInn/habitrpg/issues{/number}","pulls_url":"https://api.github.com/repos/TheHollidayInn/habitrpg/pulls{/number}","milestones_url":"https://api.github.com/repos/TheHollidayInn/habitrpg/milestones{/number}","notifications_url":"https://api.github.com/repos/TheHollidayInn/habitrpg/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/TheHollidayInn/habitrpg/labels{/name}","releases_url":"https://api.github.com/repos/TheHollidayInn/habitrpg/releases{/id}","deployments_url":"https://api.github.com/repos/TheHollidayInn/habitrpg/deployments","created_at":"2015-02-21T02:07:13Z","updated_at":"2016-01-11T18:43:21Z","pushed_at":"2016-08-17T17:05:40Z","git_url":"git://github.com/TheHollidayInn/habitrpg.git","ssh_url":"git@github.com:TheHollidayInn/habitrpg.git","clone_url":"https://github.com/TheHollidayInn/habitrpg.git","svn_url":"https://github.com/TheHollidayInn/habitrpg","homepage":"habitrpg.com","size":417567,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"develop"}},"base":{"label":"HabitRPG:develop","ref":"develop","sha":"e68c75c80274d64ac236d75258b81acf0609be10","user":{"login":"HabitRPG","id":3834775,"avatar_url":"https://avatars.githubusercontent.com/u/3834775?v=3","gravatar_id":"","url":"https://api.github.com/users/HabitRPG","html_url":"https://github.com/HabitRPG","followers_url":"https://api.github.com/users/HabitRPG/followers","following_url":"https://api.github.com/users/HabitRPG/following{/other_user}","gists_url":"https://api.github.com/users/HabitRPG/gists{/gist_id}","starred_url":"https://api.github.com/users/HabitRPG/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HabitRPG/subscriptions","organizations_url":"https://api.github.com/users/HabitRPG/orgs","repos_url":"https://api.github.com/users/HabitRPG/repos","events_url":"https://api.github.com/users/HabitRPG/events{/privacy}","received_events_url":"https://api.github.com/users/HabitRPG/received_events","type":"Organization","site_admin":false},"repo":{"id":4578898,"name":"habitrpg","full_name":"HabitRPG/habitrpg","owner":{"login":"HabitRPG","id":3834775,"avatar_url":"https://avatars.githubusercontent.com/u/3834775?v=3","gravatar_id":"","url":"https://api.github.com/users/HabitRPG","html_url":"https://github.com/HabitRPG","followers_url":"https://api.github.com/users/HabitRPG/followers","following_url":"https://api.github.com/users/HabitRPG/following{/other_user}","gists_url":"https://api.github.com/users/HabitRPG/gists{/gist_id}","starred_url":"https://api.github.com/users/HabitRPG/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HabitRPG/subscriptions","organizations_url":"https://api.github.com/users/HabitRPG/orgs","repos_url":"https://api.github.com/users/HabitRPG/repos","events_url":"https://api.github.com/users/HabitRPG/events{/privacy}","received_events_url":"https://api.github.com/users/HabitRPG/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/HabitRPG/habitrpg","description":"A habit tracker app which treats your goals like a Role Playing Game.","fork":false,"url":"https://api.github.com/repos/HabitRPG/habitrpg","forks_url":"https://api.github.com/repos/HabitRPG/habitrpg/forks","keys_url":"https://api.github.com/repos/HabitRPG/habitrpg/keys{/key_id}","collaborators_url":"https://api.github.com/repos/HabitRPG/habitrpg/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/HabitRPG/habitrpg/teams","hooks_url":"https://api.github.com/repos/HabitRPG/habitrpg/hooks","issue_events_url":"https://api.github.com/repos/HabitRPG/habitrpg/issues/events{/number}","events_url":"https://api.github.com/repos/HabitRPG/habitrpg/events","assignees_url":"https://api.github.com/repos/HabitRPG/habitrpg/assignees{/user}","branches_url":"https://api.github.com/repos/HabitRPG/habitrpg/branches{/branch}","tags_url":"https://api.github.com/repos/HabitRPG/habitrpg/tags","blobs_url":"https://api.github.com/repos/HabitRPG/habitrpg/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/HabitRPG/habitrpg/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/HabitRPG/habitrpg/git/refs{/sha}","trees_url":"https://api.github.com/repos/HabitRPG/habitrpg/git/trees{/sha}","statuses_url":"https://api.github.com/repos/HabitRPG/habitrpg/statuses/{sha}","languages_url":"https://api.github.com/repos/HabitRPG/habitrpg/languages","stargazers_url":"https://api.github.com/repos/HabitRPG/habitrpg/stargazers","contributors_url":"https://api.github.com/repos/HabitRPG/habitrpg/contributors","subscribers_url":"https://api.github.com/repos/HabitRPG/habitrpg/subscribers","subscription_url":"https://api.github.com/repos/HabitRPG/habitrpg/subscription","commits_url":"https://api.github.com/repos/HabitRPG/habitrpg/commits{/sha}","git_commits_url":"https://api.github.com/repos/HabitRPG/habitrpg/git/commits{/sha}","comments_url":"https://api.github.com/repos/HabitRPG/habitrpg/comments{/number}","issue_comment_url":"https://api.github.com/repos/HabitRPG/habitrpg/issues/comments{/number}","contents_url":"https://api.github.com/repos/HabitRPG/habitrpg/contents/{+path}","compare_url":"https://api.github.com/repos/HabitRPG/habitrpg/compare/{base}...{head}","merges_url":"https://api.github.com/repos/HabitRPG/habitrpg/merges","archive_url":"https://api.github.com/repos/HabitRPG/habitrpg/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/HabitRPG/habitrpg/downloads","issues_url":"https://api.github.com/repos/HabitRPG/habitrpg/issues{/number}","pulls_url":"https://api.github.com/repos/HabitRPG/habitrpg/pulls{/number}","milestones_url":"https://api.github.com/repos/HabitRPG/habitrpg/milestones{/number}","notifications_url":"https://api.github.com/repos/HabitRPG/habitrpg/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/HabitRPG/habitrpg/labels{/name}","releases_url":"https://api.github.com/repos/HabitRPG/habitrpg/releases{/id}","deployments_url":"https://api.github.com/repos/HabitRPG/habitrpg/deployments","created_at":"2012-06-06T22:49:48Z","updated_at":"2016-08-18T15:08:55Z","pushed_at":"2016-08-18T18:18:56Z","git_url":"git://github.com/HabitRPG/habitrpg.git","ssh_url":"git@github.com:HabitRPG/habitrpg.git","clone_url":"https://github.com/HabitRPG/habitrpg.git","svn_url":"https://github.com/HabitRPG/habitrpg","homepage":"https://habitica.com","size":496035,"stargazers_count":4091,"watchers_count":4091,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1716,"mirror_url":null,"open_issues_count":425,"forks":1716,"open_issues":425,"watchers":4091,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/HabitRPG/habitrpg/pulls/7887"},"html":{"href":"https://github.com/HabitRPG/habitrpg/pull/7887"},"issue":{"href":"https://api.github.com/repos/HabitRPG/habitrpg/issues/7887"},"comments":{"href":"https://api.github.com/repos/HabitRPG/habitrpg/issues/7887/comments"},"review_comments":{"href":"https://api.github.com/repos/HabitRPG/habitrpg/pulls/7887/comments"},"review_comment":{"href":"https://api.github.com/repos/HabitRPG/habitrpg/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/HabitRPG/habitrpg/pulls/7887/commits"},"statuses":{"href":"https://api.github.com/repos/HabitRPG/habitrpg/statuses/06e9119ce105277fef3b74372e4602804a9d76cb"}}}}
{"actor":{"display_login":"TheHollidayInn"}}