internal static void ReplaceColumnAccessControls(
     Context context,
     List <ColumnAccessControl> columnAccessControls,
     PermissionIdList permissionIdList)
 {
     columnAccessControls?.ForEach(columnAccessControl =>
     {
         columnAccessControl.Depts = columnAccessControl?.Depts
                                     ?.Select(deptId => Utilities.ConvertedDeptId(
                                                  context: context,
                                                  permissionIdList: permissionIdList,
                                                  deptId: deptId))
                                     .Where(deptId => deptId > 0)
                                     .ToList();
         columnAccessControl.Groups = columnAccessControl?.Groups
                                      ?.Select(groupId => Utilities.ConvertedGroupId(
                                                   context: context,
                                                   permissionIdList: permissionIdList,
                                                   groupId: groupId))
                                      .Where(groupId => groupId > 0)
                                      .ToList();
         columnAccessControl.Users = columnAccessControl?.Users
                                     ?.Select(userId => Utilities.ConvertedUserId(
                                                  context: context,
                                                  permissionIdList: permissionIdList,
                                                  userId: userId))
                                     .Where(userId => userId > 0)
                                     .ToList();
     });
 }
 public SitePackage(
     Context context,
     List <SelectedSite> siteList,
     bool includeSitePermission,
     bool includeRecordPermission,
     bool includeColumnPermission)
 {
     HeaderInfo = new Header(
         context: context,
         includeSitePermission: includeSitePermission,
         includeRecordPermission: includeRecordPermission,
         includeColumnPermission: includeColumnPermission);
     Sites       = new List <PackageSiteModel>();
     Data        = new List <JsonExport>();
     Permissions = new List <PackagePermissionModel>();
     Construct(
         context: context,
         siteList: siteList,
         includeRecordPermission: includeRecordPermission,
         includeColumnPermission: includeColumnPermission);
     if (includeSitePermission)
     {
         PermissionIdList = new PermissionIdList(
             context: context,
             sites: Sites,
             packagePermissionModels: Permissions);
     }
 }
Example #3
0
        public static int ConvertedUserId(
            Context context,
            PermissionIdList permissionIdList,
            int userId)
        {
            var loginId = permissionIdList?.UserIdList
                          .FirstOrDefault(x => x.UserId == userId)
                          ?.LoginId;

            return(!loginId.IsNullOrEmpty()
                ? Rds.ExecuteTable(
                       context: context,
                       statements: Rds.SelectUsers(
                           column: Rds.UsersColumn().UserId(),
                           where : Rds.UsersWhere()
                           .TenantId(context.TenantId)
                           .LoginId(loginId)))
                   .AsEnumerable()
                   .FirstOrDefault()
                   ?.Int("UserId") ?? 0
                : 0);
        }
Example #4
0
        public static int ConvertedGroupId(
            Context context,
            PermissionIdList permissionIdList,
            int groupId)
        {
            var groupName = permissionIdList?.GroupIdList
                            .FirstOrDefault(x => x.GroupId == groupId)
                            ?.GroupName;

            return(!groupName.IsNullOrEmpty()
                ? Rds.ExecuteTable(
                       context: context,
                       statements: Rds.SelectGroups(
                           column: Rds.GroupsColumn().GroupId(),
                           where : Rds.GroupsWhere()
                           .TenantId(context.TenantId)
                           .GroupName(groupName)))
                   .AsEnumerable()
                   .FirstOrDefault()
                   ?.Int("GroupId") ?? 0
                : 0);
        }
