         cb()
 
     checkRequiredAffiliation: (t, cb) ->
-        if not @requiredAffiliation? or
-           isAffiliationAtLeast @actorAffiliation, @requiredAffiliation
+        if @requiredAffiliation?.constructor is Function
+            requiredAffiliation = @requiredAffiliation()
+        else
+            requiredAffiliation = @requiredAffiliation
+
+        if not requiredAffiliation? or
+           isAffiliationAtLeast @actorAffiliation, requiredAffiliation
             cb()
         else
-            cb new errors.Forbidden("Requires affiliation #{@requiredAffiliation} (you are #{@actorAffiliation})")
+            cb new errors.Forbidden("Requires affiliation #{requiredAffiliation} (you are #{@actorAffiliation})")
 
     # Used by Publish operation
     checkPublishModel: (t, cb) ->



class ManageNodeSubscriptions extends PrivilegedOperation
    requiredAffiliation: 'owner'

    privilegedTransaction: (t, cb) ->
        defaultAffiliation = null



class AuthorizeSubscriber extends PrivilegedOperation
    requiredAffiliation: =>
        if @actorAffiliation is 'owner'
            yes
        else if @nodeConfig.channelType is 'topic' and
                @actorAffiliation is 'moderator'
            yes
        else
            no

    privilegedTransaction: (t, cb) ->
        if @req.allow
