NC implementation
This commit is contained in:
@@ -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 } },
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
public enum PalFieldType
|
||||
{
|
||||
Project,
|
||||
Quotation
|
||||
Quotation,
|
||||
NonCompliance
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,4 +4,5 @@ public interface ISharePointStructureBuilder
|
||||
{
|
||||
public bool BuildProject(string projName);
|
||||
public bool BuildQuotation(string quotationName);
|
||||
public bool BuildNonCompliance(string nonComplianceName);
|
||||
}
|
||||
@@ -17,5 +17,7 @@ public interface ISiteOptions
|
||||
string GetSubProjList(string projName);
|
||||
public string GetQuotationLibrary();
|
||||
public Uri GetProjectSite();
|
||||
|
||||
public string GetNonComplianceTenant();
|
||||
public string GetNonComplianceLibrary();
|
||||
public Uri GetNonComplianceSite();
|
||||
}
|
||||
@@ -5,4 +5,5 @@ public interface ISiteService
|
||||
public bool CreateProjectSiteIfNotExists();
|
||||
public bool CreateSubSiteIfNotExists(string projName);
|
||||
public bool CreateQuotationSiteIfNotExists(string quotationName);
|
||||
public bool CreateNonComplianceSiteIfNotExists(string nonComplianceName);
|
||||
}
|
||||
@@ -7,4 +7,5 @@ public interface ITenantService
|
||||
{
|
||||
public void CreateForProject();
|
||||
public void CreateForQuotation();
|
||||
public void CreateForNonCompliance();
|
||||
}
|
||||
@@ -73,6 +73,33 @@ public class OneNoteService : IOneNoteService
|
||||
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)
|
||||
{
|
||||
var featureName = "SiteNotebook";
|
||||
@@ -85,7 +112,6 @@ public class OneNoteService : IOneNoteService
|
||||
ctx.ExecuteQuery();
|
||||
logger.LogInformation($"> La Feature {featureName} è ora attiva!");
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
using console_spo_utils.Interfaces.Services;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.SharePoint.Client;
|
||||
using Microsoft.SharePoint.Navigation;
|
||||
|
||||
namespace console_spo_utils.Services;
|
||||
|
||||
@@ -22,6 +23,8 @@ public class ProjectQuickMenuService : IProjectQuickMenuService
|
||||
{
|
||||
try
|
||||
{
|
||||
ClearQuickMenu(ctx);
|
||||
|
||||
var subSiteUrl = siteOptions.GetSubProjSite(projName).ToString();
|
||||
var itemQuickMenu = Folders.GetProjectQuickMenu(projName, subSiteUrl);
|
||||
|
||||
@@ -58,4 +61,26 @@ public class ProjectQuickMenuService : IProjectQuickMenuService
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,8 +16,7 @@ public class ProjectService : IProjectService
|
||||
public ProjectService(ISiteOptions siteOptions,
|
||||
ISharePointAuthenticationManager sharePointAuthenticationManager,
|
||||
IWebpartService webpartService,
|
||||
ILogger<ProjectService> logger,
|
||||
IProjectQuickMenuService projectQuickMenuService)
|
||||
ILogger<ProjectService> logger)
|
||||
{
|
||||
this.siteOptions = siteOptions;
|
||||
this.sharePointAuthenticationManager = sharePointAuthenticationManager;
|
||||
|
||||
@@ -33,6 +33,13 @@ namespace console_spo_utils.Services
|
||||
{ "ITS-SPO-PROJ-SALES-MODIFY", "Edit" },
|
||||
{ "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
|
||||
|
||||
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.");
|
||||
#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))
|
||||
{
|
||||
#region DocLib Permission
|
||||
|
||||
@@ -25,8 +25,6 @@ namespace console_spo_utils.Services
|
||||
this.authMgr = authMgr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#region Check If Exist
|
||||
public bool SiteExist(ClientContext ctx)
|
||||
{
|
||||
@@ -103,7 +101,7 @@ namespace console_spo_utils.Services
|
||||
|
||||
return false;
|
||||
}
|
||||
#endregion
|
||||
|
||||
public bool ListContentTypeExist(ClientContext ctx, string listTitle, string contentTypeName)
|
||||
{
|
||||
|
||||
@@ -123,7 +121,7 @@ namespace console_spo_utils.Services
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public void PalCustomField(ClientContext ctx, PalFieldType et)
|
||||
{
|
||||
@@ -131,6 +129,7 @@ namespace console_spo_utils.Services
|
||||
{
|
||||
PalFieldType.Project => Fields.ProjectCustomFields,
|
||||
PalFieldType.Quotation => Fields.QuotationCustomFields,
|
||||
PalFieldType.NonCompliance => Fields.NonComplianceCustomFields,
|
||||
_ => throw new NotImplementedException("Entity type not found")
|
||||
};
|
||||
|
||||
|
||||
@@ -63,4 +63,17 @@ public class SharePointStructureBuilderService : ISharePointStructureBuilder
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -53,12 +53,12 @@ public class SiteOptions : ISiteOptions
|
||||
|
||||
public string GetQuotationLibrary()
|
||||
{
|
||||
return $"Offerte {GetYear()}";
|
||||
return $"{GetQuotationTenant()} {GetYear()}";
|
||||
}
|
||||
|
||||
public Uri GetQuotationSite()
|
||||
{
|
||||
return new Uri($"{SiteCollection}/sites/Offerte");
|
||||
return new Uri($"{SiteCollection}/sites/{GetQuotationTenant()}");
|
||||
}
|
||||
|
||||
public string GetSubProjList(string projName)
|
||||
@@ -75,4 +75,19 @@ public class SiteOptions : ISiteOptions
|
||||
{
|
||||
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)}");
|
||||
}
|
||||
}
|
||||
@@ -129,6 +129,27 @@ public class SiteService : ISiteService
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -8,10 +8,13 @@ namespace console_spo_utils.Services;
|
||||
public class SubSiteService : ISubSiteService
|
||||
{
|
||||
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.projectQuickMenuService = projectQuickMenuService;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +22,6 @@ public class SubSiteService : ISubSiteService
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
logger.LogInformation($"> Il sito {projName} è in fase di creazione!");
|
||||
|
||||
var wci = new WebCreationInformation
|
||||
@@ -61,8 +63,6 @@ public class SubSiteService : ISubSiteService
|
||||
ctx.ExecuteQuery();
|
||||
AddFieldsToSubProj(siteField, list, ctx);
|
||||
|
||||
|
||||
|
||||
logger.LogInformation($"> Completata la fase di importazione dei campi in 'SottoCommesse {ssProjectTitle}'.");
|
||||
#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)
|
||||
{
|
||||
Console.WriteLine($"> Inizializzata la fase di creazione del sito '../{tenantName.Replace(" ", string.Empty)}'.");
|
||||
|
||||
@@ -35,6 +35,14 @@ namespace console_spo_utils.Workers
|
||||
logger.LogError("Impossible to create structure");
|
||||
return;
|
||||
}
|
||||
|
||||
var buildNonComplianceResult = structureBuilder.BuildNonCompliance("NC0001");
|
||||
|
||||
if (!buildNonComplianceResult)
|
||||
{
|
||||
logger.LogError("Impossible to create structure");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user