Skip to content

Commit d0225e2

Browse files
authored
Empty page (no save button, no form controls) when adding new user/group (ciur/papermerge#513)
1 parent 9cee14b commit d0225e2

File tree

12 files changed

+57
-64
lines changed

12 files changed

+57
-64
lines changed

Diff for: .github/workflows/tests.yml

-27
This file was deleted.

Diff for: README.md

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
[![Tests](https://github.com/papermerge/papermerge.js/actions/workflows/tests.yml/badge.svg)](https://github.com/papermerge/papermerge.js/actions/workflows/tests.yml)
2-
3-
41
# PapermergeJS
52

63
PapermergeJS is frontend part i.e. web-based user interface of Papermerge

Diff for: app/components/group/add.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
{{#each this.permission_groups as |perm_group|}}
1111
<Group::PermissionGroup
1212
@perm_group={{perm_group}}
13-
@parent_group_model={{this.group}} />
13+
@new_group_perms={{this.new_group_perms}} />
1414
{{/each}}
1515
</div>
1616

Diff for: app/components/group/add.js

+7-12
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,15 @@ import { action } from '@ember/object';
33
import { tracked } from '@glimmer/tracking';
44
import { service } from '@ember/service';
55
import { group_perms_by_model } from 'papermerge/utils';
6+
import { TrackedArray } from 'tracked-built-ins';
67

78

89
class AddGroupComponent extends Component {
910
@service store;
1011
@service router;
1112

1213
@tracked name = '';
13-
14-
get group() {
15-
if (!this.new_group) {
16-
this.new_group = this.store.createRecord('group');
17-
}
18-
19-
return this.new_group;
20-
}
14+
@tracked new_group_perms = new TrackedArray();
2115

2216
get permission_groups() {
2317
return group_perms_by_model(this.args.all_permissions);
@@ -29,10 +23,11 @@ class AddGroupComponent extends Component {
2923

3024
@action
3125
onSubmit() {
32-
if (this.new_group && this.name) {
33-
this.new_group.name = this.name;
34-
this.new_group.save();
35-
}
26+
this.new_group = this.store.createRecord('group');
27+
this.new_group_perms.forEach(item => this.new_group.permissions.addObject(item));
28+
this.new_group.name = this.name;
29+
this.new_group.save();
30+
3631

3732
this.router.transitionTo('authenticated.groups');
3833
}

Diff for: app/components/group/edit.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
{{#each this.permission_groups as |perm_group|}}
1111
<Group::PermissionGroup
1212
@perm_group={{perm_group}}
13-
@parent_group_model={{@group}} />
13+
@new_group_perms={{@group.permissions}} />
1414
{{/each}}
1515
</div>
1616

Diff for: app/components/group/permission.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,15 @@ class PermissionComponent extends Component {
99
*/
1010
let parent_group_model_perm_ids;
1111

12-
parent_group_model_perm_ids = this.args.parent_group_model.permissions.map((p) => p.id);
12+
if (this.args.new_group_perms) {
13+
parent_group_model_perm_ids = this.args.new_group_perms.map((p) => p.id);
14+
}
1315

14-
return parent_group_model_perm_ids.includes(this.args.permission.id);
16+
if (parent_group_model_perm_ids) {
17+
return parent_group_model_perm_ids.includes(this.args.permission.id);
18+
}
19+
20+
return false;
1521
}
1622

1723
set isChecked(value) {

Diff for: app/components/group/permission_group.hbs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
{{#each @perm_group.perms as |perm|}}
88
<Group::Permission
99
@permission={{perm}}
10-
@parent_group_model={{@parent_group_model}}
10+
@new_group_perms={{@new_group_perms}}
1111
@onChange={{this.onChange}} />
1212
{{/each}}
13-
</div>
13+
</div>

Diff for: app/components/group/permission_group.js

+30-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Component from '@glimmer/component';
22
import { action } from '@ember/object';
33

4+
45
class PermissionGroupComponent extends Component {
56
/*
67
A permission group is a set of four permissions
@@ -14,6 +15,7 @@ class PermissionGroupComponent extends Component {
1415
`this.args.perm_group.model` - model name (e.g. User)
1516
*/
1617

18+
1719
get isChecked() {
1820
/*
1921
`isChecked` is true when all (four) permissions in the
@@ -28,10 +30,19 @@ class PermissionGroupComponent extends Component {
2830
*/
2931
let parent_group_model_perm_ids, group_perm_ids;
3032

31-
parent_group_model_perm_ids = this.args.parent_group_model.permissions.map((p) => p.id);
32-
group_perm_ids = this.args.perm_group.perms.map((p) => p.id);
33+
if (this.args.new_group_perms) {
34+
parent_group_model_perm_ids = this.args.new_group_perms.map((p) => p.id);
35+
}
36+
if (this.args.perm_group) {
37+
group_perm_ids = this.args.perm_group.perms.map((p) => p.id);
38+
}
39+
40+
if (parent_group_model_perm_ids) {
41+
return group_perm_ids.every((v) => parent_group_model_perm_ids.includes(v));
42+
}
3343

34-
return group_perm_ids.every((v) => parent_group_model_perm_ids.includes(v));
44+
45+
return false;
3546
}
3647

3748
set isChecked(value) {
@@ -63,31 +74,40 @@ class PermissionGroupComponent extends Component {
6374
of the group.
6475
*/
6576
let value = event.target.checked,
66-
parent_group_model = this.args.parent_group_model,
6777
that = this;
6878

6979
if (value) {
7080
// user chose to select (he checked) all
7181
// permissions in the group
7282
this.args.perm_group.perms.forEach((perm) => {
73-
that.addPermission(parent_group_model, perm);
83+
this.addPermission(perm);
7484
});
7585
} else {
7686
// user chose to unselect (i.e. he unchecked) all
7787
// permissions in the group
7888
this.args.perm_group.perms.forEach((perm) => {
79-
that.removePermission(parent_group_model, perm);
89+
this.removePermission(perm);
8090
});
8191
}
8292
}
8393

84-
addPermission(parent_group_model, perm) {
85-
parent_group_model.permissions.addObject(perm);
94+
addPermission(perm) {
95+
if (this.args.new_group_perms['push']) {
96+
this.args.new_group_perms.push(perm);
97+
} else if (this.args.new_group_perms['addObject']) {
98+
this.args.new_group_perms.addObject(perm);
99+
}
86100
}
87101

88-
removePermission(parent_group_model, perm) {
89-
parent_group_model.permissions.removeObject(perm);
102+
removePermission(perm) {
103+
if (this.args.new_group_perms['pop']) {
104+
this.args.new_group_perms.pop(perm);
105+
} else if (this.args.new_group_perms['removeObject']) {
106+
this.args.new_group_perms.removeObject(perm);
107+
}
108+
90109
}
110+
91111
}
92112

93113
export default PermissionGroupComponent;

Diff for: app/components/user/add.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,6 @@ class AddUserComponent extends Component {
2222

2323
groups = []
2424

25-
constructor(owner, args) {
26-
super(owner, args);
27-
28-
this.new_user = this.store.createRecord('user');
29-
}
30-
3125
get disabled() {
3226
/*
3327
Form can be submitted only when both
@@ -57,6 +51,9 @@ class AddUserComponent extends Component {
5751

5852
@action
5953
onSubmit() {
54+
55+
this.new_user = this.store.createRecord('user');
56+
6057
if (this.new_user && this.username && this.email) {
6158
this.new_user.username = this.username;
6259
this.new_user.email = this.email;

Diff for: app/templates/authenticated/groups/index.hbs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
<h1>Groups</h1>
2+
13
{{#if (has_perm 'add_group')}}
24
<Button::New @route="authenticated.groups.add" class="groups-add"/>
35
{{/if}}

Diff for: app/templates/authenticated/users/index.hbs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
<h1>Users</h1>
2+
13
{{#if (has_perm 'add_user')}}
24
<Button::New @route="authenticated.users.add" class="users-add"/>
35
{{/if}}

Diff for: changelog.d/513.fixed.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Empty page (no save button, no form controls) when adding new user/group

0 commit comments

Comments
 (0)