PolyGerrit: Implement /admin/create-group
Change-Id: I8817218a1e46c74147f07c90a2602241d3d9e2b8
This commit is contained in:
@@ -14,23 +14,28 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<link rel="import" href="../../../bower_components/polymer/polymer.html">
|
||||
|
||||
<link rel="import" href="../../../behaviors/gr-list-view-behavior/gr-list-view-behavior.html">
|
||||
<link rel="import" href="../../../bower_components/iron-input/iron-input.html">
|
||||
<link rel="import" href="../../../bower_components/polymer/polymer.html">
|
||||
<link rel="import" href="../../shared/gr-list-view/gr-list-view.html">
|
||||
<link rel="import" href="../../shared/gr-rest-api-interface/gr-rest-api-interface.html">
|
||||
|
||||
<link rel="import" href="../../../styles/shared-styles.html">
|
||||
<link rel="import" href="../../shared/gr-confirm-dialog/gr-confirm-dialog.html">
|
||||
<link rel="import" href="../../shared/gr-list-view/gr-list-view.html">
|
||||
<link rel="import" href="../../shared/gr-overlay/gr-overlay.html">
|
||||
<link rel="import" href="../../shared/gr-rest-api-interface/gr-rest-api-interface.html">
|
||||
<link rel="import" href="../gr-create-group-dialog/gr-create-group-dialog.html">
|
||||
|
||||
<dom-module id="gr-admin-group-list">
|
||||
<template>
|
||||
<style include="shared-styles"></style>
|
||||
<gr-list-view
|
||||
create-new="[[_createNewCapability]]"
|
||||
filter="[[_filter]]"
|
||||
items="[[_groups]]"
|
||||
items-per-page="[[_groupsPerPage]]"
|
||||
loading="[[_loading]]"
|
||||
offset="[[_offset]]"
|
||||
on-create-clicked="_handleCreateClicked"
|
||||
path="[[_path]]">
|
||||
<table id="list">
|
||||
<tr class="headerRow">
|
||||
@@ -53,6 +58,25 @@ limitations under the License.
|
||||
</template>
|
||||
</table>
|
||||
</gr-list-view>
|
||||
<gr-overlay id="createOverlay" with-backdrop>
|
||||
<gr-confirm-dialog
|
||||
id="createDialog"
|
||||
class="confirmDialog"
|
||||
disabled="[[!_hasNewGroupName]]"
|
||||
confirm-label="Create"
|
||||
on-confirm="_handleCreateGroup"
|
||||
on-cancel="_handleCloseCreate">
|
||||
<div class="header">
|
||||
Create Group
|
||||
</div>
|
||||
<div class="main">
|
||||
<gr-create-group-dialog
|
||||
has-new-group-name="{{_hasNewGroupName}}"
|
||||
params="[[params]]"
|
||||
id="createNewModal"></gr-create-group-dialog>
|
||||
</div>
|
||||
</gr-confirm-dialog>
|
||||
</gr-overlay>
|
||||
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
|
||||
</template>
|
||||
<script src="gr-admin-group-list.js"></script>
|
||||
|
||||
@@ -35,6 +35,11 @@
|
||||
readOnly: true,
|
||||
value: '/admin/groups',
|
||||
},
|
||||
_hasNewGroupName: Boolean,
|
||||
_createNewCapability: {
|
||||
type: Boolean,
|
||||
value: false,
|
||||
},
|
||||
_groups: Array,
|
||||
|
||||
/**
|
||||
@@ -62,9 +67,8 @@
|
||||
Gerrit.ListViewBehavior,
|
||||
],
|
||||
|
||||
listeners: {
|
||||
'next-page': '_handleNextPage',
|
||||
'previous-page': '_handlePreviousPage',
|
||||
attached() {
|
||||
this._getCreateGroupCapability();
|
||||
},
|
||||
|
||||
_paramsChanged(params) {
|
||||
@@ -80,6 +84,18 @@
|
||||
return this.getUrl(this._path + '/', id);
|
||||
},
|
||||
|
||||
_getCreateGroupCapability() {
|
||||
return this.$.restAPI.getAccount().then(account => {
|
||||
if (!account) { return; }
|
||||
return this.$.restAPI.getAccountCapabilities(['createGroup'])
|
||||
.then(capabilities => {
|
||||
if (capabilities.createGroup) {
|
||||
this._createNewCapability = true;
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
_getGroups(filter, groupsPerPage, offset) {
|
||||
this._groups = [];
|
||||
return this.$.restAPI.getGroups(filter, groupsPerPage, offset)
|
||||
@@ -97,6 +113,18 @@
|
||||
});
|
||||
},
|
||||
|
||||
_handleCreateGroup() {
|
||||
this.$.createNewModal.handleCreateGroup();
|
||||
},
|
||||
|
||||
_handleCloseCreate() {
|
||||
this.$.createOverlay.close();
|
||||
},
|
||||
|
||||
_handleCreateClicked() {
|
||||
this.$.createOverlay.open();
|
||||
},
|
||||
|
||||
_visibleToAll(item) {
|
||||
return item.options.visible_to_all === true ? 'Y' : 'N';
|
||||
},
|
||||
|
||||
@@ -141,5 +141,31 @@ limitations under the License.
|
||||
assert.equal(getComputedStyle(element.$.loading).display, 'none');
|
||||
});
|
||||
});
|
||||
|
||||
suite('create new', () => {
|
||||
test('_handleCreateClicked called when create-click fired', () => {
|
||||
sandbox.stub(element, '_handleCreateClicked');
|
||||
element.$$('gr-list-view').fire('create-clicked');
|
||||
assert.isTrue(element._handleCreateClicked.called);
|
||||
});
|
||||
|
||||
test('_handleCreateClicked opens modal', () => {
|
||||
const openStub = sandbox.stub(element.$.createOverlay, 'open');
|
||||
element._handleCreateClicked();
|
||||
assert.isTrue(openStub.called);
|
||||
});
|
||||
|
||||
test('_handleCreateGroup called when confirm fired', () => {
|
||||
sandbox.stub(element, '_handleCreateGroup');
|
||||
element.$.createDialog.fire('confirm');
|
||||
assert.isTrue(element._handleCreateGroup.called);
|
||||
});
|
||||
|
||||
test('_handleCloseCreate called when cancel fired', () => {
|
||||
sandbox.stub(element, '_handleCloseCreate');
|
||||
element.$.createDialog.fire('cancel');
|
||||
assert.isTrue(element._handleCloseCreate.called);
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -23,6 +23,7 @@ limitations under the License.
|
||||
<link rel="import" href="../../shared/gr-page-nav/gr-page-nav.html">
|
||||
<link rel="import" href="../../shared/gr-placeholder/gr-placeholder.html">
|
||||
<link rel="import" href="../../shared/gr-rest-api-interface/gr-rest-api-interface.html">
|
||||
<link rel="import" href="../gr-create-group-dialog/gr-create-group-dialog.html">
|
||||
<link rel="import" href="../gr-create-project-dialog/gr-create-project-dialog.html">
|
||||
<link rel="import" href="../gr-admin-group-list/gr-admin-group-list.html">
|
||||
<link rel="import" href="../gr-admin-plugin-list/gr-admin-plugin-list.html">
|
||||
|
||||
@@ -25,12 +25,7 @@
|
||||
section: 'Groups',
|
||||
url: '/admin/groups',
|
||||
view: 'gr-admin-group-list',
|
||||
children: [{
|
||||
name: 'Create Group',
|
||||
capability: 'createGroup',
|
||||
url: '/admin/create-group',
|
||||
view: 'gr-admin-create-group',
|
||||
}],
|
||||
children: [],
|
||||
}, {
|
||||
name: 'Plugins',
|
||||
capability: 'viewPlugins',
|
||||
@@ -55,10 +50,10 @@
|
||||
type: Boolean,
|
||||
value: false,
|
||||
},
|
||||
_showGroupList: Boolean,
|
||||
_showProjectMain: Boolean,
|
||||
_showProjectList: Boolean,
|
||||
_showProjectDetailList: Boolean,
|
||||
_showGroupList: Boolean,
|
||||
_showPluginList: Boolean,
|
||||
},
|
||||
|
||||
@@ -132,12 +127,12 @@
|
||||
},
|
||||
|
||||
_paramsChanged(params) {
|
||||
this.set('_showGroupList', params.adminView === 'gr-admin-group-list');
|
||||
this.set('_showProjectMain', params.adminView === 'gr-project');
|
||||
this.set('_showProjectList',
|
||||
params.adminView === 'gr-admin-project-list');
|
||||
this.set('_showProjectDetailList',
|
||||
params.adminView === 'gr-project-detail-list');
|
||||
this.set('_showGroupList', params.adminView === 'gr-admin-group-list');
|
||||
this.set('_showPluginList', params.adminView === 'gr-admin-plugin-list');
|
||||
if (params.project !== this._project) {
|
||||
this._project = params.project || '';
|
||||
@@ -173,4 +168,4 @@
|
||||
return itemView === params.adminView ? 'selected' : '';
|
||||
},
|
||||
});
|
||||
})();
|
||||
})();
|
||||
|
||||
@@ -101,7 +101,7 @@ limitations under the License.
|
||||
assert.isNotOk(element._filteredLinks[0].subsection);
|
||||
|
||||
// Groups
|
||||
assert.equal(element._filteredLinks[1].children.length, 1);
|
||||
assert.equal(element._filteredLinks[1].children.length, 0);
|
||||
|
||||
// Plugins
|
||||
assert.equal(element._filteredLinks[2].children.length, 0);
|
||||
@@ -154,7 +154,7 @@ limitations under the License.
|
||||
assert.equal(element._filteredLinks[0].subsection.name, 'Test Project');
|
||||
|
||||
// Groups
|
||||
assert.equal(element._filteredLinks[1].children.length, 1);
|
||||
assert.equal(element._filteredLinks[1].children.length, 0);
|
||||
|
||||
// Plugins
|
||||
assert.equal(element._filteredLinks[2].children.length, 0);
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
<!--
|
||||
Copyright (C) 2017 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<link rel="import" href="../../../bower_components/polymer/polymer.html">
|
||||
|
||||
<link rel="import" href="../../../behaviors/base-url-behavior/base-url-behavior.html">
|
||||
<link rel="import" href="../../../behaviors/gr-url-encoding-behavior.html">
|
||||
<link rel="import" href="../../../bower_components/iron-input/iron-input.html">
|
||||
<link rel="import" href="../../../styles/gr-form-styles.html">
|
||||
<link rel="import" href="../../../styles/shared-styles.html">
|
||||
<link rel="import" href="../../shared/gr-rest-api-interface/gr-rest-api-interface.html">
|
||||
|
||||
<dom-module id="gr-create-group-dialog">
|
||||
<template>
|
||||
<style include="shared-styles"></style>
|
||||
<style include="gr-form-styles">
|
||||
:host {
|
||||
display: inline-block;
|
||||
}
|
||||
input {
|
||||
width: 20em;
|
||||
}
|
||||
</style>
|
||||
<div class="gr-form-styles">
|
||||
<div id="form">
|
||||
<section>
|
||||
<span class="title">Group name</span>
|
||||
<input
|
||||
is="iron-input"
|
||||
id="groupNameInput"
|
||||
bind-value="{{_name}}">
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
|
||||
</template>
|
||||
<script src="gr-create-group-dialog.js"></script>
|
||||
</dom-module>
|
||||
@@ -0,0 +1,64 @@
|
||||
// Copyright (C) 2017 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
Polymer({
|
||||
is: 'gr-create-group-dialog',
|
||||
|
||||
properties: {
|
||||
params: Object,
|
||||
hasNewGroupName: {
|
||||
type: Boolean,
|
||||
notify: true,
|
||||
value: false,
|
||||
},
|
||||
_name: Object,
|
||||
_groupCreated: {
|
||||
type: Boolean,
|
||||
value: false,
|
||||
},
|
||||
},
|
||||
|
||||
observers: [
|
||||
'_updateGroupName(_name)',
|
||||
],
|
||||
|
||||
behaviors: [
|
||||
Gerrit.BaseUrlBehavior,
|
||||
Gerrit.URLEncodingBehavior,
|
||||
],
|
||||
|
||||
_computeGroupUrl(groupId) {
|
||||
return this.getBaseUrl() + '/admin/groups/' +
|
||||
this.encodeURL(groupId, true);
|
||||
},
|
||||
|
||||
_updateGroupName(name) {
|
||||
this.hasNewGroupName = !!name;
|
||||
},
|
||||
|
||||
handleCreateGroup() {
|
||||
return this.$.restAPI.createGroup({name: this._name})
|
||||
.then(groupRegistered => {
|
||||
if (groupRegistered.status !== 201) { return; }
|
||||
this._groupCreated = true;
|
||||
return this.$.restAPI.getGroupConfig(this._name)
|
||||
.then(group => {
|
||||
page.show(this._computeGroupUrl(group.group_id));
|
||||
});
|
||||
});
|
||||
},
|
||||
});
|
||||
})();
|
||||
@@ -0,0 +1,92 @@
|
||||
<!DOCTYPE html>
|
||||
<!--
|
||||
Copyright (C) 2017 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
|
||||
<title>gr-create-group-dialog</title>
|
||||
|
||||
<script src="../../../bower_components/page/page.js"></script>
|
||||
<script src="../../../bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>
|
||||
<script src="../../../bower_components/web-component-tester/browser.js"></script>
|
||||
<link rel="import" href="../../../test/common-test-setup.html"/>
|
||||
<link rel="import" href="gr-create-group-dialog.html">
|
||||
|
||||
<script>void(0);</script>
|
||||
|
||||
<test-fixture id="basic">
|
||||
<template>
|
||||
<gr-create-group-dialog></gr-create-group-dialog>
|
||||
</template>
|
||||
</test-fixture>
|
||||
|
||||
<script>
|
||||
suite('gr-create-group-dialog tests', () => {
|
||||
let element;
|
||||
let sandbox;
|
||||
const GROUP_NAME = 'test-group';
|
||||
|
||||
setup(() => {
|
||||
sandbox = sinon.sandbox.create();
|
||||
stub('gr-rest-api-interface', {
|
||||
getLoggedIn() { return Promise.resolve(true); },
|
||||
});
|
||||
element = fixture('basic');
|
||||
});
|
||||
|
||||
teardown(() => {
|
||||
sandbox.restore();
|
||||
});
|
||||
|
||||
test('name is updated correctly', () => {
|
||||
assert.isFalse(element.hasNewGroupName);
|
||||
|
||||
element.$.groupNameInput.bindValue = GROUP_NAME;
|
||||
|
||||
assert.isTrue(element.hasNewGroupName);
|
||||
assert.deepEqual(element._name, GROUP_NAME);
|
||||
});
|
||||
|
||||
test('test for redirecting to group on successful creation', done => {
|
||||
sandbox.stub(element.$.restAPI, 'createGroup')
|
||||
.returns(Promise.resolve({status: 201}));
|
||||
|
||||
sandbox.stub(element.$.restAPI, 'getGroupConfig')
|
||||
.returns(Promise.resolve({group_id: 551}));
|
||||
|
||||
const showStub = sandbox.stub(page, 'show');
|
||||
element.handleCreateGroup()
|
||||
.then(() => {
|
||||
assert.isTrue(showStub.calledWith('/admin/groups/551'));
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('test for unsuccessful group creation', done => {
|
||||
sandbox.stub(element.$.restAPI, 'createGroup')
|
||||
.returns(Promise.resolve({status: 409}));
|
||||
|
||||
sandbox.stub(element.$.restAPI, 'getGroupConfig')
|
||||
.returns(Promise.resolve({group_id: 551}));
|
||||
|
||||
const showStub = sandbox.stub(page, 'show');
|
||||
element.handleCreateGroup()
|
||||
.then(() => {
|
||||
assert.isFalse(showStub.called);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@@ -170,14 +170,24 @@
|
||||
},
|
||||
|
||||
createProject(config, opt_errFn, opt_ctx) {
|
||||
if (!config.name) {
|
||||
return '';
|
||||
}
|
||||
if (!config.name) { return ''; }
|
||||
const encodeName = encodeURIComponent(config.name);
|
||||
return this.send('PUT', `/projects/${encodeName}`, config, opt_errFn,
|
||||
opt_ctx);
|
||||
},
|
||||
|
||||
createGroup(config, opt_errFn, opt_ctx) {
|
||||
if (!config.name) { return ''; }
|
||||
const encodeName = encodeURIComponent(config.name);
|
||||
return this.send('PUT', `/groups/${encodeName}`, config, opt_errFn,
|
||||
opt_ctx);
|
||||
},
|
||||
|
||||
getGroupConfig(group) {
|
||||
const encodeName = encodeURIComponent(group);
|
||||
return this._fetchSharedCacheURL('/groups/' + encodeName + '/detail');
|
||||
},
|
||||
|
||||
getVersion() {
|
||||
return this._fetchSharedCacheURL('/config/server/version');
|
||||
},
|
||||
|
||||
@@ -34,8 +34,9 @@ limitations under the License.
|
||||
'admin/gr-admin-plugin-list/gr-admin-plugin-list_test.html',
|
||||
'admin/gr-admin-project-list/gr-admin-project-list_test.html',
|
||||
'admin/gr-admin-view/gr-admin-view_test.html',
|
||||
'admin/gr-project/gr-project_test.html',
|
||||
'admin/gr-create-group-dialog/gr-create-group-dialog_test.html',
|
||||
'admin/gr-create-project-dialog/gr-create-project-dialog_test.html',
|
||||
'admin/gr-project/gr-project_test.html',
|
||||
'admin/gr-project-detail-list/gr-project-detail-list_test.html',
|
||||
'change-list/gr-change-list-item/gr-change-list-item_test.html',
|
||||
'change-list/gr-change-list-view/gr-change-list-view_test.html',
|
||||
|
||||
Reference in New Issue
Block a user