librelist archives

« back to archive

[bamboo]为user模型添加权限相关API

[bamboo]为user模型添加权限相关API

From:
Uno Young
Date:
2012-03-29 @ 03:56
  addPerm = function(self, ...)
    local perms = {...}
    for _, perm in ipairs(perms) do
      local ps = Perm:filter(function(u) return u.name:startsWith(perm) end)
      for _, p in ipairs(ps) do
        self:addForeign('perms', p)
      end
    end
  end;

  hasPerm = function(self, ...)
    local perms = {...}
    for _, perm in ipairs(perms) do
      local ps = Perm:filter(function(u) return u.name:startsWith(perm) end)
      for _, p in ipairs(ps) do
        if not self:hasForeign('perms', p) then
          return false
        end
      end
    end
    return true
  end;

Re: [bamboo]为user模型添加权限相关API

From:
Tang Daogang
Date:
2012-03-30 @ 02:47
已合并。

2012/3/29 Uno Young <littlehaker@gmail.com>

>   addPerm = function(self, ...)
>     local perms = {...}
>     for _, perm in ipairs(perms) do
>       local ps = Perm:filter(function(u) return u.name:startsWith(perm)
> end)
>       for _, p in ipairs(ps) do
>         self:addForeign('perms', p)
>       end
>     end
>   end;
>
>   hasPerm = function(self, ...)
>     local perms = {...}
>     for _, perm in ipairs(perms) do
>       local ps = Perm:filter(function(u) return u.name:startsWith(perm)
> end)
>       for _, p in ipairs(ps) do
>         if not self:hasForeign('perms', p) then
>           return false
>         end
>       end
>     end
>     return true
>   end;
>



-- 
Nothing is impossible.