# All files / src/api authorisation.coffee

54.55% Statements 6/11
100% Branches 0/0
0% Functions 0/3
54.55% Lines 6/11

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    331x
    1x
    1x

    1x

    1x

    1x

     Channel = require("../model/channels").Channel
    logger = require 'winston'
    Q = require "q"

    exports.inGroup = (group, user) ->
      return user.groups.indexOf(group) >= 0

    ##
    # A promise returning function that returns the list
    # of viewable channels for a user.
    ##
    exports.getUserViewableChannels = (user) ->

      # if admin allow all channel
      if exports.inGroup 'admin', user
        return Channel.find({}).exec()
      else
        # otherwise figure out what this user can view
        return Channel.find({ txViewAcl: { $in: user.groups } }).exec()

    ##
    # A promise returning function that returns the list
    # of rerunnable channels for a user.
    ##
    exports.getUserRerunableChannels = (user) ->

      # if admin allow all channel
      if exports.inGroup 'admin', user
        return Channel.find({}).exec()
      else
        # otherwise figure out what this user can rerun
        return Channel.find({ txRerunAcl: { $in: user.groups } }).exec()