NC implementation

This commit is contained in:
Kalarumeth
2022-09-27 17:04:46 +02:00
parent 551054255a
commit b840d8a984
17 changed files with 182 additions and 16 deletions
+17
View File
@@ -124,4 +124,21 @@ public static class Fields
}; };
} }
} }
public static Dictionary<string, string[]> NonComplianceCustomFields
{
get
{
return new Dictionary<string, string[]>()
{
{ "PAL_NC_Source", new string[] {"Choice", "Sorgente", "PAL Field", "FALSE", "FALSE", "TRUE", "TRUE", "TRUE", "TRUE", "<CHOICES><CHOICE>Interno</CHOICE><CHOICE>Cliente</CHOICE><CHOICE></CHOICE>Fornitore</CHOICE>" } },
{ "PAL_NC_Reference", new string[] { "Text", "Rifermento", "PAL Field", "FALSE", "FALSE", "TRUE", "TRUE", "TRUE", "TRUE", string.Empty } },
{ "PAL_NC_Nominative", new string[] { "Text", "Nominativo", "PAL Field", "FALSE", "FALSE", "TRUE", "TRUE", "TRUE", "TRUE", string.Empty } },
{ "PAL_NC_DateOfDetection", new string[] { "Text", "Data Rilevazione", "PAL Field", "FALSE", "FALSE", "TRUE", "TRUE", "TRUE", "TRUE", string.Empty } },
{ "PAL_NC_Project", new string[] { "Text", "Commessa", "PAL Field", "FALSE", "FALSE", "TRUE", "TRUE", "TRUE", "TRUE", string.Empty } },
{ "PAL_NC_ItemCode", new string[] { "Text", "Parte", "PAL Field", "FALSE", "FALSE", "TRUE", "TRUE", "TRUE", "TRUE", string.Empty } },
{ "PAL_NC_Portal", new string[] {"URL", "Portal", "PAL Field", "FALSE", "FALSE", "TRUE", "TRUE", "TRUE", "TRUE", string.Empty } },
};
}
}
} }
+2 -1
View File
@@ -3,6 +3,7 @@
public enum PalFieldType public enum PalFieldType
{ {
Project, Project,
Quotation Quotation,
NonCompliance
} }
} }
@@ -4,4 +4,5 @@ public interface ISharePointStructureBuilder
{ {
public bool BuildProject(string projName); public bool BuildProject(string projName);
public bool BuildQuotation(string quotationName); public bool BuildQuotation(string quotationName);
public bool BuildNonCompliance(string nonComplianceName);
} }
@@ -17,5 +17,7 @@ public interface ISiteOptions
string GetSubProjList(string projName); string GetSubProjList(string projName);
public string GetQuotationLibrary(); public string GetQuotationLibrary();
public Uri GetProjectSite(); public Uri GetProjectSite();
public string GetNonComplianceTenant();
public string GetNonComplianceLibrary();
public Uri GetNonComplianceSite();
} }
@@ -5,4 +5,5 @@ public interface ISiteService
public bool CreateProjectSiteIfNotExists(); public bool CreateProjectSiteIfNotExists();
public bool CreateSubSiteIfNotExists(string projName); public bool CreateSubSiteIfNotExists(string projName);
public bool CreateQuotationSiteIfNotExists(string quotationName); public bool CreateQuotationSiteIfNotExists(string quotationName);
public bool CreateNonComplianceSiteIfNotExists(string nonComplianceName);
} }
@@ -7,4 +7,5 @@ public interface ITenantService
{ {
public void CreateForProject(); public void CreateForProject();
public void CreateForQuotation(); public void CreateForQuotation();
public void CreateForNonCompliance();
} }
+27 -1
View File
@@ -73,6 +73,33 @@ public class OneNoteService : IOneNoteService
return true; return true;
} }
public bool CreateFolderInsideNonCompliance(string quotationName, ClientContext ctx)
{
try
{
logger.LogInformation($"> Inizializzata la fase di creazione della sezione {quotationName} in OneNote.");
var list = ctx.Web.Lists.EnsureSiteAssetsLibrary();
ctx.Load(list, l => l.RootFolder);
ctx.ExecuteQuery();
//TODO: verificare se worka
var rPath = ResourcePath.FromDecodedUrl($"{siteOptions.GetNonComplianceTenant()} Notebook/{DateTime.Today.Year}/{quotationName}");
list.RootFolder.AddSubFolderUsingPath(rPath);
ctx.ExecuteQuery();
logger.LogInformation($"> Completata la fase di creazione della sezione {quotationName} in OneNote.");
}
catch (Exception ex)
{
logger.LogError(ex, "OnenoteSPFeature");
return false;
}
return true;
}
public void EnableFeature(ClientContext ctx) public void EnableFeature(ClientContext ctx)
{ {
var featureName = "SiteNotebook"; var featureName = "SiteNotebook";
@@ -85,7 +112,6 @@ public class OneNoteService : IOneNoteService
ctx.ExecuteQuery(); ctx.ExecuteQuery();
logger.LogInformation($"> La Feature {featureName} è ora attiva!"); logger.LogInformation($"> La Feature {featureName} è ora attiva!");
} }
#endregion #endregion
} }
} }
@@ -2,6 +2,7 @@
using console_spo_utils.Interfaces.Services; using console_spo_utils.Interfaces.Services;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.SharePoint.Client; using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Navigation;
namespace console_spo_utils.Services; namespace console_spo_utils.Services;
@@ -22,6 +23,8 @@ public class ProjectQuickMenuService : IProjectQuickMenuService
{ {
try try
{ {
ClearQuickMenu(ctx);
var subSiteUrl = siteOptions.GetSubProjSite(projName).ToString(); var subSiteUrl = siteOptions.GetSubProjSite(projName).ToString();
var itemQuickMenu = Folders.GetProjectQuickMenu(projName, subSiteUrl); var itemQuickMenu = Folders.GetProjectQuickMenu(projName, subSiteUrl);
@@ -58,4 +61,26 @@ public class ProjectQuickMenuService : IProjectQuickMenuService
logger.LogError(ex, "CreateForProject"); logger.LogError(ex, "CreateForProject");
} }
} }
private void ClearQuickMenu(ClientContext ctx)
{
try
{
NavigationNodeCollection navBar = ctx.Web.Navigation.QuickLaunch;
ctx.Load(navBar);
ctx.ExecuteQueryRetry();
int[] element = new[] { 1, 1, 1 };
foreach (var e in element)
{
navBar[e].DeleteObject();
ctx.ExecuteQuery();
}
}
catch (Exception ex)
{
logger.LogError(ex, "ClearQuickMenu");
}
}
} }
+1 -2
View File
@@ -16,8 +16,7 @@ public class ProjectService : IProjectService
public ProjectService(ISiteOptions siteOptions, public ProjectService(ISiteOptions siteOptions,
ISharePointAuthenticationManager sharePointAuthenticationManager, ISharePointAuthenticationManager sharePointAuthenticationManager,
IWebpartService webpartService, IWebpartService webpartService,
ILogger<ProjectService> logger, ILogger<ProjectService> logger)
IProjectQuickMenuService projectQuickMenuService)
{ {
this.siteOptions = siteOptions; this.siteOptions = siteOptions;
this.sharePointAuthenticationManager = sharePointAuthenticationManager; this.sharePointAuthenticationManager = sharePointAuthenticationManager;
@@ -33,6 +33,13 @@ namespace console_spo_utils.Services
{ "ITS-SPO-PROJ-SALES-MODIFY", "Edit" }, { "ITS-SPO-PROJ-SALES-MODIFY", "Edit" },
{ "ITS-SPO-PROJ-SALES-READ", "Read" } { "ITS-SPO-PROJ-SALES-READ", "Read" }
}; };
var itsAdGruopNCRole = new Dictionary<string, string>()
{
{ "ITS-SPO-NC-OWNER", "Full Control" },
{ "ITS-SPO-NC-MODIFY", "Edit" },
{ "ITS-SPO-NC-READ", "Read" }
};
#endregion #endregion
logger.LogInformation("> Inizializzata la fase di assegnazione dei ruoli."); logger.LogInformation("> Inizializzata la fase di assegnazione dei ruoli.");
@@ -81,6 +88,27 @@ namespace console_spo_utils.Services
logger.LogInformation("> Completata la fase di assegnazione dei ruoli."); logger.LogInformation("> Completata la fase di assegnazione dei ruoli.");
#endregion #endregion
} }
else if (tenantName.Contains("Conformità"))
{
#region Site Permission Quotation
var web = ctx.Web;
foreach (var role in itsAdGruopNCRole)
{
var adGroup = web.EnsureUser(role.Key);
ctx.Load(adGroup);
var roleD = web.RoleDefinitions.GetByName(role.Value);
var roleDb = new RoleDefinitionBindingCollection(ctx) { roleD };
web.RoleAssignments.Add(adGroup, roleDb);
web.Update();
}
ctx.ExecuteQuery();
logger.LogInformation("> Completata la fase di assegnazione dei ruoli.");
#endregion
}
else if (!string.IsNullOrEmpty(docLibName)) else if (!string.IsNullOrEmpty(docLibName))
{ {
#region DocLib Permission #region DocLib Permission
@@ -25,8 +25,6 @@ namespace console_spo_utils.Services
this.authMgr = authMgr; this.authMgr = authMgr;
} }
#region Check If Exist #region Check If Exist
public bool SiteExist(ClientContext ctx) public bool SiteExist(ClientContext ctx)
{ {
@@ -103,7 +101,7 @@ namespace console_spo_utils.Services
return false; return false;
} }
#endregion
public bool ListContentTypeExist(ClientContext ctx, string listTitle, string contentTypeName) public bool ListContentTypeExist(ClientContext ctx, string listTitle, string contentTypeName)
{ {
@@ -123,7 +121,7 @@ namespace console_spo_utils.Services
return true; return true;
} }
} }
#endregion
public void PalCustomField(ClientContext ctx, PalFieldType et) public void PalCustomField(ClientContext ctx, PalFieldType et)
{ {
@@ -131,6 +129,7 @@ namespace console_spo_utils.Services
{ {
PalFieldType.Project => Fields.ProjectCustomFields, PalFieldType.Project => Fields.ProjectCustomFields,
PalFieldType.Quotation => Fields.QuotationCustomFields, PalFieldType.Quotation => Fields.QuotationCustomFields,
PalFieldType.NonCompliance => Fields.NonComplianceCustomFields,
_ => throw new NotImplementedException("Entity type not found") _ => throw new NotImplementedException("Entity type not found")
}; };
@@ -63,4 +63,17 @@ public class SharePointStructureBuilderService : ISharePointStructureBuilder
return true; return true;
} }
public bool BuildNonCompliance(string nonComplianceName)
{
var siteBuildResult = siteService.CreateNonComplianceSiteIfNotExists(nonComplianceName);
if (!siteBuildResult)
{
throw new Exception($"Impossibile to build site");
}
quotationBuildService.CreateIfNotExists(nonComplianceName);
return true;
}
} }
+17 -2
View File
@@ -53,12 +53,12 @@ public class SiteOptions : ISiteOptions
public string GetQuotationLibrary() public string GetQuotationLibrary()
{ {
return $"Offerte {GetYear()}"; return $"{GetQuotationTenant()} {GetYear()}";
} }
public Uri GetQuotationSite() public Uri GetQuotationSite()
{ {
return new Uri($"{SiteCollection}/sites/Offerte"); return new Uri($"{SiteCollection}/sites/{GetQuotationTenant()}");
} }
public string GetSubProjList(string projName) public string GetSubProjList(string projName)
@@ -75,4 +75,19 @@ public class SiteOptions : ISiteOptions
{ {
return new Uri($"{SiteCollection}/sites/{GetProjectTenant()}"); return new Uri($"{SiteCollection}/sites/{GetProjectTenant()}");
} }
public string GetNonComplianceTenant()
{
return "Non Conformità";
}
public string GetNonComplianceLibrary()
{
return $"{GetNonComplianceTenant()} {GetYear()}";
}
public Uri GetNonComplianceSite()
{
return new Uri($"{SiteCollection}/sites/{GetNonComplianceTenant().Replace(" ", String.Empty)}");
}
} }
+21
View File
@@ -129,6 +129,27 @@ public class SiteService : ISiteService
return true; return true;
} }
public bool CreateNonComplianceSiteIfNotExists(string nonComplianceName)
{
try
{
var site = siteOptions.GetNonComplianceSite();
using var ctx = authMgr.GetContext(site);
if (spc.SiteExist(ctx))
{
return true;
}
tenantService.CreateForNonCompliance();
}
catch (Exception e)
{
logger.LogError(e, "Site Service");
return false;
}
return true;
}
private void CreateProjectListEntry(string projName, ClientContext ctx) private void CreateProjectListEntry(string projName, ClientContext ctx)
{ {
+4 -4
View File
@@ -8,10 +8,13 @@ namespace console_spo_utils.Services;
public class SubSiteService : ISubSiteService public class SubSiteService : ISubSiteService
{ {
private readonly ILogger<SubSiteService> logger; private readonly ILogger<SubSiteService> logger;
private readonly IProjectQuickMenuService projectQuickMenuService;
public SubSiteService(ILogger<SubSiteService> logger) public SubSiteService(ILogger<SubSiteService> logger,
IProjectQuickMenuService projectQuickMenuService)
{ {
this.logger = logger; this.logger = logger;
this.projectQuickMenuService = projectQuickMenuService;
} }
@@ -19,7 +22,6 @@ public class SubSiteService : ISubSiteService
{ {
try try
{ {
logger.LogInformation($"> Il sito {projName} è in fase di creazione!"); logger.LogInformation($"> Il sito {projName} è in fase di creazione!");
var wci = new WebCreationInformation var wci = new WebCreationInformation
@@ -61,8 +63,6 @@ public class SubSiteService : ISubSiteService
ctx.ExecuteQuery(); ctx.ExecuteQuery();
AddFieldsToSubProj(siteField, list, ctx); AddFieldsToSubProj(siteField, list, ctx);
logger.LogInformation($"> Completata la fase di importazione dei campi in 'SottoCommesse {ssProjectTitle}'."); logger.LogInformation($"> Completata la fase di importazione dei campi in 'SottoCommesse {ssProjectTitle}'.");
#endregion #endregion
@@ -49,6 +49,15 @@ public class TenantService : ITenantService
); );
} }
public void CreateForNonCompliance()
{
TenantCreation(
siteOptions.GetNonComplianceTenant(),
siteOptions.GetNonComplianceSite(),
PalFieldType.NonCompliance
);
}
public void TenantCreation(string tenantName, Uri site, PalFieldType fieldType) public void TenantCreation(string tenantName, Uri site, PalFieldType fieldType)
{ {
Console.WriteLine($"> Inizializzata la fase di creazione del sito '../{tenantName.Replace(" ", string.Empty)}'."); Console.WriteLine($"> Inizializzata la fase di creazione del sito '../{tenantName.Replace(" ", string.Empty)}'.");
+8
View File
@@ -35,6 +35,14 @@ namespace console_spo_utils.Workers
logger.LogError("Impossible to create structure"); logger.LogError("Impossible to create structure");
return; return;
} }
var buildNonComplianceResult = structureBuilder.BuildNonCompliance("NC0001");
if (!buildNonComplianceResult)
{
logger.LogError("Impossible to create structure");
return;
}
} }
} }
} }