您的位置:首页 > 其它

删除角色:系统定制员产生的问题和解决方法

2008-05-04 17:38 459 查看
MSCRM3.0系统自带角色中,MS允许删除系统定制员角色,但是删除该角色后出现无法

客户化情况,因为创建实体的时候系统会自动为系统定制员角色赋予权限。系统定制员角色不存在所以就导致无法客户化。

解决方法一:

一、备份数据库

二、创建一个角色 角色名称:系统定制员 业务部门 选择 顶级部门

三、打开查询分析器 运行以下代码

UPDATE RoleBase SET RoleTemplateId = (SELECT RoleTemplateId FROM RoleTemplateBase WHERE Name = '系统定制员')

WHERE RoleTemplateId IS NULL AND Name = '系统定制员'
注:以上方法请不要用于产品环境,不确保不会出现其他问题。

解决方法二:

一、备份数据库

二、打开查询分析器 运行以下代码

create function dbo.GetPrivilegeDepthMask(@isbasic bit, @islocal bit, @isdeep bit, @isglobal bit, @parentRoleId uniqueidentifier)returns int as

2

3begin

4

5declare @mask int

6

7select @mask = 0

8

9

10

11if (@isbasic <> 0)

12

13begin

14

15if (@parentRoleId is null)

16

17begin

18

19select @mask = 1

20

21end

22

23if (@parentRoleId is not null)

24

25begin

26

27select @mask = 0x00000010

28

29end

30

31end

32

33if (@islocal <> 0)

34

35begin

36

37if (@parentRoleId is null)

38

39begin

40

41select @mask = 2

42

43end

44

45if (@parentRoleId is not null)

46

47begin

48

49select @mask = 0x00000020

50

51end

52

53end

54

55if (@isdeep <> 0)

56

57begin

58

59if (@parentRoleId is null)

60

61begin

62

63select @mask = 4

64

65end

66

67if (@parentRoleId is not null)

68

69begin

70

71select @mask = 0x00000040

72

73end

74

75end

76

77if (@isglobal <> 0)

78

79begin

80

81if (@parentRoleId is null)

82

83begin

84

85select @mask = 8

86

87end

88

89if (@parentRoleId is not null)

90

91begin

92

93select @mask = 0x00000080

94

95end

96

97end

98

99

100

101return @mask

102

103end

104

105go

106

107

108

109declare @rootBiz uniqueidentifier

110

111declare @rootId uniqueidentifier

112

113declare @organizationid uniqueidentifier

114

115

116

117declare @roleTemplateId uniqueidentifier

118

119select @roleTemplateId = '119F245C-3CC8-4B62-B31C-D1A046CED15D'

120

121declare @roleTemplateName nvarchar(256)

122

123select @roleTemplateName = Name from RoleTemplateBase where RoleTemplateId = @roleTemplateId

124

125

126

127declare @parentRoleId uniqueidentifier

128

129select @parentRoleId = null

130

131

132

133declare @roleid uniqueidentifier

134

135select @roleid = null

136

137

138

139select @rootBiz = BusinessUnitId from BusinessUnitBase where ParentBusinessUnitId is null

140

141declare c cursor FORWARD_ONLY READ_ONLY for select businessunitid from dbo.GetSubsidiaryBusinesses(@rootBiz) order by depth

142

143open c

144

145fetch next from c into @rootId

146

147while (@@fetch_status = 0)

148

149begin

150

151-- Get ParentRoleId

152

153select @parentRoleId = RoleId from RoleBase where BusinessUnitId = (select ParentBusinessUnitId from BusinessUnitBase where BusinessUnitId = @rootId) and RoleTemplateId = @roleTemplateId select @roleid = RoleId from RoleBase where BusinessUnitId = @rootId and RoleTemplateId = @roleTemplateId

154

155if (@roleid is null)

156

157begin

158

159select @roleid = newid()

160

161insert into RoleBase(RoleId, RoleTemplateId, OrganizationId, DeletionStateCode, Name, BusinessUnitId, CreatedOn, ModifiedOn, CreatedBy, ModifiedBy, ParentRoleId) values(@roleid, @roleTemplateId, @organizationid, 0, @roleTemplateName, @rootId, getutcdate(), getutcdate(), null, null, @parentRoleId)

162

163end

164

165delete from RolePrivileges where RoleId = @roleid

166

167insert into RolePrivileges(RoleId, PrivilegeId, PrivilegeDepthMask)

168

169select @roleid, rtp.PrivilegeId, dbo.GetPrivilegeDepthMask(rtp.IsBasic, rtp.IsLocal, rtp.IsDeep, rtp.IsGlobal, @parentRoleId) from RoleTemplatePrivileges rtp where rtp.RoleTemplateId = @roleTemplateId

170

171fetch next from c into @rootId

172

173select @roleid = null

174

175end

176

177close c

178

179deallocate c
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