aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/store
diff options
context:
space:
mode:
authorGrégoire Aubert <gregoire.aubert@sonarsource.com>2018-06-29 16:33:30 +0200
committerSonarTech <sonartech@sonarsource.com>2018-07-11 20:21:21 +0200
commit477cfbd296c49853604563e24fc2c9987b4f751e (patch)
tree02346fa12e2f500fd0bf8b0e712e99a242d61609 /server/sonar-web/src/main/js/store
parent65950a3720eab9c67e2d99ca6e7973de13a54bcb (diff)
downloadsonarqube-477cfbd296c49853604563e24fc2c9987b4f751e.tar.gz
sonarqube-477cfbd296c49853604563e24fc2c9987b4f751e.zip
SONAR-10945 QP and QG pages should only be visible only to members of paid organizations
* SONAR-10968 Warn user about project privacy after billing upgrade * SONAR-10949 Show QG, QP, members and rules only when the user has correct access * SONAR-10959 Do not display Rules, QP and QG pages for non members of paid organizations * SONAR-10961 Do not display Members page for non member of private organizations * Remove rule permalink in issues page for non members of paid orgs * Do not display QP, QG on project overview page
Diffstat (limited to 'server/sonar-web/src/main/js/store')
-rw-r--r--server/sonar-web/src/main/js/store/organizations/duck.ts (renamed from server/sonar-web/src/main/js/store/organizations/duck.js)178
1 files changed, 58 insertions, 120 deletions
diff --git a/server/sonar-web/src/main/js/store/organizations/duck.js b/server/sonar-web/src/main/js/store/organizations/duck.ts
index 1571e3a40f9..8b6c76e3993 100644
--- a/server/sonar-web/src/main/js/store/organizations/duck.js
+++ b/server/sonar-web/src/main/js/store/organizations/duck.ts
@@ -17,118 +17,67 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-// @flow
import { combineReducers } from 'redux';
import { omit, uniq, without } from 'lodash';
+import { Group, Organization } from '../../app/types';
-/*::
-export type Organization = {
- adminPages?: Array<{ key: string, name: string }>,
- avatar?: string,
- canAdmin?: boolean,
- canDelete?: boolean,
- canProvisionProjects?: boolean,
- canUpdateProjectsVisibilityToPrivate?: boolean,
- description?: string,
- isAdmin: bool,
- key: string,
- name: string,
- pages?: Array<{ key: string, name: string }>,
- projectVisibility: string,
- url?: string
-};
-*/
-
-/*::
-export type OrgGroup = {
- id: string,
- default: boolean,
- description: string,
- membersCount: number,
- name: string
-};
-*/
-
-/*::
-type ReceiveOrganizationsAction = {
- type: 'RECEIVE_ORGANIZATIONS',
- organizations: Array<Organization>
-};
-*/
+interface ReceiveOrganizationsAction {
+ type: 'RECEIVE_ORGANIZATIONS';
+ organizations: Organization[];
+}
-/*::
-type ReceiveMyOrganizationsAction = {
- type: 'RECEIVE_MY_ORGANIZATIONS',
- organizations: Array<Organization>
-};
-*/
+interface ReceiveMyOrganizationsAction {
+ type: 'RECEIVE_MY_ORGANIZATIONS';
+ organizations: Organization[];
+}
-/*::
-type ReceiveOrganizationGroups = {
- type: 'RECEIVE_ORGANIZATION_GROUPS',
- key: string,
- groups: Array<OrgGroup>
-};
-*/
+interface ReceiveOrganizationGroups {
+ type: 'RECEIVE_ORGANIZATION_GROUPS';
+ key: string;
+ groups: Group[];
+}
-/*::
-type CreateOrganizationAction = {
- type: 'CREATE_ORGANIZATION',
- organization: Organization
-};
-*/
+interface CreateOrganizationAction {
+ type: 'CREATE_ORGANIZATION';
+ organization: Organization;
+}
-/*::
-type UpdateOrganizationAction = {
- type: 'UPDATE_ORGANIZATION',
- key: string,
- changes: {}
-};
-*/
+interface UpdateOrganizationAction {
+ type: 'UPDATE_ORGANIZATION';
+ key: string;
+ changes: {};
+}
-/*::
-type DeleteOrganizationAction = {
- type: 'DELETE_ORGANIZATION',
- key: string
-};
-*/
+interface DeleteOrganizationAction {
+ type: 'DELETE_ORGANIZATION';
+ key: string;
+}
-/*::
type Action =
| ReceiveOrganizationsAction
| ReceiveMyOrganizationsAction
| ReceiveOrganizationGroups
| CreateOrganizationAction
| UpdateOrganizationAction
- | DeleteOrganizationAction; */
+ | DeleteOrganizationAction;
-/*::
-type ByKeyState = {
- [key: string]: Organization
-};
-*/
+interface ByKeyState {
+ [key: string]: Organization;
+}
-/*::
-type GroupsState = {
- [key: string]: Array<OrgGroup>
-};
-*/
+interface GroupsState {
+ [key: string]: Group[];
+}
-/*::
-type MyState = Array<string>;
-*/
+type MyState = string[];
-/*::
-type State = {
- byKey: ByKeyState,
- my: MyState,
- groups: GroupsState
-};
-*/
+interface State {
+ byKey: ByKeyState;
+ my: MyState;
+ groups: GroupsState;
+}
-export function receiveOrganizations(
- organizations /*: Array<Organization> */
-) /*: ReceiveOrganizationsAction */ {
+export function receiveOrganizations(organizations: Organization[]): ReceiveOrganizationsAction {
return {
type: 'RECEIVE_ORGANIZATIONS',
organizations
@@ -136,18 +85,15 @@ export function receiveOrganizations(
}
export function receiveMyOrganizations(
- organizations /*: Array<Organization> */
-) /*: ReceiveMyOrganizationsAction */ {
+ organizations: Organization[]
+): ReceiveMyOrganizationsAction {
return {
type: 'RECEIVE_MY_ORGANIZATIONS',
organizations
};
}
-export function receiveOrganizationGroups(
- key /*: string */,
- groups /*: Array<OrgGroup> */
-) /*: receiveOrganizationGroups */ {
+export function receiveOrganizationGroups(key: string, groups: Group[]): ReceiveOrganizationGroups {
return {
type: 'RECEIVE_ORGANIZATION_GROUPS',
key,
@@ -155,19 +101,14 @@ export function receiveOrganizationGroups(
};
}
-export function createOrganization(
- organization /*: Organization */
-) /*: CreateOrganizationAction */ {
+export function createOrganization(organization: Organization): CreateOrganizationAction {
return {
type: 'CREATE_ORGANIZATION',
organization
};
}
-export function updateOrganization(
- key /*: string */,
- changes /*: {} */
-) /*: UpdateOrganizationAction */ {
+export function updateOrganization(key: string, changes: {}): UpdateOrganizationAction {
return {
type: 'UPDATE_ORGANIZATION',
key,
@@ -175,7 +116,7 @@ export function updateOrganization(
};
}
-export function deleteOrganization(key /*: string */) /*: DeleteOrganizationAction */ {
+export function deleteOrganization(key: string): DeleteOrganizationAction {
return {
type: 'DELETE_ORGANIZATION',
key
@@ -183,9 +124,9 @@ export function deleteOrganization(key /*: string */) /*: DeleteOrganizationActi
}
function onReceiveOrganizations(
- state /*: ByKeyState */,
- action /*: ReceiveOrganizationsAction | ReceiveMyOrganizationsAction */
-) /*: ByKeyState */ {
+ state: ByKeyState,
+ action: ReceiveOrganizationsAction | ReceiveMyOrganizationsAction
+): ByKeyState {
const nextState = { ...state };
action.organizations.forEach(organization => {
nextState[organization.key] = { ...state[organization.key], ...organization };
@@ -193,7 +134,7 @@ function onReceiveOrganizations(
return nextState;
}
-function byKey(state /*: ByKeyState */ = {}, action /*: Action */) {
+function byKey(state: ByKeyState = {}, action: Action) {
switch (action.type) {
case 'RECEIVE_ORGANIZATIONS':
case 'RECEIVE_MY_ORGANIZATIONS':
@@ -216,7 +157,7 @@ function byKey(state /*: ByKeyState */ = {}, action /*: Action */) {
}
}
-function my(state /*: MyState */ = [], action /*: Action */) {
+function my(state: MyState = [], action: Action) {
switch (action.type) {
case 'RECEIVE_MY_ORGANIZATIONS':
return uniq([...state, ...action.organizations.map(o => o.key)]);
@@ -229,7 +170,7 @@ function my(state /*: MyState */ = [], action /*: Action */) {
}
}
-function groups(state /*: GroupsState */ = {}, action /*: Action */) {
+function groups(state: GroupsState = {}, action: Action) {
if (action.type === 'RECEIVE_ORGANIZATION_GROUPS') {
return { ...state, [action.key]: action.groups };
}
@@ -238,21 +179,18 @@ function groups(state /*: GroupsState */ = {}, action /*: Action */) {
export default combineReducers({ byKey, my, groups });
-export function getOrganizationByKey(state /*: State */, key /*: string */) /*: Organization */ {
+export function getOrganizationByKey(state: State, key: string): Organization | undefined {
return state.byKey[key];
}
-export function getOrganizationGroupsByKey(
- state /*: State */,
- key /*: string */
-) /*: Array<OrgGroup> */ {
+export function getOrganizationGroupsByKey(state: State, key: string): Group[] {
return state.groups[key] || [];
}
-export function getMyOrganizations(state /*: State */) /*: Array<Organization> */ {
- return state.my.map(key => getOrganizationByKey(state, key));
+export function getMyOrganizations(state: State): Organization[] {
+ return state.my.map(key => getOrganizationByKey(state, key) as Organization);
}
-export function areThereCustomOrganizations(state /*: State */) /*: boolean */ {
+export function areThereCustomOrganizations(state: State): boolean {
return Object.keys(state.byKey).length > 1;
}