Skip to content

Commit c9aadbf

Browse files
begedinjoshsmith
authored andcommitted
Added admin UI for project approval
Fix ember-modal-dialog deprecation warning
1 parent a6cda16 commit c9aadbf

17 files changed

Lines changed: 367 additions & 1 deletion

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import Controller from '@ember/controller';
2+
import { get, set } from '@ember/object';
3+
import { inject as service } from '@ember/service';
4+
5+
export default Controller.extend({
6+
flashMessages: service(),
7+
8+
async approve(project) {
9+
set(project, 'approved', true);
10+
let title = get(project, 'title');
11+
project.save().then(() => {
12+
get(this, 'flashMessages').clearMessages().success(`You approved ${title}.`);
13+
}).catch(() => {
14+
project.rollbackAttributes();
15+
get(this, 'flashMessages').clearMessages().danger(`An error occurred while approving ${title}.`);
16+
});
17+
}
18+
});

app/router.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Router.map(function() {
3636
this.route('organization-invites', function() {
3737
this.route('new');
3838
});
39+
this.route('projects', function() {});
3940
});
4041

4142
// GitHub OAuth redirection route

app/routes/admin/projects/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import Route from '@ember/routing/route';
2+
3+
export default Route.extend({
4+
model() {
5+
return this.store.findAll('project');
6+
}
7+
});

