Skip to content

Commit

Permalink
Credit page (#588)
Browse files Browse the repository at this point in the history
* updated for mtsinai examples

* added missing user group and role tables to leafdb.schema.sql script

* upgraded dependencies, added migration script, bumped versions, switched to dotnet core 6

* updated client deps
  • Loading branch information
ndobb authored Apr 24, 2023
1 parent a54f777 commit 73d1ee7
Show file tree
Hide file tree
Showing 26 changed files with 685 additions and 345 deletions.
60 changes: 60 additions & 0 deletions src/db/build/LeafDB.Schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1364,6 +1364,43 @@ CREATE TABLE [rela].[QueryConceptDependency](
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [auth].[UserRole] Script Date: ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [auth].[UserRole](
[ScopedIdentity] [nvarchar](200) NOT NULL,
[IsUser] [bit] NOT NULL,
[IsAdmin] [bit] NOT NULL,
[IsSuper] [bit] NOT NULL,
[IsIdentified] [bit] NOT NULL,
[IsFederated] [bit] NOT NULL,
[Created] datetime NOT NULL,
[Updated] datetime NOT NULL
CONSTRAINT [PK__UserRole] PRIMARY KEY CLUSTERED
(
[ScopedIdentity] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [auth].[UserGroup] Script Date: ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [auth].[UserGroup](
[ScopedIdentity] [nvarchar](200) NOT NULL,
[GroupName] [nvarchar](200) NOT NULL,
[Created] datetime NOT NULL,
[Updated] datetime NOT NULL
CONSTRAINT [PK__UserGroup] PRIMARY KEY CLUSTERED
(
[ScopedIdentity] ASC,
[GroupName] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [rela].[QueryDependency] Script Date: ******/
SET ANSI_NULLS ON
GO
Expand Down Expand Up @@ -9061,9 +9098,32 @@ BEGIN

EXEC network.sp_GetEndpoints;
END
GO


-- =======================================
-- Author: Nic Dobbins
-- Create date: 2021/10/19
-- Description: Gets user roles
-- =======================================
CREATE PROCEDURE [auth].[sp_GetUserGroupsAndRoles]
@scopedId nvarchar(200)
AS
BEGIN
SET NOCOUNT ON

-- Roles
SELECT IsUser, IsAdmin, IsSuper, IsIdentified, IsFederated
FROM [auth].[UserRole] AS R
WHERE R.ScopedIdentity = @scopedId

-- Groups
SELECT GroupName
FROM [auth].[UserGroup] AS G
WHERE G.ScopedIdentity = @scopedId

END
GO



Expand Down
11 changes: 10 additions & 1 deletion src/db/migration/3.11.1__3.11.2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,29 @@ IF COLUMNPROPERTY(OBJECT_ID('app.DemographicQuery'), 'ColumnNamesJson', 'ColumnI
BEGIN
ALTER TABLE app.DemographicQuery
ADD [ColumnNamesJson] NVARCHAR(MAX) NULL
END
GO

IF (SELECT ColumnNamesJson FROM app.DemographicQuery) IS NULL
BEGIN
UPDATE app.DemographicQuery
SET [ColumnNamesJson] = '{}'
SET [ColumnNamesJson] = '{}'
END
GO


/**
* Add [IsDefault] to app.DatasetQuery
*/
IF COLUMNPROPERTY(OBJECT_ID('app.DatasetQuery'), 'IsDefault', 'ColumnId') IS NULL
BEGIN
ALTER TABLE app.DatasetQuery
ADD [IsDefault] BIT NULL
END
GO

IF (SELECT COUNT(*) FROM app.DatasetQuery WHERE IsDefault IS NULL) > 0
BEGIN
UPDATE app.DatasetQuery
SET [IsDefault] = 0
END
Expand Down
6 changes: 6 additions & 0 deletions src/db/migration/3.11.2__3.11.3.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* Update version
*/
UPDATE ref.[Version]
SET [Version] = '3.11.3'
GO
10 changes: 5 additions & 5 deletions src/server/API/API.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<!-- <TargetLatestRuntimePatch>true</TargetLatestRuntimePatch> -->
<TieredCompilation>true</TieredCompilation>
<ReleaseVersion>3.1</ReleaseVersion>
Expand All @@ -27,22 +27,22 @@
<Folder Include="DTO\Notification\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.3.0">
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.3.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Serilog.AspNetCore" Version="3.4.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="3.0.1" />
<PackageReference Include="Serilog.Sinks.Async" Version="1.4.0" />
<PackageReference Include="Serilog.Sinks.Async" Version="1.5.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
<PackageReference Include="Serilog.Sinks.RollingFile" Version="3.3.0" />
<PackageReference Include="Microsoft.AspNetCore.App">
<PrivateAssets Condition="'%(PackageReference.Version)' == ''">all</PrivateAssets>
<Publish Condition="'%(PackageReference.Version)' == ''">true</Publish>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.4" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.7.1" />
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.7.1" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.29.0" />
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.29.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.18" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.8" />
</ItemGroup>
Expand Down
9 changes: 8 additions & 1 deletion src/server/API/Controllers/ConfigController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,15 @@ public ActionResult<ConfigDTO> Get()
Attestation = new AttestationConfigDTO
{
Enabled = attestationOptions.Enabled,
SkipModeSelection = attestationOptions.SkipModeSelection,
Text = attestationOptions.Text,
Type = attestationOptions.Type
Type = attestationOptions.Type,
Credits = new AttestationConfigDTO.AttestationCreditsDTO
{
Enabled = attestationOptions.Credits.Enabled,
Logos = attestationOptions.Credits.Logos,
Text = attestationOptions.Credits.Text
}
},
Cohort = new CohortConfigDTO
{
Expand Down
10 changes: 10 additions & 0 deletions src/server/API/DTO/Config/ConfigDTO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,18 @@ public class CohortConfigDTO
public class AttestationConfigDTO
{
public bool Enabled { get; set; }
public bool SkipModeSelection { get; set; }
public string[] Text { get; set; }
public CustomAttestationType Type { get; set; }

public AttestationCreditsDTO Credits { get; set; }

public class AttestationCreditsDTO
{
public bool Enabled { get; set; }
public string[] Logos { get; set; }
public string Text { get; set; }
}
}

public class ClientOptionsDTO
Expand Down
8 changes: 8 additions & 0 deletions src/server/API/Options/Config.Attestation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ public static class Attestation
public const string Enabled = @"Attestation:Enabled";
public const string Type = @"Attestation:Type";
public const string Text = @"Attestation:Text";
public const string SkipModeSelection = "Attestation:SkipModeSelection";

public static class Credits
{
public const string Enabled = @"Attestation:Credits:Enabled";
public const string Text = @"Attestation:Credits:Text";
public const string Logos = @"Attestation:Credits:Logos";
}
}
}
}
12 changes: 12 additions & 0 deletions src/server/API/Options/StartupExtensions.Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,29 @@ static IServiceCollection ConfigureAttestationOptions(this IServiceCollection se

if (attest.Enabled)
{
attest.SkipModeSelection = config.GetValue<bool>(Config.Attestation.SkipModeSelection);
attest.WithAttestationType(config.GetValue<string>(Config.Attestation.Type));
if (attest.Type != CustomAttestationType.None)
{
attest.Text = config.GetSection(Config.Attestation.Text).Get<string[]>();
}
}

var hasCredits = config.TryGetValue<bool>(Config.Attestation.Credits.Enabled, out bool creditsEnabled);
if (hasCredits && creditsEnabled)
{
attest.Credits.Enabled = true;
attest.Credits.Text = config.GetValue<string>(Config.Attestation.Credits.Text);
attest.Credits.Logos = config.GetSection(Config.Attestation.Credits.Logos).Get<string[]>();
}

services.Configure<AttestationOptions>(opts =>
{
opts.Enabled = attest.Enabled;
opts.SkipModeSelection = attest.SkipModeSelection;
opts.Text = attest.Text;
opts.Type = attest.Type;
opts.Credits = attest.Credits;
});

return services;
Expand Down
2 changes: 1 addition & 1 deletion src/server/API/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
}
},
"Attestation": {
"Enabled": false
"Enabled": true
},
"Compiler": {
"Alias": "@",
Expand Down
2 changes: 1 addition & 1 deletion src/server/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project>
<PropertyGroup>
<VersionPrefix>3.11.2</VersionPrefix>
<VersionPrefix>3.11.3</VersionPrefix>
</PropertyGroup>
</Project>
6 changes: 3 additions & 3 deletions src/server/Model/Compiler/SqlBuilder/ConceptDatasetSqlSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ internal override void SetSelect()
var encounterId = new ExpressedColumn(
new Expression(dialect.Convert(ColumnType.String, EncounterId)),
EncounterColumns.EncounterId);
var dateField = new ExpressedColumn(Date, ConceptColumns.DateField);
var dateField = new ExpressedColumn(new Expression(Date), ConceptColumns.DateField);

cols.Add(personId);
cols.Add(encounterId);
cols.Add(dateField);

if (PanelItem != null && PanelItem.UseNumericFilter)
{
var numericField = new ExpressedColumn(Number, ConceptColumns.NumberField);
var numericField = new ExpressedColumn(new Expression(Number), ConceptColumns.NumberField);
cols.Add(numericField);
}

Expand All @@ -73,7 +73,7 @@ public CachedCohortSqlSet(CompilerOptions compilerOptions)
{
Select = new ISelectable[]
{
new ExpressedColumn(PersonId, DatasetColumns.PersonId),
new ExpressedColumn(new Expression(PersonId), DatasetColumns.PersonId),
Salt
};
From = $"{compilerOptions.AppDb}.app.Cohort";
Expand Down
4 changes: 2 additions & 2 deletions src/server/Model/Compiler/SqlBuilder/DatasetJoinedSqlSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public DatasetJoinedSqlSet(

Select = new ISelectable[]
{
new ExpressedColumn(last.PersonId, DatasetColumns.PersonId),
new ExpressedColumn(last.EncounterId, EncounterColumns.EncounterId),
new ExpressedColumn(new Expression(last.PersonId), DatasetColumns.PersonId),
new ExpressedColumn(new Expression(last.EncounterId), EncounterColumns.EncounterId),
join.Salt
};
From = From.Prepend(join);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public DatasetNonAggregateJoinedSqlSet(
new ExpressedColumn(
new Expression(dialect.Convert(ColumnType.String, last.EncounterId)),
EncounterColumns.EncounterId),
new ExpressedColumn(last.Date, ConceptColumns.DateField),
new ExpressedColumn(new Expression(last.Date), ConceptColumns.DateField),
join.Salt
};
From = From.Prepend(join);
Expand Down
4 changes: 2 additions & 2 deletions src/server/Model/Compiler/SqlBuilder/Dialect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public static class Field

public static class Alias
{
public const string Person = "_S";
public const string Sequence = "_T";
public const string Person = "S";
public const string Sequence = "T";
}

public static class Syntax
Expand Down
8 changes: 4 additions & 4 deletions src/server/Model/Model.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<!-- <TargetLatestRuntimePatch>true</TargetLatestRuntimePatch> -->
<TieredCompilation>true</TieredCompilation>
<ReleaseVersion>3.1</ReleaseVersion>
<ReleaseVersion>6.0</ReleaseVersion>
</PropertyGroup>
<PropertyGroup>
<LangVersion>latest</LangVersion>
Expand All @@ -20,9 +20,9 @@
<Folder Include="Admin\Notification\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Composure" Version="1.1.0" />
<PackageReference Include="Composure" Version="1.3.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="7.0.1" />
</ItemGroup>
<ItemGroup>
<None Remove="Compiler\appsettings.json" />
Expand Down
10 changes: 10 additions & 0 deletions src/server/Model/Options/AttestationOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ namespace Model.Options
public class AttestationOptions
{
public bool Enabled { get; set; }
public bool SkipModeSelection { get; set; }
public string[] Text { get; set; }

public const string TextType = "TEXT";
public const string HtmlType = "HTML";

public CreditsOptions Credits = new CreditsOptions();

public CustomAttestationType Type { get; set; }
public static readonly IEnumerable<string> ValidTypeOptions = new string[] { TextType, HtmlType };

Expand Down Expand Up @@ -46,6 +49,13 @@ public void WithAttestationType(string value)
break;
}
}

public class CreditsOptions
{
public bool Enabled { get; set; }
public string Text { get; set; }
public string[] Logos { get; set; }
}
}

public enum CustomAttestationType : ushort
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ public async Task<AdminDemographicQuery> GetDemographicQueryAsync()
commandType: CommandType.StoredProcedure,
commandTimeout: opts.DefaultTimeout);

return demo.ToAdminDemographicQuery();
if (demo != null) return demo.ToAdminDemographicQuery();
return new AdminDemographicQuery
{
SqlStatement = "",
ColumnNames = new Dictionary<string, string>()
};
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/server/Services/Services.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<!-- <TargetLatestRuntimePatch>true</TargetLatestRuntimePatch> -->
<TieredCompilation>true</TieredCompilation>
<ReleaseVersion>3.1</ReleaseVersion>
Expand All @@ -15,7 +15,7 @@
<PackageReference Include="Dapper" Version="1.60.6" />
<PackageReference Include="System.Data.SqlClient" Version="4.6.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="7.0.1" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="2.2.0" />
<PackageReference Include="System.DirectoryServices.AccountManagement" Version="4.5.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
Expand Down
Loading

0 comments on commit 73d1ee7

Please sign in to comment.