const config = require('lib/config')
const execAll = require('lib/utils/exec-all')

/**
* Privileges are the calculated actions users can make.
*
* These are calculated verifying:
* + Forum Visibility
* + If User is owner of a forum
* + User Role on Topic Permissions
*
*/

var privileges = {
  canEdit: function canEdit (forum, user, topic) {
    if (!config.multiForum && user && user.staff) return true
    if (forum.hasVisibility('collaborative') &&
      (forum.isOwner(user) || forum.hasRole(user, 'admin', 'collaborator')) &&
      forum.hasRole(topic.owner, 'admin', 'collaborator', 'author')) return true
    if (forum.hasRole(user, 'author') && topic.draft) return true
    if (forum.hasVisibility('collaborative') && topic.isOwner(user)) return true
    return false
  },

  canDelete: function canDelete (forum, user, topic) {
    if (!config.multiForum && user && user.staff) return true
    if (forum.isOwner(user) || forum.hasRole(user, 'admin')) return true
    if (forum.hasRole(user, 'author') && topic.draft) return true
    if (forum.hasVisibility('collaborative') && topic.isOwner(user)) return true
    return false
  }
}

/**
 * Retrieve all the privileges of a user on a specific topic.
 */

privileges.all = execAll(privileges)

module.exports = privileges

@@ -403,63 +403,35 @@
 rue%0A
-    if (forum.hasVisibility('collaborative') &&
+%0A    const isAdmin =
 %0A      
-(
 foru
@@ -440,32 +440,38 @@
 isOwner(user) %7C%7C
+%0A     
  forum.hasRole(u
@@ -503,18 +503,78 @@
 or')
-) &&%0A     
+%0A%0A    if (forum.hasVisibility('collaborative')) %7B%0A      if (isAdmin &&
  for
@@ -653,137 +653,153 @@
     
+  
 if (
-forum.hasRole(user, 'author') && topic.draft) return true%0A    if (forum.hasVisibility('collaborative') && topic.isOwner(user)
+topic.isOwner(user)) return true%0A      return false%0A    %7D%0A    if (isAdmin) return true%0A    if (forum.hasRole(user, 'author') && topic.draft
 ) re

fix edit permission