app/templates/admin.hbs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
{{fa-icon "envelope-open-o"}} Organization Invites
1717
{{/link-to}}
1818
</li>
19+
<li>
20+
{{#link-to "admin.projects"}}
21+
{{fa-icon "clipboard"}} Projects
22+
{{/link-to}}
23+
</li>
1924
</ul>
2025
</div>
2126
<div class="admin-main">

app/templates/admin/projects.hbs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<div data-test-page-menu class="page-menu page-menu--horizontal">
2+
<div class="container">
3+
<ul>
4+
<li>
5+
{{link-to "Projects" "admin.projects.index" data-test-index-link}}
6+
</li>
7+
</ul>
8+
</div>
9+
</div>
10+
11+
{{outlet}}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<div class="log-rows">
2+
<div data-test-log-row-header class="log-row log-row--header">
3+
<span class="log-cell log-cell--shrink"></span>
4+
<span class="log-cell log-cell--shrink">Project</span>
5+
<span class="log-cell log-cell--shrink">Organization</span>
6+
<span class="log-cell">Status</span>
7+
<span class="log-cell log-cell--shrink">Approval</span>
8+
</div>
9+
10+
{{#each model as |project|}}
11+
<div data-test-log-row class="log-row">
12+
<span data-test-icon class="log-cell log-cell--shrink">
13+
{{#if project.iconThumbUrl}}
14+
{{#link-to 'project' project.organization.slug project.slug}}
15+
<img class="icon icon--small" width="35" height="35" src="{{project.iconThumbUrl}}" />
16+
{{/link-to}}
17+
{{else}}
18+
<div class="icon icon--small"></div>
19+
{{/if}}
20+
</span>
21+
<span data-test-title class="log-cell log-cell--shrink">
22+
{{#link-to 'project' project.organization.slug project.slug}}
23+
{{project.title}}
24+
{{/link-to}}
25+
</span>
26+
<span data-test-organization class="log-cell log-cell--shrink">
27+
{{#link-to 'slugged-route' project.organization.slug}}
28+
{{project.organization.name}}
29+
{{/link-to}}
30+
</span>
31+
<span data-test-approval-status class="log-cell">
32+
{{#if project.isSaving}}
33+
{{fa-icon "ellipsis-h"}} Saving...
34+
{{else if project.approved}}
35+
<span class="log-data--success">
36+
{{fa-icon "check-circle"}} Approved
37+
</span>
38+
{{else if project.approvalRequested}}
39+
{{fa-icon "question-circle"}} Pending approval
40+
{{else}}
41+
{{fa-icon "asterisk"}} Created
42+
{{/if}}
43+
</span>
44+
<span data-test-actions class="log-cell log-cell--shrink">
45+
{{#if (and project.approvalRequested (not project.approved))}}
46+
<button {{action approve project}} class="default small">Approve</button>
47+
{{/if}}
48+
</span>
49+
</div>
50+
{{/each}}
51+
</div>

app/templates/components/modal-confirm.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{{#if showDialog}}
22
<div class="modal-confirm">
3-
{{#modal-dialog clickOutsideToClose=true close="closeDialog" translucentOverlay=true}}
3+
{{#modal-dialog clickOutsideToClose=true onClose="closeDialog" translucentOverlay=true}}
44
<div class="dialog-text">
55
<p>{{dialogText}}</p>
66
</div>

tests/acceptance/admin-github-event-test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,32 @@ import moment from 'moment';
66

77
moduleForAcceptance('Acceptance | Admin | GitHub Event | Show');
88

9+
test('The page requires logging in', function(assert) {
10+
assert.expect(1);
11+
12+
let event = server.create('github-event');
13+
page.visit({ id: event.id });
14+
15+
andThen(() => {
16+
assert.equal(currentRouteName(), 'login', 'Got redirected to login');
17+
});
18+
});
19+
20+
test('The page requires user to be admin', function(assert) {
21+
assert.expect(2);
22+
23+
let user = server.create('user', { admin: false, id: 1 });
24+
authenticateSession(this.application, { user_id: user.id });
25+
26+
let event = server.create('github-event');
27+
page.visit({ id: event.id });
28+
29+
andThen(() => {
30+
assert.equal(page.flashErrors().count, 1, 'Flash error was rendered');
31+
assert.equal(currentRouteName(), 'projects-list', 'Got redirected');
32+
});
33+
});
34+
935
test('Displays all the logged events', function(assert) {
1036
assert.expect(12);
1137

tests/acceptance/admin-github-events-test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,30 @@ import page from '../pages/admin/github-events/index';
55

66
moduleForAcceptance('Acceptance | Admin | GitHub Events | Index');
77

8+
test('The page requires logging in', function(assert) {
9+
assert.expect(1);
10+
11+
page.visit();
12+
13+
andThen(() => {
14+
assert.equal(currentRouteName(), 'login', 'Got redirected to login');
15+
});
16+
});
17+
18+
test('The page requires user to be admin', function(assert) {
19+
assert.expect(2);
20+
21+
let user = server.create('user', { admin: false, id: 1 });
22+
authenticateSession(this.application, { user_id: user.id });
23+
24+
page.visit();
25+
26+
andThen(() => {
27+
assert.equal(page.flashErrors().count, 1, 'Flash error was rendered');
28+
assert.equal(currentRouteName(), 'projects-list', 'Got redirected');
29+
});
30+
});
31+
832
test('Displays all the logged events', function(assert) {
933
assert.expect(16);
1034

tests/acceptance/admin-organization-invite-new-test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,30 @@ import page from 'code-corps-ember/tests/pages/admin/organization-invites/new';
77

88
moduleForAcceptance('Acceptance | Admin | Organization Invites | New');
99

10+
test('The page requires logging in', function(assert) {
11+
assert.expect(1);
12+
13+
page.visit();
14+
15+
andThen(() => {
16+
assert.equal(currentRouteName(), 'login', 'Got redirected to login');
17+
});
18+
});
19+
20+
test('The page requires user to be admin', function(assert) {
21+
assert.expect(2);
22+
23+
let user = server.create('user', { admin: false, id: 1 });
24+
authenticateSession(this.application, { user_id: user.id });
25+
26+
page.visit();
27+
28+
andThen(() => {
29+
assert.equal(page.flashErrors().count, 1, 'Flash error was rendered');
30+
assert.equal(currentRouteName(), 'projects-list', 'Got redirected');
31+
});
32+
});
33+
1034
test('An admin can create and send an organization invite', function(assert) {
1135
assert.expect(3);
1236

0 commit comments

Comments
 (0)