Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Coscine
backend
apis
Project
Commits
53e20e81
Commit
53e20e81
authored
Mar 30, 2020
by
Marcel Nellesen
Browse files
Merge branch 'Sprint/2020-05' into 'master'
Sprint/2020-05 See merge request coscine/api/project!79
parents
4a610113
6686d515
Changes
11
Pipelines
3
Hide whitespace changes
Inline
Side-by-side
src/Project.Tests/DefaultControllerTests.cs
View file @
53e20e81
...
...
@@ -17,6 +17,9 @@ using System.Security.Claims;
using
LinqToDB.Data
;
using
Coscine.Database.Settings
;
using
Coscine.Configuration
;
using
Microsoft.Extensions.Logging
;
using
Microsoft.Extensions.Logging.Abstractions
;
using
Coscine.Logging
;
namespace
Coscine.Api.Project.Tests
{
...
...
@@ -44,6 +47,20 @@ namespace Coscine.Api.Project.Tests
Controller
=
controller
;
}
private
static
ILogger
<
ProjectController
>
projectLogger
=
null
;
private
static
ILogger
<
ProjectController
>
ProjectLogger
{
get
{
if
(
projectLogger
==
null
)
{
CoscineLoggerConfiguration
.
SetConfig
();
projectLogger
=
new
NullLogger
<
ProjectController
>();
}
return
projectLogger
;
}
}
[
OneTimeSetUp
]
public
void
Setup
()
{
...
...
@@ -294,7 +311,7 @@ namespace Coscine.Api.Project.Tests
{
projectResourceModel
.
Delete
(
projectResource
);
}
ProjectController
projectController
=
new
ProjectController
();
ProjectController
projectController
=
new
ProjectController
(
ProjectLogger
);
foreach
(
var
project
in
Projects
)
{
projectController
.
DeleteProject
(
project
,
true
,
false
);
...
...
src/Project.Tests/Project.Tests.csproj
View file @
53e20e81
...
...
@@ -59,17 +59,17 @@
<Reference
Include=
"Coscine.Action, Version=1.10.0.0, Culture=neutral, processorArchitecture=AMD64"
>
<HintPath>
..\packages\Coscine.Action.1.10.0\lib\net461\Coscine.Action.dll
</HintPath>
</Reference>
<Reference
Include=
"Coscine.ApiCommons, Version=1.
6.3
.0, Culture=neutral, PublicKeyToken=af4c1345df96546b, processorArchitecture=MSIL"
>
<HintPath>
..\packages\Coscine.ApiCommons.1.
6.3
\lib\net461\Coscine.ApiCommons.dll
</HintPath>
<Reference
Include=
"Coscine.ApiCommons, Version=1.
7.0
.0, Culture=neutral, PublicKeyToken=af4c1345df96546b, processorArchitecture=MSIL"
>
<HintPath>
..\packages\Coscine.ApiCommons.1.
7.0
\lib\net461\Coscine.ApiCommons.dll
</HintPath>
</Reference>
<Reference
Include=
"Coscine.Configuration, Version=1.
4
.0.0, Culture=neutral, PublicKeyToken=ce3d7a32d7dc1e5a, processorArchitecture=MSIL"
>
<HintPath>
..\packages\Coscine.Configuration.1.
4
.0\lib\net461\Coscine.Configuration.dll
</HintPath>
<Reference
Include=
"Coscine.Configuration, Version=1.
5
.0.0, Culture=neutral, PublicKeyToken=ce3d7a32d7dc1e5a, processorArchitecture=MSIL"
>
<HintPath>
..\packages\Coscine.Configuration.1.
5
.0\lib\net461\Coscine.Configuration.dll
</HintPath>
</Reference>
<Reference
Include=
"Coscine.Database, Version=1.1
6
.0.0, Culture=neutral, PublicKeyToken=767d77427707b70a, processorArchitecture=MSIL"
>
<HintPath>
..\packages\Coscine.Database.1.1
6
.0\lib\net461\Coscine.Database.dll
</HintPath>
<Reference
Include=
"Coscine.Database, Version=1.1
7
.0.0, Culture=neutral, PublicKeyToken=767d77427707b70a, processorArchitecture=MSIL"
>
<HintPath>
..\packages\Coscine.Database.1.1
7
.0\lib\net461\Coscine.Database.dll
</HintPath>
</Reference>
<Reference
Include=
"Coscine.Logging, Version=1.
0.1
.0, Culture=neutral, PublicKeyToken=e1ed402bc3f6525e, processorArchitecture=MSIL"
>
<HintPath>
..\packages\Coscine.Logging.1.
0.1
\lib\net461\Coscine.Logging.dll
</HintPath>
<Reference
Include=
"Coscine.Logging, Version=1.
1.0
.0, Culture=neutral, PublicKeyToken=e1ed402bc3f6525e, processorArchitecture=MSIL"
>
<HintPath>
..\packages\Coscine.Logging.1.
1.0
\lib\net461\Coscine.Logging.dll
</HintPath>
</Reference>
<Reference
Include=
"Coscine.ProxyApi, Version=1.2.1.0, Culture=neutral, processorArchitecture=MSIL"
>
<HintPath>
..\packages\Coscine.ProxyApi.1.2.1\lib\net461\Coscine.ProxyApi.dll
</HintPath>
...
...
src/Project.Tests/ProjectControllerTests.cs
View file @
53e20e81
...
...
@@ -9,15 +9,31 @@ using System;
using
Coscine.ApiCommons.Factories
;
using
System.Collections.Generic
;
using
Coscine.Database.Util
;
using
Microsoft.Extensions.Logging
;
using
Moq
;
using
Microsoft.Extensions.Logging.Abstractions
;
using
Coscine.Logging
;
namespace
Coscine.Api.Project.Tests
{
[
TestFixture
]
public
class
ProjectControllerTests
:
DefaultControllerTests
<
ProjectController
>
{
public
ProjectControllerTests
()
:
base
(
new
ProjectController
())
private
static
ILogger
<
ProjectController
>
projectLogger
=
null
;
private
static
ILogger
<
ProjectController
>
ProjectLogger
{
get
{
if
(
projectLogger
==
null
)
{
CoscineLoggerConfiguration
.
SetConfig
();
projectLogger
=
new
NullLogger
<
ProjectController
>();
}
return
projectLogger
;
}
}
public
ProjectControllerTests
()
:
base
(
new
ProjectController
(
ProjectLogger
))
{
}
[
Test
]
...
...
src/Project.Tests/app.config
View file @
53e20e81
...
...
@@ -88,7 +88,7 @@
</
dependentAssembly
>
<
dependentAssembly
>
<
assemblyIdentity
name
=
"Coscine.Database"
publicKeyToken
=
"767d77427707b70a"
culture
=
"neutral"
/>
<
bindingRedirect
oldVersion
=
"0.0.0.0-1.1
6
.0.0"
newVersion
=
"1.1
6
.0.0"
/>
<
bindingRedirect
oldVersion
=
"0.0.0.0-1.1
7
.0.0"
newVersion
=
"1.1
7
.0.0"
/>
</
dependentAssembly
>
<
dependentAssembly
>
<
assemblyIdentity
name
=
"System.IdentityModel.Tokens.Jwt"
publicKeyToken
=
"31bf3856ad364e35"
culture
=
"neutral"
/>
...
...
@@ -140,7 +140,7 @@
</
dependentAssembly
>
<
dependentAssembly
>
<
assemblyIdentity
name
=
"Coscine.Logging"
publicKeyToken
=
"e1ed402bc3f6525e"
culture
=
"neutral"
/>
<
bindingRedirect
oldVersion
=
"0.0.0.0-1.
0.1
.0"
newVersion
=
"1.
0.1
.0"
/>
<
bindingRedirect
oldVersion
=
"0.0.0.0-1.
1.0
.0"
newVersion
=
"1.
1.0
.0"
/>
</
dependentAssembly
>
<
dependentAssembly
>
<
assemblyIdentity
name
=
"Microsoft.IdentityModel.Logging"
publicKeyToken
=
"31bf3856ad364e35"
culture
=
"neutral"
/>
...
...
@@ -150,6 +150,10 @@
<
assemblyIdentity
name
=
"LinqKit"
publicKeyToken
=
"bc217f8844052a91"
culture
=
"neutral"
/>
<
bindingRedirect
oldVersion
=
"0.0.0.0-1.1.17.0"
newVersion
=
"1.1.17.0"
/>
</
dependentAssembly
>
<
dependentAssembly
>
<
assemblyIdentity
name
=
"Coscine.Configuration"
publicKeyToken
=
"ce3d7a32d7dc1e5a"
culture
=
"neutral"
/>
<
bindingRedirect
oldVersion
=
"0.0.0.0-1.5.0.0"
newVersion
=
"1.5.0.0"
/>
</
dependentAssembly
>
</
assemblyBinding
>
</
runtime
>
<
entityFramework
>
...
...
src/Project.Tests/packages.config
View file @
53e20e81
...
...
@@ -5,10 +5,10 @@
<
package
id
=
"Castle.Core"
version
=
"4.4.0"
targetFramework
=
"net472"
/>
<
package
id
=
"Consul"
version
=
"0.7.2.6"
targetFramework
=
"net472"
/>
<
package
id
=
"Coscine.Action"
version
=
"1.10.0"
targetFramework
=
"net472"
/>
<
package
id
=
"Coscine.ApiCommons"
version
=
"1.
6.3
"
targetFramework
=
"net472"
/>
<
package
id
=
"Coscine.Configuration"
version
=
"1.
4
.0"
targetFramework
=
"net472"
/>
<
package
id
=
"Coscine.Database"
version
=
"1.1
6
.0"
targetFramework
=
"net472"
/>
<
package
id
=
"Coscine.Logging"
version
=
"1.
0.1
"
targetFramework
=
"net472"
/>
<
package
id
=
"Coscine.ApiCommons"
version
=
"1.
7.0
"
targetFramework
=
"net472"
/>
<
package
id
=
"Coscine.Configuration"
version
=
"1.
5
.0"
targetFramework
=
"net472"
/>
<
package
id
=
"Coscine.Database"
version
=
"1.1
7
.0"
targetFramework
=
"net472"
/>
<
package
id
=
"Coscine.Logging"
version
=
"1.
1.0
"
targetFramework
=
"net472"
/>
<
package
id
=
"Coscine.ProxyApi"
version
=
"1.2.1"
targetFramework
=
"net472"
/>
<
package
id
=
"Coscine.SharePoint.Webparts.Vue"
version
=
"1.5.0"
targetFramework
=
"net472"
/>
<
package
id
=
"EntityFramework"
version
=
"6.2.0"
targetFramework
=
"net472"
/>
...
...
src/Project/App.config
View file @
53e20e81
...
...
@@ -91,7 +91,7 @@
</
dependentAssembly
>
<
dependentAssembly
>
<
assemblyIdentity
name
=
"Coscine.Database"
publicKeyToken
=
"767d77427707b70a"
culture
=
"neutral"
/>
<
bindingRedirect
oldVersion
=
"0.0.0.0-1.1
6
.0.0"
newVersion
=
"1.1
6
.0.0"
/>
<
bindingRedirect
oldVersion
=
"0.0.0.0-1.1
7
.0.0"
newVersion
=
"1.1
7
.0.0"
/>
</
dependentAssembly
>
<
dependentAssembly
>
<
assemblyIdentity
name
=
"System.IdentityModel.Tokens.Jwt"
publicKeyToken
=
"31bf3856ad364e35"
culture
=
"neutral"
/>
...
...
@@ -143,7 +143,7 @@
</
dependentAssembly
>
<
dependentAssembly
>
<
assemblyIdentity
name
=
"Coscine.Logging"
publicKeyToken
=
"e1ed402bc3f6525e"
culture
=
"neutral"
/>
<
bindingRedirect
oldVersion
=
"0.0.0.0-1.
0.1
.0"
newVersion
=
"1.
0.1
.0"
/>
<
bindingRedirect
oldVersion
=
"0.0.0.0-1.
1.0
.0"
newVersion
=
"1.
1.0
.0"
/>
</
dependentAssembly
>
<
dependentAssembly
>
<
assemblyIdentity
name
=
"Microsoft.IdentityModel.Logging"
publicKeyToken
=
"31bf3856ad364e35"
culture
=
"neutral"
/>
...
...
@@ -153,6 +153,10 @@
<
assemblyIdentity
name
=
"LinqKit"
publicKeyToken
=
"bc217f8844052a91"
culture
=
"neutral"
/>
<
bindingRedirect
oldVersion
=
"0.0.0.0-1.1.17.0"
newVersion
=
"1.1.17.0"
/>
</
dependentAssembly
>
<
dependentAssembly
>
<
assemblyIdentity
name
=
"Coscine.Configuration"
publicKeyToken
=
"ce3d7a32d7dc1e5a"
culture
=
"neutral"
/>
<
bindingRedirect
oldVersion
=
"0.0.0.0-1.5.0.0"
newVersion
=
"1.5.0.0"
/>
</
dependentAssembly
>
</
assemblyBinding
>
</
runtime
>
<
entityFramework
>
...
...
src/Project/Controllers/ProjectController.cs
View file @
53e20e81
...
...
@@ -10,6 +10,11 @@ using System.Linq;
using
Coscine.Configuration
;
using
Microsoft.AspNetCore.Authorization
;
using
Coscine.Database.Util
;
using
Coscine.Logging
;
using
Microsoft.Extensions.Logging
;
using
Newtonsoft.Json.Linq
;
using
Coscine.Database.DataModel
;
using
System.Collections.Generic
;
namespace
Coscine.Api.Project.Controllers
{
...
...
@@ -20,24 +25,33 @@ namespace Coscine.Api.Project.Controllers
private
readonly
ProjectModel
_projectModel
;
private
readonly
IConfiguration
_configuration
;
private
readonly
Emitter
_emitter
;
private
readonly
ProjectRoleModel
_projectRoleModel
;
private
readonly
CoscineLogger
_coscineLogger
;
private
readonly
AnalyticsLogObject
_analyticsLogObject
;
public
ProjectController
()
public
ProjectController
(
ILogger
<
ProjectController
>
logger
)
{
_authenticator
=
new
Authenticator
(
this
,
Program
.
Configuration
);
_configuration
=
Program
.
Configuration
;
_projectModel
=
new
ProjectModel
();
_emitter
=
new
Emitter
(
_configuration
);
_projectRoleModel
=
new
ProjectRoleModel
();
_coscineLogger
=
new
CoscineLogger
(
logger
);
_analyticsLogObject
=
new
AnalyticsLogObject
();
}
[
Route
(
"[controller]"
)]
public
IActionResult
Index
()
{
var
user
=
_authenticator
.
GetUser
();
return
Ok
(
_projectModel
.
GetWithAccess
(
user
,
UserRoles
.
Member
,
UserRoles
.
Owner
).
ToList
()
var
result
=
_projectModel
.
GetWithAccess
(
user
,
UserRoles
.
Member
,
UserRoles
.
Owner
).
ToList
()
.
Select
((
project
)
=>
_projectModel
.
CreateReturnObjectFromDatabaseObject
(
project
))
.
OrderBy
(
element
=>
element
.
DisplayName
)
);
.
OrderBy
(
element
=>
element
.
DisplayName
);
LogAnalytics
(
"View Home"
,
result
);
return
Ok
(
result
);
}
[
HttpGet
(
"[controller]/{id}"
)]
...
...
@@ -73,14 +87,18 @@ namespace Coscine.Api.Project.Controllers
var
resourceTypeModel
=
new
ResourceTypeModel
();
if
(
_projectModel
.
HasAccess
(
user
,
project
,
UserRoles
.
Member
,
UserRoles
.
Owner
))
{
return
Json
(
resourceModel
.
GetAllWhere
((
resource
)
=>
var
resources
=
resourceModel
.
GetAllWhere
((
resource
)
=>
(
from
projectResource
in
resource
.
ProjectResourceResourceIdIds
where
projectResource
.
ProjectId
==
project
.
Id
select
projectResource
).
Any
())
.
Select
((
resource
)
=>
{
return
resourceModel
.
CreateReturnObjectFromDatabaseObject
(
resource
);
}).
OrderBy
(
element
=>
element
.
DisplayName
));
}).
OrderBy
(
element
=>
element
.
DisplayName
);
LogAnalytics
(
"View Resources"
,
null
,
resources
);
return
Json
(
resources
);
}
else
{
...
...
@@ -94,8 +112,9 @@ namespace Coscine.Api.Project.Controllers
var
user
=
_authenticator
.
GetUser
();
var
projectObject
=
ObjectFactory
<
ProjectObject
>.
DeserializeFromStream
(
Request
.
Body
);
var
project
=
_projectModel
.
GetById
(
Guid
.
Parse
(
id
));
if
(
_projectModel
.
HasAccess
(
user
,
project
,
UserRoles
.
Owner
))
if
(
_projectModel
.
HasAccess
(
user
,
project
,
UserRoles
.
Owner
))
{
LogAnalytics
(
"Edit Project"
,
null
,
null
,
id
,
user
);
return
Ok
(
_projectModel
.
UpdateByObject
(
project
,
projectObject
));
}
else
...
...
@@ -111,6 +130,7 @@ namespace Coscine.Api.Project.Controllers
var
project
=
_projectModel
.
GetById
(
Guid
.
Parse
(
id
));
if
(
_projectModel
.
HasAccess
(
user
,
project
,
UserRoles
.
Owner
))
{
LogAnalytics
(
"Delete Project"
,
null
,
null
,
id
,
user
);
DeleteProject
(
project
);
return
Json
(
_projectModel
.
CreateReturnObjectFromDatabaseObject
(
project
));
}
...
...
@@ -238,7 +258,51 @@ namespace Coscine.Api.Project.Controllers
ProjectOwner
=
user
});
LogAnalytics
(
"Add Project"
,
null
,
null
,
project
.
Id
.
ToString
(),
user
);
return
Json
(
_projectModel
.
CreateReturnObjectFromDatabaseObject
(
project
));
}
private
void
LogAnalytics
(
string
operation
,
IEnumerable
<
ProjectObject
>
projects
=
null
,
IEnumerable
<
ResourceObject
>
resources
=
null
,
string
projectId
=
null
,
User
user
=
null
)
{
if
(
CoscineLoggerConfiguration
.
IsLogLevelActivated
(
LogType
.
Analytics
))
{
_analyticsLogObject
.
Type
=
"Action"
;
_analyticsLogObject
.
Operation
=
operation
;
if
(
projects
!=
null
)
{
List
<
string
>
projectList
=
new
List
<
string
>();
foreach
(
var
entry
in
projects
)
{
projectList
.
Add
(
entry
.
Id
.
ToString
());
}
_analyticsLogObject
.
ProjectList
=
projectList
;
}
if
(
resources
!=
null
)
{
List
<
string
>
shownResources
=
new
List
<
string
>();
foreach
(
var
entry
in
resources
)
{
shownResources
.
Add
(
entry
.
Id
.
ToString
());
}
_analyticsLogObject
.
ResourceList
=
shownResources
;
}
if
(
projectId
!=
null
)
{
_analyticsLogObject
.
ProjectId
=
projectId
;
if
(
user
!=
null
)
{
_analyticsLogObject
.
RoleId
=
_projectRoleModel
.
GetGetUserRoleForProject
(
new
Guid
(
_analyticsLogObject
.
ProjectId
),
user
.
Id
).
ToString
();
}
}
_coscineLogger
.
AnalyticsLog
(
_analyticsLogObject
);
}
}
}
}
src/Project/Controllers/ProjectRoleController.cs
View file @
53e20e81
...
...
@@ -10,6 +10,11 @@ using Microsoft.AspNetCore.Mvc;
using
System
;
using
System.Linq
;
using
Coscine.Database.Util
;
using
Coscine.Logging
;
using
Microsoft.Extensions.Logging
;
using
Newtonsoft.Json.Linq
;
using
System.Collections.Generic
;
using
Coscine.Database.DataModel
;
namespace
Coscine.Api.Project.Controllers
{
...
...
@@ -20,13 +25,18 @@ namespace Coscine.Api.Project.Controllers
private
readonly
ProjectRoleModel
_projectRoleModel
;
private
readonly
Emitter
_emitter
;
private
readonly
IConfiguration
_configuration
;
private
readonly
CoscineLogger
_coscineLogger
;
private
readonly
AnalyticsLogObject
_analyticsLogObject
;
public
ProjectRoleController
()
public
ProjectRoleController
(
ILogger
<
ProjectRoleController
>
logger
)
{
_emitter
=
new
Emitter
(
Program
.
Configuration
);
_authenticator
=
new
Authenticator
(
this
,
Program
.
Configuration
);
_projectRoleModel
=
new
ProjectRoleModel
();
_configuration
=
Program
.
Configuration
;
_coscineLogger
=
new
CoscineLogger
(
logger
);
_analyticsLogObject
=
new
AnalyticsLogObject
();
}
[
Route
(
"[controller]/{projectId}"
)]
...
...
@@ -40,7 +50,7 @@ namespace Coscine.Api.Project.Controllers
if
(
projectModel
.
HasAccess
(
user
,
projectModel
.
GetById
(
projectIdGuid
),
UserRoles
.
Owner
,
UserRoles
.
Member
))
{
return
Json
(
_projectRoleModel
.
GetAllWhere
((
projectRole
)
=>
var
users
=
_projectRoleModel
.
GetAllWhere
((
projectRole
)
=>
(
projectRole
.
ProjectId
==
projectIdGuid
)
).
Select
((
projectRole
)
=>
{
...
...
@@ -55,7 +65,10 @@ namespace Coscine.Api.Project.Controllers
role
=
roleModel
.
GetById
(
projectRole
.
RoleId
);
}
return
new
ProjectRoleObject
(
projectRole
.
ProjectId
,
new
UserObject
(
userInst
.
Id
,
userInst
.
DisplayName
,
userInst
.
Givenname
,
userInst
.
Surname
,
userInst
.
EmailAddress
),
new
RoleObject
(
role
.
Id
,
role
.
DisplayName
));
}));
});
LogAnalytics
(
"View Users"
,
user
,
users
);
return
Json
(
users
);
}
else
{
...
...
@@ -63,6 +76,8 @@ namespace Coscine.Api.Project.Controllers
}
}
//Get all roles for current user and given project
[
HttpGet
(
"[controller]/project/{projectId}"
)]
public
IActionResult
Get
(
string
projectId
)
...
...
@@ -98,12 +113,16 @@ namespace Coscine.Api.Project.Controllers
if
(
projectModel
.
HasAccess
(
user
,
project
,
UserRoles
.
Owner
))
{
var
userIsAlreadymember
=
projectModel
.
HasAccess
(
userToAdd
,
project
,
UserRoles
.
Owner
,
UserRoles
.
Member
);
_emitter
.
EmitUserAdd
(
new
UserEventArgs
(
_configuration
)
{
Project
=
project
,
Role
=
role
,
User
=
userToAdd
});
LogAnalytics
(
userIsAlreadymember
==
true
?
"Change Role"
:
"Add Member"
,
user
,
null
,
project
.
Id
.
ToString
());
return
Json
(
_projectRoleModel
.
SetFromObject
(
projectRoleObject
));
}
else
...
...
@@ -132,6 +151,8 @@ namespace Coscine.Api.Project.Controllers
User
=
userToRemove
});
LogAnalytics
(
"Remove User"
,
user
,
null
,
project
.
Id
.
ToString
());
return
Json
(
_projectRoleModel
.
Delete
(
_projectRoleModel
.
GetWhere
((
projectRole
)
=>
projectRole
.
ProjectId
==
projectId
&&
projectRole
.
UserId
==
userId
...
...
@@ -142,5 +163,34 @@ namespace Coscine.Api.Project.Controllers
return
Unauthorized
(
"The user is not authorized to delete a project role for the given project!"
);
}
}
private
void
LogAnalytics
(
string
operation
,
User
user
,
IEnumerable
<
ProjectRoleObject
>
users
=
null
,
string
projectId
=
null
)
{
if
(
CoscineLoggerConfiguration
.
IsLogLevelActivated
(
LogType
.
Analytics
))
{
_analyticsLogObject
.
Type
=
"Action"
;
_analyticsLogObject
.
Operation
=
operation
;
if
(
users
!=
null
)
{
List
<
string
>
shownUsers
=
new
List
<
string
>();
foreach
(
var
entry
in
users
)
{
shownUsers
.
Add
(
entry
.
User
.
Id
.
ToString
());
}
_analyticsLogObject
.
UserList
=
shownUsers
;
}
if
(
projectId
!=
null
)
{
_analyticsLogObject
.
ProjectId
=
projectId
;
_analyticsLogObject
.
RoleId
=
_projectRoleModel
.
GetGetUserRoleForProject
(
new
Guid
(
_analyticsLogObject
.
ProjectId
),
user
.
Id
).
ToString
();
}
_coscineLogger
.
AnalyticsLog
(
_analyticsLogObject
);
}
}
}
}
src/Project/Controllers/SearchController.cs
View file @
53e20e81
...
...
@@ -9,6 +9,9 @@ using Newtonsoft.Json;
using
Newtonsoft.Json.Linq
;
using
Microsoft.AspNetCore.Authorization
;
using
Coscine.Database.Util
;
using
Microsoft.Extensions.Logging
;
using
Coscine.Database.Models
;
using
Coscine.Logging
;
namespace
Coscine.Api.Project.Controllers
{
...
...
@@ -16,10 +19,17 @@ namespace Coscine.Api.Project.Controllers
public
class
SearchController
:
Controller
{
private
readonly
Authenticator
_authenticator
;
private
readonly
ProjectRoleModel
_projectRoleModel
;
private
readonly
CoscineLogger
_coscineLogger
;
private
readonly
AnalyticsLogObject
_analyticsLogObject
;
public
SearchController
()
public
SearchController
(
ILogger
<
SearchController
>
logger
)
{
_authenticator
=
new
Authenticator
(
this
,
Program
.
Configuration
);
_projectRoleModel
=
new
ProjectRoleModel
();
_coscineLogger
=
new
CoscineLogger
(
logger
);
_analyticsLogObject
=
new
AnalyticsLogObject
();
}
[
HttpGet
(
"[controller]/allNoFilter/"
)]
...
...
@@ -96,11 +106,10 @@ namespace Coscine.Api.Project.Controllers
// search and ad results for sub-projects
json
[
"SubProjects"
]
=
SearchForProjects
(
userId
,
searchQuery
,
projectId
,
list
,
true
);
LogAnalytics
(
"View Search Results"
,
userId
,
projectId
,
json
);
return
json
;
}
private
List
<
Guid
>
GetAllSubProjects
(
string
projectId
)
{
var
list
=
new
List
<
Guid
>();
...
...
@@ -216,5 +225,38 @@ namespace Coscine.Api.Project.Controllers
});
}
private
void
LogAnalytics
(
string
operation
,
Guid
userId
,
string
projectId
,
JObject
json
)
{
if
(
CoscineLoggerConfiguration
.
IsLogLevelActivated
(
LogType
.
Analytics
))
{
List
<
string
>
projects
=
new
List
<
string
>();
foreach
(
var
entry
in
json
[
"Projects"
])
{
projects
.
Add
(
entry
[
"Id"
].
ToString
());
}
foreach
(
var
entry
in
json
[
"SubProjects"
])
{
projects
.
Add
(
entry
[
"Id"
].
ToString
());
}
List
<
string
>
resources
=
new
List
<
string
>();
foreach
(
var
entry
in
json
[
"Resources"
])
{
resources
.
Add
(
entry
[
"Id"
].
ToString
());
}
_analyticsLogObject
.
Type
=
"Action"
;
_analyticsLogObject
.
Operation
=
operation
;
if
(!
projectId
.
Equals
(
""
))
{
_analyticsLogObject
.
ProjectId
=
projectId
;
_analyticsLogObject
.
RoleId
=
_projectRoleModel
.
GetGetUserRoleForProject
(
new
Guid
(
_analyticsLogObject
.
ProjectId
),
userId
).
ToString
();
}
_analyticsLogObject
.
ProjectList
=
projects
;
_analyticsLogObject
.
ResourceList
=
resources
;
_coscineLogger
.
AnalyticsLog
(
_analyticsLogObject
);
}
}
}
}
\ No newline at end of file
src/Project/Project.csproj
View file @
53e20e81
...
...
@@ -52,17 +52,17 @@
<Reference
Include=
"Coscine.Action, Version=1.10.0.0, Culture=neutral, processorArchitecture=AMD64"
>
<HintPath>
..\packages\Coscine.Action.1.10.0\lib\net461\Coscine.Action.dll
</HintPath>
</Reference>
<Reference
Include=
"Coscine.ApiCommons, Version=1.
6.3
.0, Culture=neutral, PublicKeyToken=af4c1345df96546b, processorArchitecture=MSIL"
>
<HintPath>
..\packages\Coscine.ApiCommons.1.
6.3
\lib\net461\Coscine.ApiCommons.dll
</HintPath>
<Reference
Include=
"Coscine.ApiCommons, Version=1.
7.0
.0, Culture=neutral, PublicKeyToken=af4c1345df96546b, processorArchitecture=MSIL"
>
<HintPath>
..\packages\Coscine.ApiCommons.1.
7.0
\lib\net461\Coscine.ApiCommons.dll
</HintPath>
</Reference>
<Reference
Include=
"Coscine.Configuration, Version=1.
4
.0.0, Culture=neutral, PublicKeyToken=ce3d7a32d7dc1e5a, processorArchitecture=MSIL"
>
<HintPath>
..\packages\Coscine.Configuration.1.
4
.0\lib\net461\Coscine.Configuration.dll
</HintPath>
<Reference
Include=
"Coscine.Configuration, Version=1.
5
.0.0, Culture=neutral, PublicKeyToken=ce3d7a32d7dc1e5a, processorArchitecture=MSIL"
>
<HintPath>
..\packages\Coscine.Configuration.1.
5
.0\lib\net461\Coscine.Configuration.dll
</HintPath>
</Reference>
<Reference
Include=
"Coscine.Database, Version=1.1
6
.0.0, Culture=neutral, PublicKeyToken=767d77427707b70a, processorArchitecture=MSIL"
>
<HintPath>
..\packages\Coscine.Database.1.1
6
.0\lib\net461\Coscine.Database.dll
</HintPath>
<Reference
Include=
"Coscine.Database, Version=1.1
7
.0.0, Culture=neutral, PublicKeyToken=767d77427707b70a, processorArchitecture=MSIL"
>
<HintPath>
..\packages\Coscine.Database.1.1
7
.0\lib\net461\Coscine.Database.dll
</HintPath>
</Reference>
<Reference
Include=
"Coscine.Logging, Version=1.
0.1
.0, Culture=neutral, PublicKeyToken=e1ed402bc3f6525e, processorArchitecture=MSIL"
>
<HintPath>
..\packages\Coscine.Logging.1.
0.1
\lib\net461\Coscine.Logging.dll
</HintPath>
<Reference
Include=
"Coscine.Logging, Version=1.
1.0
.0, Culture=neutral, PublicKeyToken=e1ed402bc3f6525e, processorArchitecture=MSIL"
>
<HintPath>
..\packages\Coscine.Logging.1.
1.0
\lib\net461\Coscine.Logging.dll
</HintPath>
</Reference>
<Reference
Include=
"Coscine.ProxyApi, Version=1.2.1.0, Culture=neutral, processorArchitecture=MSIL"
>
<HintPath>
..\packages\Coscine.ProxyApi.1.2.1\lib\net461\Coscine.ProxyApi.dll
</HintPath>
...
...
src/Project/packages.config
View file @
53e20e81
...
...
@@ -5,10 +5,10 @@
<
package
id
=
"Castle.Core"
version
=
"4.4.0"
targetFramework
=
"net472"
/>
<
package
id
=
"Consul"
version
=
"0.7.2.6"
targetFramework
=
"net472"
/>
<
package
id
=
"Coscine.Action"
version
=
"1.10.0"
targetFramework
=
"net472"
/>
<
package
id
=
"Coscine.ApiCommons"
version
=
"1.
6.3
"
targetFramework
=
"net472"
/>
<
package
id
=
"Coscine.Configuration"
version
=
"1.
4
.0"
targetFramework
=
"net472"
/>
<
package
id
=
"Coscine.Database"
version
=
"1.1
6
.0"
targetFramework
=
"net472"
/>
<
package
id
=
"Coscine.Logging"
version
=
"1.
0.1
"
targetFramework
=
"net472"
/>
<
package
id
=
"Coscine.ApiCommons"
version
=
"1.
7.0
"
targetFramework
=
"net472"
/>
<
package
id
=
"Coscine.Configuration"
version
=
"1.
5
.0"
targetFramework
=
"net472"
/>
<
package
id
=
"Coscine.Database"
version
=
"1.1
7
.0"
targetFramework
=
"net472"
/>
<
package
id
=
"Coscine.Logging"
version
=
"1.
1.0
"
targetFramework
=
"net472"
/>
<
package
id
=
"Coscine.ProxyApi"
version
=
"1.2.1"
targetFramework
=
"net472"
/>
<
package
id
=
"Coscine.SharePoint.Webparts.Vue"
version
=
"1.5.0"
targetFramework
=
"net472"
/>
<
package
id
=
"EntityFramework"
version
=
"6.2.0"
targetFramework
=
"net472"
/>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment