Ejemplo n.º 1
0
        private async Task RemoveUserGroupCheckPemissionCache(long userGroupId)
        {
            var sql       = @"SELECT oar.ServiceId FROM OperationActionRelation as oar 
INNER JOIN Operation as o on oar.OperationId=o.Id AND o.IsDeleted=@IsDeleted
INNER JOIN UserGroupPermission as ugp on o.PermissionId=ugp.PermissionId
WHERE ugp.UserGroupId=@UserGroupId AND TenantId=@TenantId";
            var sqlParams = new Dictionary <string, object>()
            {
                { "IsDeleted", HeroConstants.UnDeletedFlag }, { "UserGroupId", userGroupId }, { "TenantId", _session.TenantId }
            };

            await using (Connection)
            {
                var userGroupServiceIds = await Connection.QueryAsync <string>(sql, sqlParams);

                foreach (var serviceId in userGroupServiceIds)
                {
                    var cacheKey = string.Format(HeroConstants.CacheKey.PermissionCheck, serviceId, "*");
                    await _cacheProvider.RemoveAsync(cacheKey);
                }
            }

            var userGroupRoleIds =
                (await _userGroupRoleRepository.GetAllAsync(p => p.UserGroupId == userGroupId)).Select(p => p.RoleId);

            foreach (var roleId in userGroupRoleIds)
            {
                await _roleDomainService.RemoveRoleCheckPemissionCache(roleId);
            }
        }