Skip to content
This repository has been archived by the owner on Oct 20, 2021. It is now read-only.

Commit

Permalink
fix: Read only right is not well handled on documentation page
Browse files Browse the repository at this point in the history
  • Loading branch information
aelamrani authored and NicolasGeraud committed Oct 28, 2019
1 parent 3268405 commit 7f1c31f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ class ComponentCtrl implements ng.IComponentController {
var lastElement = Constants.portal.uploadMedia.maxSizeInOctet;
}

$onInit() {}

$onChanges() {
const initialValue = this.page && this.page.content ? this.page.content : "";
let mediaURL;
Expand Down
6 changes: 3 additions & 3 deletions src/management/api/portal/apis.portal.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ function apisPortalRouterConfig($stateProvider) {
resolvedFetchers: (FetcherService: FetcherService) => {
return FetcherService.list().then(response => {
return response.data;
})
});
}
},
data: {
Expand All @@ -416,7 +416,7 @@ function apisPortalRouterConfig($stateProvider) {
page: 'management-api-documentation'
},
perms: {
only: ['api-documentation-u']
only: ['api-documentation-r']
}
},
params: {
Expand All @@ -426,5 +426,5 @@ function apisPortalRouterConfig($stateProvider) {
squash: false
}
}
})
});
}
10 changes: 8 additions & 2 deletions src/management/components/documentation/edit-page.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import DocumentationService from "../../../services/documentation.service";
import {StateService} from "@uirouter/core";
import {IScope} from "angular";
import _ = require('lodash');
import UserService from "../../../services/user.service";

interface IPageScope extends IScope {
getContentMode: string;
Expand All @@ -37,6 +38,7 @@ const EditPageComponent: ng.IComponentOptions = {
controller: function (
NotificationService: NotificationService,
DocumentationService: DocumentationService,
UserService: UserService,
$state: StateService,
$scope: IPageScope
) {
Expand Down Expand Up @@ -81,7 +83,11 @@ const EditPageComponent: ng.IComponentOptions = {
} else {
this.page.authorizedGroups = _.map(this.groups, 'id');
}

if (this.apiId) {
this.canUpdate = UserService.isUserHasPermissions(["api-documentation-u"]);
} else {
this.canUpdate = UserService.isUserHasPermissions(["portal-documentation-u"]);
}
};

this.initEditor = () => {
Expand Down Expand Up @@ -174,7 +180,7 @@ const EditPageComponent: ng.IComponentOptions = {
};

this.goToExternalSource = () => {
this.selectedTab = 2
this.selectedTab = 2;
};

this.selectTab = (idx: number) => {
Expand Down
37 changes: 19 additions & 18 deletions src/management/components/documentation/edit-page.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<h1>{{$ctrl.page.name}}</h1>
<a ng-click="$ctrl.cancel()">Back to Documentation</a>
</div>
<div>
<div ng-if="$ctrl.canUpdate">
<md-button class="md-raised md-primary" type="button" ng-if="$ctrl.page.source" ng-click="$ctrl.fetch()">
Fetch
</md-button>
Expand Down Expand Up @@ -62,7 +62,7 @@ <h1>{{$ctrl.page.name}}</h1>
<h2></h2>
<div class="gv-form-content" layout="column">

<div ng-if="editorReadonly" class="gv-page-draft-banner">
<div ng-if="editorReadonly && $ctrl.canUpdate" class="gv-page-draft-banner">
<ng-md-icon icon="warning" class="gv-warning"></ng-md-icon>
Page's content is retrieved from an external source. If you want to edit content manually, <a ng-click="$ctrl.goToExternalSource()">please change the configuration</a>.
</div>
Expand All @@ -75,36 +75,37 @@ <h2></h2>
<!-- edit SWAGGER inline -->
<div ng-if="'SWAGGER' === $ctrl.page.type" style="display: inline-block; width: 100%;">
<div layout="row" style="max-height: 900px; overflow: auto;">
<md-input-container class="md-block" flex="50">
<textarea
ui-codemirror
ui-codemirror-opts="$ctrl.codeMirrorOptions"
ng-model="$ctrl.page.content"
aria-label="page content"
rows="5" style="overflow-y: scroll;"
ng-disabled="$ctrl.page.source"
md-autofocus></textarea>
<md-input-container class="md-block" flex="50" ng-if="$ctrl.canUpdate">
<textarea
ui-codemirror
ui-codemirror-opts="$ctrl.codeMirrorOptions"
ng-model="$ctrl.page.content"
aria-label="page content"
rows="5" style="overflow-y: scroll;"
ng-disabled="$ctrl.page.source"
md-autofocus></textarea>
</md-input-container>
<gv-page flex="50" page="$ctrl.page" enable-try-it="false" edit="true"></gv-page>
<gv-page flex page="$ctrl.page" edit="$ctrl.canUpdate"></gv-page>
</div>
</div>

<!-- edit MARKDOWN inline -->
<div ng-if="'MARKDOWN' === $ctrl.page.type" style="display: inline-block; width: 100%;">
<md-input-container class="md-block">
<gv-page-editor-markdown page="$ctrl.page"></gv-page-editor-markdown>
<gv-page-editor-markdown ng-if="$ctrl.canUpdate" page="$ctrl.page"></gv-page-editor-markdown>
<gv-page-markdown ng-if="!$ctrl.canUpdate" page="$ctrl.page"></gv-page-markdown>
</md-input-container>
</div>

<!-- import file -->
<div style="display: inline-block;">
<div style="display: inline-block;" ng-if="$ctrl.canUpdate">
<h4>Select a file to import:</h4>
<input type="file" filecontent="pageContentFile.content" filename="pageContentFile.name" >
</div>
</md-tab-body>
</md-tab>

<md-tab md-on-select="currentTab=$ctrl.selectTab(1)">
<md-tab md-on-select="currentTab=$ctrl.selectTab(1)" ng-if="$ctrl.canUpdate">
<md-tab-label>Configuration</md-tab-label>
<md-tab-body>
<h3>General</h3>
Expand Down Expand Up @@ -170,7 +171,7 @@ <h3>Swagger</h3>
</md-tab-body>
</md-tab>

<md-tab md-on-select="currentTab=$ctrl.selectTab(2)">
<md-tab md-on-select="currentTab=$ctrl.selectTab(2)" ng-if="$ctrl.canUpdate">
<md-tab-label>External Source</md-tab-label>
<md-tab-body>
<div style="display: inline-block;">
Expand All @@ -190,7 +191,7 @@ <h3></h3>
</md-tab-body>
</md-tab>

<md-tab md-on-select="currentTab=$ctrl.selectTab(3)">
<md-tab md-on-select="currentTab=$ctrl.selectTab(3)" ng-if="$ctrl.canUpdate">
<md-tab-label>Access Control</md-tab-label>
<md-tab-body>
<h3>Groups Authorizations</h3>
Expand All @@ -206,7 +207,7 @@ <h3>Groups Authorizations</h3>
</md-tab>
</md-tabs>

<div class="md-actions gravitee-api-save-button" layout="row" style="padding-top: 32px;">
<div class="md-actions gravitee-api-save-button" layout="row" style="padding-top: 32px;" ng-if="$ctrl.canUpdate">
<md-button class="md-raised md-primary" type="submit" ng-click="$ctrl.save()" ng-disabled="!$ctrl.page.name">
Save
</md-button>
Expand Down

0 comments on commit 7f1c31f

Please sign in to comment.