检查 当前用户是否 管理员 isUserAdmin

两种方法:

第一: 查询userGroupList表

select userGroupList  where userGroupList.userId == currentUserId  && userGroupList.groupId == 'Admin'
   

第二: 执行EventSecurity::construct(curuserid()).isUserAdmin()

static void CheckFormTab(FormDataSource _frm,FormTabControl _Tab = null)
{
    FormBuildGroupControl       formBuildGroupControl;
    FormGroupControl c;
    FormGridControl gd;
    Int dataSourceId;

    If (_tab || EventSecurity::construct(curuserid()).isUserAdmin())
    {
        c = _Tab.addControl(FormControlType::TabPage,'RunTimeControlTab');
        c.caption("Security");
        gd = c.addControl(FormControlType::Grid,'RunTimeControlGrid');
        gd.widthMode(1);
        gd.heightMode(1);
        dataSourceId = _frm.id();
        gd.dataSource(dataSourceId);
        gd.addDataField(dataSourceId,fieldnum(NJ_FormSecurity,UserId));
        gd.addDataField(dataSourceId,fieldnum(NJ_FormSecurity,UserName));
        gd.addDataField(dataSourceId,fieldnum(NJ_FormSecurity,Dept));
        gd.addDataField(dataSourceId,fieldnum(NJ_FormSecurity,Remarks));
        If (EventSecurity::construct(curuserid()).isUserAdmin() )
        {
            gd.addDataField(dataSourceId,fieldnum(NJ_FormSecurity,FormName)).allowEdit(false);
            gd.addDataField(dataSourceId,fieldnum(NJ_FormSecurity,Level));
            gd.addDataField(dataSourceId,fieldnum(NJ_FormSecurity,FormAdmin));
            gd.addDataField(dataSourceId,fieldnum(NJ_FormSecurity,EmailAdmin));
        }
    }

}

Static void CheckFormSecurity(FormDataSource _frm,FormName _FormName,FormTabControl tab)
{
    NJ_FormSecurity _Form;

    If (!EventSecurity::construct(curuserid()).isUserAdmin() )
    {
        //Select FirstOnly _Form Where _Form.FormName == this.form().name()
        Select FirstOnly _Form Where _Form.FormName == _FormName
                                && _Form.UserID == CurUserID();
        If (!_Form)
            throw Error("No Right!");
        else
        If (_Form.formadmin == NoYes::Yes)
            NJ_BM::CheckFormTab(_frm,tab);
    }
    else
        NJ_BM::CheckFormTab(_frm,tab);
    //    element.CheckFormTab(tab);
}

posted @ 2012-03-01 11:43  perock  阅读(774)  评论(0编辑  收藏  举报