Skip to content

Commit

Permalink
Revert "merging from master"
Browse files Browse the repository at this point in the history
This reverts commit 17164cb, reversing
changes made to db2b666.
  • Loading branch information
ndobb committed Sep 13, 2022
1 parent 17164cb commit 25bbe19
Show file tree
Hide file tree
Showing 156 changed files with 92 additions and 38,155 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
/bin

todo.md
src/ui-dashboard-client

109 changes: 22 additions & 87 deletions src/db/build/LeafDB.Schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,26 @@ CREATE TABLE [app].[ConceptTokenizedIndex](
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object: Table [app].[Dashboard] Script Date: ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [app].[Dashboard](
[Id] [uniqueidentifier] NOT NULL,
[JsonConfig] [nvarchar](max) NOT NULL,
[UiDisplayName] [nvarchar](200) NOT NULL,
[UiDisplayDescription] [nvarchar](4000) NOT NULL,
[Created] [datetime] NOT NULL,
[CreatedBy] [nvarchar](1000) NOT NULL,
[Updated] [datetime] NOT NULL,
[UpdatedBy] [nvarchar](1000) NOT NULL,
CONSTRAINT [PK__Dashboard] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object: Table [app].[DatasetQuery] Script Date: ******/
SET ANSI_NULLS ON
GO
Expand Down Expand Up @@ -1473,6 +1493,8 @@ ALTER TABLE [app].[Concept] ADD CONSTRAINT [DF_Concept_Id] DEFAULT (newsequent
GO
ALTER TABLE [app].[Concept] ADD CONSTRAINT [DF_Concept_AddDateTime] DEFAULT (getdate()) FOR [AddDateTime]
GO
ALTER TABLE [app].[Dashboard] ADD CONSTRAINT [DF_Dashboard_] DEFAULT (newid()) FOR [Id]
GO
ALTER TABLE [app].[DatasetQuery] ADD CONSTRAINT [DF_DatasetQuery_Id] DEFAULT (newsequentialid()) FOR [Id]
GO
ALTER TABLE [app].[DatasetQuery] ADD CONSTRAINT [DF_DatasetQuery_Created] DEFAULT (getdate()) FOR [Created]
Expand Down Expand Up @@ -5285,92 +5307,6 @@ END



GO
/****** Object: StoredProcedure [app].[sp_GetCohortById] Script Date: ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =======================================
-- Author: Nic Dobbins
-- Create date: 2022/2/1
-- Description: Retrieves a cohort by Id.
-- =======================================
CREATE PROCEDURE [app].[sp_GetCohortById]
@id [uniqueidentifier],
@user auth.[User],
@groups auth.GroupMembership READONLY,
@exportedOnly bit,
@admin bit = 0
AS
BEGIN
SET NOCOUNT ON;

DECLARE @result TABLE (
QueryId UNIQUEIDENTIFIER NOT NULL,
PersonId nvarchar(200) NOT NULL,
Exported bit NOT NULL,
Salt UNIQUEIDENTIFIER
);

-- if not found
IF @id IS NULL
BEGIN
SELECT QueryId, PersonId, Exported, Salt
FROM @result;
RETURN;
END;

-- Admin can access any query
IF (@admin = 1)
INSERT INTO @result (QueryId, PersonId, Exported, Salt)
SELECT C.QueryId, C.PersonId, C.Exported, C.Salt
FROM app.Cohort AS C
WHERE C.QueryId = @id
AND (@exportedOnly = 0 OR Exported = 1)
ELSE
BEGIN
-- permission filter
WITH permitted AS (
-- user based constraint
SELECT
QueryId
FROM auth.QueryConstraint
WHERE QueryId = @id
AND ConstraintId = 1
AND ConstraintValue = @user
UNION
-- group base constraint
SELECT
QueryId
FROM auth.QueryConstraint
WHERE QueryId = @id
AND ConstraintId = 2
AND ConstraintValue IN (SELECT [Group] FROM @groups)
)
INSERT INTO @result (QueryId, PersonId, Exported, Salt)
SELECT C.QueryId, C.PersonId, C.Exported, C.Salt
FROM app.Cohort AS C
INNER JOIN app.Query AS Q ON C.QueryId = Q.Id
WHERE (Q.[Owner] = @user OR Q.Id IN (SELECT Id FROM permitted))
AND Q.Id = @id
AND (@exportedOnly = 0 OR Exported = 1);
END

-- did not pass filter
IF (SELECT COUNT(*) FROM @result) < 1
BEGIN
DECLARE @secmsg nvarchar(400) = @user + ' not permitted to query ' + CONVERT(NVARCHAR(100), @id);
THROW 70403, @secmsg, 1
END;

-- return
SELECT QueryId, PersonId, Exported, Salt
FROM @result;
END


GO
/****** Object: StoredProcedure [app].[sp_GetConceptById] Script Date: ******/
SET ANSI_NULLS ON
Expand Down Expand Up @@ -6806,7 +6742,6 @@ END




GO
/****** Object: StoredProcedure [app].[sp_GetPreflightConceptById] Script Date: ******/
SET ANSI_NULLS ON
Expand Down
112 changes: 24 additions & 88 deletions src/db/build/LeafDB.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
-- This Source Code Form is subject to the terms of the Mozilla Public
-- License, v. 2.0. If a copy of the MPL was not distributed with this
-- file, You can obtain one at http://mozilla.org/MPL/2.0/.
USE [master]
USE [master]
GO
/****** Object: Database [LeafDB] Script Date: ******/
CREATE DATABASE [LeafDB]
CONTAINMENT = NONE
ON PRIMARY
( NAME = N'LeafDB', FILENAME = N'/var/opt/mssql/data/LeafDB.mdf' , SIZE = 73728KB , MAXSIZE = UNLIMITED, FILEGROWTH = 65536KB )
LOG ON
( NAME = N'LeafDB_log', FILENAME = N'/var/opt/mssql/data/LeafDB_log.ldf' , SIZE = 335872KB , MAXSIZE = 2048GB , FILEGROWTH = 65536KB )
( NAME = N'LeafDB_log', FILENAME = N'/var/opt/mssql/data/LeafDB_log.ldf' , SIZE = 204800KB , MAXSIZE = 2048GB , FILEGROWTH = 65536KB )
GO
IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
begin
Expand Down Expand Up @@ -829,6 +829,26 @@ CREATE TABLE [app].[ConceptTokenizedIndex](
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object: Table [app].[Dashboard] Script Date: ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [app].[Dashboard](
[Id] [uniqueidentifier] NOT NULL,
[JsonConfig] [nvarchar](max) NOT NULL,
[UiDisplayName] [nvarchar](200) NOT NULL,
[UiDisplayDescription] [nvarchar](4000) NOT NULL,
[Created] [datetime] NOT NULL,
[CreatedBy] [nvarchar](1000) NOT NULL,
[Updated] [datetime] NOT NULL,
[UpdatedBy] [nvarchar](1000) NOT NULL,
CONSTRAINT [PK__Dashboard] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object: Table [app].[DatasetQuery] Script Date: ******/
SET ANSI_NULLS ON
GO
Expand Down Expand Up @@ -1548,6 +1568,8 @@ ALTER TABLE [app].[Concept] ADD CONSTRAINT [DF_Concept_Id] DEFAULT (newsequent
GO
ALTER TABLE [app].[Concept] ADD CONSTRAINT [DF_Concept_AddDateTime] DEFAULT (getdate()) FOR [AddDateTime]
GO
ALTER TABLE [app].[Dashboard] ADD CONSTRAINT [DF_Dashboard_] DEFAULT (newid()) FOR [Id]
GO
ALTER TABLE [app].[DatasetQuery] ADD CONSTRAINT [DF_DatasetQuery_Id] DEFAULT (newsequentialid()) FOR [Id]
GO
ALTER TABLE [app].[DatasetQuery] ADD CONSTRAINT [DF_DatasetQuery_Created] DEFAULT (getdate()) FOR [Created]
Expand Down Expand Up @@ -5360,92 +5382,6 @@ END



GO
/****** Object: StoredProcedure [app].[sp_GetCohortById] Script Date: ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =======================================
-- Author: Nic Dobbins
-- Create date: 2022/2/1
-- Description: Retrieves a cohort by Id.
-- =======================================
CREATE PROCEDURE [app].[sp_GetCohortById]
@id [uniqueidentifier],
@user auth.[User],
@groups auth.GroupMembership READONLY,
@exportedOnly bit,
@admin bit = 0
AS
BEGIN
SET NOCOUNT ON;

DECLARE @result TABLE (
QueryId UNIQUEIDENTIFIER NOT NULL,
PersonId nvarchar(200) NOT NULL,
Exported bit NOT NULL,
Salt UNIQUEIDENTIFIER
);

-- if not found
IF @id IS NULL
BEGIN
SELECT QueryId, PersonId, Exported, Salt
FROM @result;
RETURN;
END;

-- Admin can access any query
IF (@admin = 1)
INSERT INTO @result (QueryId, PersonId, Exported, Salt)
SELECT C.QueryId, C.PersonId, C.Exported, C.Salt
FROM app.Cohort AS C
WHERE C.QueryId = @id
AND (@exportedOnly = 0 OR Exported = 1)
ELSE
BEGIN
-- permission filter
WITH permitted AS (
-- user based constraint
SELECT
QueryId
FROM auth.QueryConstraint
WHERE QueryId = @id
AND ConstraintId = 1
AND ConstraintValue = @user
UNION
-- group base constraint
SELECT
QueryId
FROM auth.QueryConstraint
WHERE QueryId = @id
AND ConstraintId = 2
AND ConstraintValue IN (SELECT [Group] FROM @groups)
)
INSERT INTO @result (QueryId, PersonId, Exported, Salt)
SELECT C.QueryId, C.PersonId, C.Exported, C.Salt
FROM app.Cohort AS C
INNER JOIN app.Query AS Q ON C.QueryId = Q.Id
WHERE (Q.[Owner] = @user OR Q.Id IN (SELECT Id FROM permitted))
AND Q.Id = @id
AND (@exportedOnly = 0 OR Exported = 1);
END

-- did not pass filter
IF (SELECT COUNT(*) FROM @result) < 1
BEGIN
DECLARE @secmsg nvarchar(400) = @user + ' not permitted to query ' + CONVERT(NVARCHAR(100), @id);
THROW 70403, @secmsg, 1
END;

-- return
SELECT QueryId, PersonId, Exported, Salt
FROM @result;
END


GO
/****** Object: StoredProcedure [app].[sp_GetConceptById] Script Date: ******/
SET ANSI_NULLS ON
Expand Down
94 changes: 0 additions & 94 deletions src/db/migration/dashboard.sql

This file was deleted.

2 changes: 1 addition & 1 deletion src/db/obj/LeafDB.Database.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ CREATE DATABASE [LeafDB]
ON PRIMARY
( NAME = N'LeafDB', FILENAME = N'/var/opt/mssql/data/LeafDB.mdf' , SIZE = 73728KB , MAXSIZE = UNLIMITED, FILEGROWTH = 65536KB )
LOG ON
( NAME = N'LeafDB_log', FILENAME = N'/var/opt/mssql/data/LeafDB_log.ldf' , SIZE = 335872KB , MAXSIZE = 2048GB , FILEGROWTH = 65536KB )
( NAME = N'LeafDB_log', FILENAME = N'/var/opt/mssql/data/LeafDB_log.ldf' , SIZE = 204800KB , MAXSIZE = 2048GB , FILEGROWTH = 65536KB )
GO
IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
begin
Expand Down
Loading

0 comments on commit 25bbe19

Please sign in to comment.