Example #5
0
        public static int ConvertedDeptId(
            Context context,
            PermissionIdList permissionIdList,
            int deptId)
        {
            var deptCode = permissionIdList?.DeptIdList
                           .FirstOrDefault(x => x.DeptId == deptId)
                           ?.DeptCode;

            return(!deptCode.IsNullOrEmpty()
                ? Rds.ExecuteTable(
                       context: context,
                       statements: Rds.SelectDepts(
                           column: Rds.DeptsColumn().DeptId(),
                           where : Rds.DeptsWhere()
                           .TenantId(context.TenantId)
                           .DeptCode(deptCode)))
                   .AsEnumerable()
                   .FirstOrDefault()
                   ?.Int("DeptId") ?? 0
                : 0);
        }
        internal SiteSettings GetSavedSiteSettings(
            Context context,
            SitePackage.Header header,
            bool includeColumnPermission,
            PermissionIdList permissionIdList)
        {
            var ss = SiteSettings;

            ss.SiteId = SavedSiteId;
            ss.Links?.ForEach(link =>
                              link.SiteId = header.GetConvertedId(link.SiteId));
            ss.Summaries?.ForEach(summary =>
                                  summary.SiteId = header.GetConvertedId(summary.SiteId));
            if (ss.IntegratedSites?.Any() == true)
            {
                var integratedSites = new List <long>();
                ss.IntegratedSites?.ForEach(id =>
                                            integratedSites.Add(header.GetConvertedId(id)));
                ss.IntegratedSites = integratedSites;
            }
            ss.Columns?
            .Where(e => e.ChoicesText != null)
            .ForEach(column =>
                     column.ChoicesText = ReplaceChoicesText(
                         header: header,
                         source: column.ChoicesText));
            if (ss.GridColumns != null)
            {
                var gridColumns = new List <string>();
                ss.GridColumns.ForEach(column =>
                                       gridColumns.Add(
                                           ReplaceJoinColumn(
                                               header: header,
                                               source: column)));
                ss.GridColumns = gridColumns;
            }
            if (ss.FilterColumns != null)
            {
                var filterColumns = new List <string>();
                ss.FilterColumns.ForEach(column =>
                                         filterColumns.Add(
                                             ReplaceJoinColumn(
                                                 header: header,
                                                 source: column)));
                ss.FilterColumns = filterColumns;
            }
            ss.Exports?.ForEach(export =>
                                export.Columns?.ForEach(column =>
                                                        column.ColumnName = ReplaceJoinColumn(
                                                            header: header,
                                                            source: column.ColumnName)));
            ss.Views?.ForEach(view =>
            {
                if (view.GridColumns?.Any() == true)
                {
                    var gridColumns = new List <string>();
                    view.GridColumns.ForEach(column =>
                                             gridColumns.Add(
                                                 ReplaceJoinColumn(
                                                     header: header,
                                                     source: column)));
                    view.GridColumns = gridColumns;
                }
                if (view.ColumnFilterHash?.Any() == true)
                {
                    var hash = new Dictionary <string, string>();
                    view.ColumnFilterHash
                    .Where(o => o.Value != "[]")
                    .ForEach(o => hash.Add(
                                 ReplaceJoinColumn(
                                     header: header,
                                     source: o.Key),
                                 o.Value));
                    view.ColumnFilterHash = hash;
                }
                if (view.ColumnSorterHash?.Any() == true)
                {
                    var hash = new Dictionary <string, SqlOrderBy.Types>();
                    view.ColumnSorterHash
                    .ForEach(o => hash.Add(
                                 ReplaceJoinColumn(
                                     header: header,
                                     source: o.Key),
                                 o.Value));
                    view.ColumnSorterHash = hash;
                }
                if (view.CrosstabGroupByX?.Any() == true)
                {
                    if (view.CrosstabGroupByX.Contains("~"))
                    {
                        view.CrosstabGroupByX = ReplaceJoinColumn(
                            header: header,
                            source: view.CrosstabGroupByX);
                    }
                }
                if (view.CrosstabGroupByY?.Any() == true)
                {
                    if (view.CrosstabGroupByY.Contains("~"))
                    {
                        view.CrosstabGroupByY = ReplaceJoinColumn(
                            header: header,
                            source: view.CrosstabGroupByY);
                    }
                }
                if (view.CrosstabValue?.Any() == true)
                {
                    if (view.CrosstabValue.Contains("~"))
                    {
                        view.CrosstabValue = ReplaceJoinColumn(
                            header: header,
                            source: view.CrosstabValue);
                    }
                }
            });
            if (!includeColumnPermission)
            {
                ss.CreateColumnAccessControls?.Clear();
                ss.ReadColumnAccessControls?.Clear();
                ss.UpdateColumnAccessControls?.Clear();
            }
            else
            {
                ReplaceColumnAccessControls(
                    context: context,
                    columnAccessControls: ss.CreateColumnAccessControls,
                    permissionIdList: permissionIdList);
                ReplaceColumnAccessControls(
                    context: context,
                    columnAccessControls: ss.ReadColumnAccessControls,
                    permissionIdList: permissionIdList);
                ReplaceColumnAccessControls(
                    context: context,
                    columnAccessControls: ss.UpdateColumnAccessControls,
                    permissionIdList: permissionIdList);
            }
            return(ss);
        }
Example #7
0
 public IdConverter(
     Context context,
     long siteId,
     PermissionShortModel permissionShortModel,
     PermissionIdList permissionIdList,
     long convertSiteId)
 {
     Convert        = true;
     ConvertDeptId  = permissionShortModel.DeptId;
     ConvertGroupId = permissionShortModel.GroupId;
     ConvertUserId  = permissionShortModel.UserId;
     if (permissionShortModel.DeptId > 0)
     {
         var deptId = Utilities.ConvertedDeptId(
             context: context,
             permissionIdList: permissionIdList,
             deptId: permissionShortModel.DeptId);
         if (deptId > 0)
         {
             ConvertDeptId = deptId;
         }
         else
         {
             Convert = false;
         }
     }
     if (permissionShortModel.GroupId > 0)
     {
         var groupId = Utilities.ConvertedGroupId(
             context: context,
             permissionIdList: permissionIdList,
             groupId: permissionShortModel.GroupId);
         if (groupId > 0)
         {
             ConvertGroupId = groupId;
         }
         else
         {
             Convert = false;
         }
     }
     if (permissionShortModel.UserId == -1)
     {
         var tenant = new TenantModel(
             context: context,
             ss: new SiteModel(
                 context: context,
                 siteId: siteId).SiteSettings);
         if (tenant.DisableAllUsersPermission == true)
         {
             Convert = false;
         }
     }
     if (permissionShortModel.UserId > 0)
     {
         var userId = Utilities.ConvertedUserId(
             context: context,
             permissionIdList: permissionIdList,
             userId: permissionShortModel.UserId);
         if (userId > 0)
         {
             ConvertUserId = userId;
         }
         else
         {
             Convert = false;
         }
     }
     if (context.UserId == ConvertUserId)
     {
         var check = Rds.ExecuteTable(
             context: context,
             statements: Rds.SelectPermissions(
                 column: Rds.PermissionsColumn().PermissionType(),
                 where : Rds.PermissionsWhere()
                 .ReferenceId(convertSiteId)
                 .DeptId(ConvertDeptId)
                 .GroupId(ConvertGroupId)
                 .UserId(ConvertUserId)));
         Convert = (check.Rows.Count == 0);
     }
 }