Skip to content

Commit

Permalink
Grant project owners access to the data statistics page (#1970)
Browse files Browse the repository at this point in the history
* Allow project owners to access the Data Statistics tab

* Include the projectID parameter in the route when calling the statistic API

* Correct the permission checking process for project owners in the StatisticsController
  • Loading branch information
fuencui authored Mar 21, 2023
1 parent c0370d9 commit 2244168
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 70 deletions.
12 changes: 6 additions & 6 deletions Backend/Controllers/StatisticsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ namespace BackendFramework.Controllers
{
[Authorize]
[Produces("application/json")]
[Route("v1/statistics")]
[Route("v1/projects/{projectId}/statistics")]


public class StatisticsController : Controller
{
Expand All @@ -33,7 +34,7 @@ public StatisticsController(IStatisticsService staService, IPermissionService pe
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(List<SemanticDomainCount>))]
public async Task<IActionResult> GetSemanticDomainCounts(string projectId, string lang)
{
if (!await _permissionService.HasProjectPermission(HttpContext, Permission.WordEntry))
if (!await _permissionService.HasProjectPermission(HttpContext, Permission.Owner))
{
return Forbid();
}
Expand All @@ -55,7 +56,7 @@ public async Task<IActionResult> GetSemanticDomainCounts(string projectId, strin
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(List<WordsPerDayPerUserCount>))]
public async Task<IActionResult> GetWordsPerDayPerUserCounts(string projectId)
{
if (!await _permissionService.HasProjectPermission(HttpContext, Permission.WordEntry))
if (!await _permissionService.HasProjectPermission(HttpContext, Permission.Owner))
{
return Forbid();
}
Expand All @@ -76,7 +77,7 @@ public async Task<IActionResult> GetWordsPerDayPerUserCounts(string projectId)
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(ChartRootData))]
public async Task<IActionResult> GetLineChartRootData(string projectId)
{
if (!await _permissionService.HasProjectPermission(HttpContext, Permission.WordEntry))
if (!await _permissionService.HasProjectPermission(HttpContext, Permission.Owner))
{
return Forbid();
}
Expand All @@ -93,14 +94,13 @@ public async Task<IActionResult> GetLineChartRootData(string projectId)




/// <summary> Get a list of SemanticDomainUserCount <see cref="SemanticDomainUserCount"/>s of a specific project in order </summary>
/// <returns> A list of SemanticDomainUserCount <see cref="SemanticDomainUserCount"/>s </returns>
[HttpGet("GetSemanticDomainUserCounts", Name = "GetSemanticDomainUserCounts")]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(List<SemanticDomainUserCount>))]
public async Task<IActionResult> GetSemanticDomainUserCounts(string projectId, string lang)
{
if (!await _permissionService.HasProjectPermission(HttpContext, Permission.WordEntry))
if (!await _permissionService.HasProjectPermission(HttpContext, Permission.Owner))
{
return Forbid();
}
Expand Down
112 changes: 60 additions & 52 deletions src/api/api/statistics-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,21 @@ export const StatisticsApiAxiosParamCreator = function (
return {
/**
*
* @param {string} [projectId]
* @param {string} projectId
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
getLineChartRootData: async (
projectId?: string,
projectId: string,
options: any = {}
): Promise<RequestArgs> => {
const localVarPath = `/v1/statistics/GetLineChartRootData`;
// verify required parameter 'projectId' is not null or undefined
assertParamExists("getLineChartRootData", "projectId", projectId);
const localVarPath =
`/v1/projects/{projectId}/statistics/GetLineChartRootData`.replace(
`{${"projectId"}}`,
encodeURIComponent(String(projectId))
);
// use dummy base URL string because the URL constructor only accepts absolute URLs.
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
let baseOptions;
Expand All @@ -78,10 +84,6 @@ export const StatisticsApiAxiosParamCreator = function (
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;

if (projectId !== undefined) {
localVarQueryParameter["projectId"] = projectId;
}

setSearchParams(localVarUrlObj, localVarQueryParameter, options.query);
let headersFromBaseOptions =
baseOptions && baseOptions.headers ? baseOptions.headers : {};
Expand All @@ -98,17 +100,23 @@ export const StatisticsApiAxiosParamCreator = function (
},
/**
*
* @param {string} [projectId]
* @param {string} projectId
* @param {string} [lang]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
getSemanticDomainCounts: async (
projectId?: string,
projectId: string,
lang?: string,
options: any = {}
): Promise<RequestArgs> => {
const localVarPath = `/v1/statistics/GetSemanticDomainCounts`;
// verify required parameter 'projectId' is not null or undefined
assertParamExists("getSemanticDomainCounts", "projectId", projectId);
const localVarPath =
`/v1/projects/{projectId}/statistics/GetSemanticDomainCounts`.replace(
`{${"projectId"}}`,
encodeURIComponent(String(projectId))
);
// use dummy base URL string because the URL constructor only accepts absolute URLs.
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
let baseOptions;
Expand All @@ -124,10 +132,6 @@ export const StatisticsApiAxiosParamCreator = function (
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;

if (projectId !== undefined) {
localVarQueryParameter["projectId"] = projectId;
}

if (lang !== undefined) {
localVarQueryParameter["lang"] = lang;
}
Expand All @@ -148,17 +152,23 @@ export const StatisticsApiAxiosParamCreator = function (
},
/**
*
* @param {string} [projectId]
* @param {string} projectId
* @param {string} [lang]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
getSemanticDomainUserCounts: async (
projectId?: string,
projectId: string,
lang?: string,
options: any = {}
): Promise<RequestArgs> => {
const localVarPath = `/v1/statistics/GetSemanticDomainUserCounts`;
// verify required parameter 'projectId' is not null or undefined
assertParamExists("getSemanticDomainUserCounts", "projectId", projectId);
const localVarPath =
`/v1/projects/{projectId}/statistics/GetSemanticDomainUserCounts`.replace(
`{${"projectId"}}`,
encodeURIComponent(String(projectId))
);
// use dummy base URL string because the URL constructor only accepts absolute URLs.
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
let baseOptions;
Expand All @@ -174,10 +184,6 @@ export const StatisticsApiAxiosParamCreator = function (
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;

if (projectId !== undefined) {
localVarQueryParameter["projectId"] = projectId;
}

if (lang !== undefined) {
localVarQueryParameter["lang"] = lang;
}
Expand All @@ -198,15 +204,21 @@ export const StatisticsApiAxiosParamCreator = function (
},
/**
*
* @param {string} [projectId]
* @param {string} projectId
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
getWordsPerDayPerUserCounts: async (
projectId?: string,
projectId: string,
options: any = {}
): Promise<RequestArgs> => {
const localVarPath = `/v1/statistics/GetWordsPerDayPerUserCounts`;
// verify required parameter 'projectId' is not null or undefined
assertParamExists("getWordsPerDayPerUserCounts", "projectId", projectId);
const localVarPath =
`/v1/projects/{projectId}/statistics/GetWordsPerDayPerUserCounts`.replace(
`{${"projectId"}}`,
encodeURIComponent(String(projectId))
);
// use dummy base URL string because the URL constructor only accepts absolute URLs.
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
let baseOptions;
Expand All @@ -222,10 +234,6 @@ export const StatisticsApiAxiosParamCreator = function (
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;

if (projectId !== undefined) {
localVarQueryParameter["projectId"] = projectId;
}

setSearchParams(localVarUrlObj, localVarQueryParameter, options.query);
let headersFromBaseOptions =
baseOptions && baseOptions.headers ? baseOptions.headers : {};
Expand Down Expand Up @@ -253,12 +261,12 @@ export const StatisticsApiFp = function (configuration?: Configuration) {
return {
/**
*
* @param {string} [projectId]
* @param {string} projectId
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async getLineChartRootData(
projectId?: string,
projectId: string,
options?: any
): Promise<
(axios?: AxiosInstance, basePath?: string) => AxiosPromise<ChartRootData>
Expand All @@ -277,13 +285,13 @@ export const StatisticsApiFp = function (configuration?: Configuration) {
},
/**
*
* @param {string} [projectId]
* @param {string} projectId
* @param {string} [lang]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async getSemanticDomainCounts(
projectId?: string,
projectId: string,
lang?: string,
options?: any
): Promise<
Expand All @@ -307,13 +315,13 @@ export const StatisticsApiFp = function (configuration?: Configuration) {
},
/**
*
* @param {string} [projectId]
* @param {string} projectId
* @param {string} [lang]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async getSemanticDomainUserCounts(
projectId?: string,
projectId: string,
lang?: string,
options?: any
): Promise<
Expand All @@ -337,12 +345,12 @@ export const StatisticsApiFp = function (configuration?: Configuration) {
},
/**
*
* @param {string} [projectId]
* @param {string} projectId
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async getWordsPerDayPerUserCounts(
projectId?: string,
projectId: string,
options?: any
): Promise<
(
Expand Down Expand Up @@ -378,12 +386,12 @@ export const StatisticsApiFactory = function (
return {
/**
*
* @param {string} [projectId]
* @param {string} projectId
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
getLineChartRootData(
projectId?: string,
projectId: string,
options?: any
): AxiosPromise<ChartRootData> {
return localVarFp
Expand All @@ -392,13 +400,13 @@ export const StatisticsApiFactory = function (
},
/**
*
* @param {string} [projectId]
* @param {string} projectId
* @param {string} [lang]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
getSemanticDomainCounts(
projectId?: string,
projectId: string,
lang?: string,
options?: any
): AxiosPromise<Array<SemanticDomainCount>> {
Expand All @@ -408,13 +416,13 @@ export const StatisticsApiFactory = function (
},
/**
*
* @param {string} [projectId]
* @param {string} projectId
* @param {string} [lang]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
getSemanticDomainUserCounts(
projectId?: string,
projectId: string,
lang?: string,
options?: any
): AxiosPromise<Array<SemanticDomainUserCount>> {
Expand All @@ -424,12 +432,12 @@ export const StatisticsApiFactory = function (
},
/**
*
* @param {string} [projectId]
* @param {string} projectId
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
getWordsPerDayPerUserCounts(
projectId?: string,
projectId: string,
options?: any
): AxiosPromise<Array<WordsPerDayPerUserCount>> {
return localVarFp
Expand All @@ -450,7 +458,7 @@ export interface StatisticsApiGetLineChartRootDataRequest {
* @type {string}
* @memberof StatisticsApiGetLineChartRootData
*/
readonly projectId?: string;
readonly projectId: string;
}

/**
Expand All @@ -464,7 +472,7 @@ export interface StatisticsApiGetSemanticDomainCountsRequest {
* @type {string}
* @memberof StatisticsApiGetSemanticDomainCounts
*/
readonly projectId?: string;
readonly projectId: string;

/**
*
Expand All @@ -485,7 +493,7 @@ export interface StatisticsApiGetSemanticDomainUserCountsRequest {
* @type {string}
* @memberof StatisticsApiGetSemanticDomainUserCounts
*/
readonly projectId?: string;
readonly projectId: string;

/**
*
Expand All @@ -506,7 +514,7 @@ export interface StatisticsApiGetWordsPerDayPerUserCountsRequest {
* @type {string}
* @memberof StatisticsApiGetWordsPerDayPerUserCounts
*/
readonly projectId?: string;
readonly projectId: string;
}

/**
Expand All @@ -524,7 +532,7 @@ export class StatisticsApi extends BaseAPI {
* @memberof StatisticsApi
*/
public getLineChartRootData(
requestParameters: StatisticsApiGetLineChartRootDataRequest = {},
requestParameters: StatisticsApiGetLineChartRootDataRequest,
options?: any
) {
return StatisticsApiFp(this.configuration)
Expand All @@ -540,7 +548,7 @@ export class StatisticsApi extends BaseAPI {
* @memberof StatisticsApi
*/
public getSemanticDomainCounts(
requestParameters: StatisticsApiGetSemanticDomainCountsRequest = {},
requestParameters: StatisticsApiGetSemanticDomainCountsRequest,
options?: any
) {
return StatisticsApiFp(this.configuration)
Expand All @@ -560,7 +568,7 @@ export class StatisticsApi extends BaseAPI {
* @memberof StatisticsApi
*/
public getSemanticDomainUserCounts(
requestParameters: StatisticsApiGetSemanticDomainUserCountsRequest = {},
requestParameters: StatisticsApiGetSemanticDomainUserCountsRequest,
options?: any
) {
return StatisticsApiFp(this.configuration)
Expand All @@ -580,7 +588,7 @@ export class StatisticsApi extends BaseAPI {
* @memberof StatisticsApi
*/
public getWordsPerDayPerUserCounts(
requestParameters: StatisticsApiGetWordsPerDayPerUserCountsRequest = {},
requestParameters: StatisticsApiGetWordsPerDayPerUserCountsRequest,
options?: any
) {
return StatisticsApiFp(this.configuration)
Expand Down
Loading

0 comments on commit 2244168

Please sign in to comment.