Skip to content

Commit f2794a9

Browse files
Merge pull request #121 from documize/granular-permissions
Granular permissions
2 parents 3756363 + d9eda2a commit f2794a9

File tree

224 files changed

+11796
-7706
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

224 files changed

+11796
-7706
lines changed

README.md

+58-13
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,93 @@
11
# Documize Community Edition
22

3-
Documize is an Integrated Document Environment (IDE) unifying documents, wiki, reporting and dashboards -- one tool to power the enterprise-wide knowledge backbone.
3+
## The mission
44

5-
![Alt text](screenshot.png "Documize")
5+
To bring software development inspired features to the world of documenting -- refactoring, importing, testing, linting, metrics, PRs, versioning....
66

7-
The mission is to bring software dev inspired features (refactoring, testing, linting, metrics, PRs) to those poor souls stuck writing docs in the dark ages.
7+
## What is it?
8+
9+
Documize is an intelligent document environment (IDE) for creating, securing and sharing documents -- everything you need in one place.
10+
11+
## Why should I care?
12+
13+
Because maybe like us, you might be tired of:
14+
15+
* juggling WYSIWYG editors, wiki software and various document related solutions
16+
* playing document related email tennis with contributions, versions and feedback
17+
* sharing not-so-secure folders with external participants
18+
19+
Sound familiar? Read on.
20+
21+
## Who is it for?
22+
23+
Anyone who wants a single place for any kind of document.
24+
25+
Anyone who wants to loop in external participants complete security.
26+
27+
Anyone who wishes documentation and knowledge capture worked like agile software development.
28+
29+
## What's different about Documize?
30+
31+
Sane organization through personal, team and public spaces.
32+
33+
Granular document access control via categories.
34+
35+
Section based approach to document construction.
36+
37+
Reusable templates and content blocks.
38+
39+
Documentation related tasking and delegation.
40+
41+
Integrations for embedding SaaS data within documents.
842

943
## Latest version
1044

11-
v1.53.6
45+
v1.54.0
1246

13-
## OS Support
47+
## OS support
48+
49+
Documize runs on the following:
1450

15-
- Windows
1651
- Linux
52+
- Windows
1753
- macOS
1854

19-
## Tech stack
55+
## Technology stack
56+
57+
Documize is built with the following technologies:
2058

2159
- EmberJS (v2.15.0)
2260
- Go (v1.9.0)
23-
- MySQL (v5.7.10+) or Percona (v5.7.16-10+) or MariaDB (10.3.0+)
2461

25-
## Documentation
62+
...and supports the following databases:
2663

27-
<https://docs.documize.com>
64+
- MySQL (v5.7.10+)
65+
- Percona (v5.7.16-10+)
66+
- MariaDB (10.3.0+)
67+
68+
Coming soon, PostgreSQL and Microsoft SQL Server support.
69+
70+
## Authentication options
71+
72+
Besides email/password login, you can also leverage the following options.
2873

29-
## Keycloak Integration
74+
### Keycloak Integration
3075

3176
Documize provides out-of-the-box integration with [Redhat Keycloak](http://www.keycloak.org) for open source identity and access management.
3277

3378
Connect and authenticate with LDAP, Active Directory and more.
3479

3580
<https://docs.documize.com>
3681

37-
## Auth0 Compatible
82+
### Auth0 Compatible
3883

3984
Documize is compatible with Auth0 identity as a service.
4085

4186
[![JWT Auth for open source projects](https://cdn.auth0.com/oss/badges/a0-badge-dark.png)](https://auth0.com/?utm_source=oss&utm_medium=gp&utm_campaign=oss)
4287

4388
Open Source Identity and Access Management
4489

45-
## Legal
90+
## The legal bit at the end
4691

4792
<https://documize.com>
4893

build.sh

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#! /bin/bash
22

3+
# ember s apiHost=https://demo1.dev:5001
4+
# go run edition/community.go -port=5001 -forcesslport=5002 -cert selfcert/cert.pem -key selfcert/key.pem -salt=tsu3Acndky8cdTNx3
5+
36
NOW=$(date)
47
echo "Build process started $NOW"
58

core/database/check.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ func Check(runtime *env.Runtime) bool {
120120

121121
{ // check all the required tables exist
122122
var tables = []string{`account`,
123-
`attachment`, `audit`, `document`,
124-
`label`, `labelrole`, `organization`,
123+
`attachment`, `document`,
124+
`label`, `organization`,
125125
`page`, `revision`, `search`, `user`}
126126

127127
for _, table := range tables {

core/database/endpoint.go

+9-7
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ func setupAccount(rt *env.Runtime, completion onboardRequest, serial string) (er
161161
return err
162162
}
163163

164-
// Set up default labels for main collection.
164+
// create space
165165
labelID := uniqueid.Generate()
166166
sql = fmt.Sprintf("insert into label (refid, orgid, label, type, userid) values (\"%s\", \"%s\", \"My Project\", 2, \"%s\")", labelID, orgID, userID)
167167
_, err = runSQL(rt, sql)
@@ -170,12 +170,14 @@ func setupAccount(rt *env.Runtime, completion onboardRequest, serial string) (er
170170
rt.Log.Error("insert into label failed", err)
171171
}
172172

173-
labelRoleID := uniqueid.Generate()
174-
sql = fmt.Sprintf("insert into labelrole (refid, labelid, orgid, userid, canview, canedit) values (\"%s\", \"%s\", \"%s\", \"%s\", 1, 1)", labelRoleID, labelID, orgID, userID)
175-
_, err = runSQL(rt, sql)
176-
177-
if err != nil {
178-
rt.Log.Error("insert into labelrole failed", err)
173+
// assign permissions to space
174+
perms := []string{"view", "manage", "own", "doc-add", "doc-edit", "doc-delete", "doc-move", "doc-copy", "doc-template"}
175+
for _, p := range perms {
176+
sql = fmt.Sprintf("insert into permission (orgid, who, whoid, action, scope, location, refid) values (\"%s\", 'user', \"%s\", \"%s\", 'object', 'space', \"%s\")", orgID, userID, p, labelID)
177+
_, err = runSQL(rt, sql)
178+
if err != nil {
179+
rt.Log.Error("insert into permission failed", err)
180+
}
179181
}
180182

181183
return
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
/* community edition */
2+
3+
-- permission records space and document level privelges, making existing labelrole table obsolete
4+
-- who column can be user or role
5+
-- whoid column contains eitehr user or role ID
6+
-- action column records permission type (view, edit, delete...)
7+
-- scope column details if action applies to object or table
8+
-- location column details name of table
9+
-- refid column details ID of item that the action applies to (only if scope=object)
10+
DROP TABLE IF EXISTS `permission`;
11+
12+
CREATE TABLE IF NOT EXISTS `permission` (
13+
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
14+
`orgid` CHAR(16) NOT NULL COLLATE utf8_bin,
15+
`who` VARCHAR(30) NOT NULL,
16+
`whoid` CHAR(16) DEFAULT '' NOT NULL COLLATE utf8_bin,
17+
`action` VARCHAR(30) NOT NULL,
18+
`scope` VARCHAR(30) NOT NULL,
19+
`location` VARCHAR(100) NOT NULL,
20+
`refid` CHAR(16) NOT NULL COLLATE utf8_bin,
21+
`created` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
22+
UNIQUE INDEX `idx_permission_id` (`id` ASC),
23+
INDEX `idx_permission_orgid` (`orgid` ASC))
24+
DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci
25+
ENGINE = MyISAM;
26+
27+
CREATE INDEX idx_permission_1 ON permission(orgid,who,whoid,location);
28+
CREATE INDEX idx_permission_2 ON permission(orgid,who,whoid,location,action);
29+
CREATE INDEX idx_permission_3 ON permission(orgid,location,refid);
30+
CREATE INDEX idx_permission_4 ON permission(orgid,who,location,action);
31+
32+
-- category represents "folder/label/category" assignment to document (1:M)
33+
DROP TABLE IF EXISTS `category`;
34+
35+
CREATE TABLE IF NOT EXISTS `category` (
36+
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
37+
`refid` CHAR(16) NOT NULL COLLATE utf8_bin,
38+
`orgid` CHAR(16) NOT NULL COLLATE utf8_bin,
39+
`labelid` CHAR(16) NOT NULL COLLATE utf8_bin,
40+
`category` VARCHAR(30) NOT NULL,
41+
`created` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
42+
`revised` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
43+
UNIQUE INDEX `idx_category_id` (`id` ASC),
44+
INDEX `idx_category_refid` (`refid` ASC),
45+
INDEX `idx_category_orgid` (`orgid` ASC))
46+
DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci
47+
ENGINE = MyISAM;
48+
49+
CREATE INDEX idx_category_1 ON category(orgid,labelid);
50+
51+
-- category member records who can see a category and the documents within
52+
DROP TABLE IF EXISTS `categorymember`;
53+
54+
CREATE TABLE IF NOT EXISTS `categorymember` (
55+
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
56+
`refid` CHAR(16) NOT NULL COLLATE utf8_bin,
57+
`orgid` CHAR(16) NOT NULL COLLATE utf8_bin,
58+
`labelid` CHAR(16) NOT NULL COLLATE utf8_bin,
59+
`categoryid` CHAR(16) NOT NULL COLLATE utf8_bin,
60+
`documentid` CHAR(16) NOT NULL COLLATE utf8_bin,
61+
`created` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
62+
`revised` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
63+
UNIQUE INDEX `idx_categorymember_id` (`id` ASC),
64+
INDEX `idx_category_documentid` (`documentid`))
65+
DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci
66+
ENGINE = MyISAM;
67+
68+
CREATE INDEX idx_categorymember_1 ON categorymember(orgid,documentid);
69+
CREATE INDEX idx_categorymember_2 ON categorymember(orgid,labelid);
70+
71+
-- rolee represent user groups
72+
DROP TABLE IF EXISTS `role`;
73+
74+
CREATE TABLE IF NOT EXISTS `role` (
75+
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
76+
`refid` CHAR(16) NOT NULL COLLATE utf8_bin,
77+
`orgid` CHAR(16) NOT NULL COLLATE utf8_bin,
78+
`role` VARCHAR(30) NOT NULL,
79+
`created` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
80+
UNIQUE INDEX `idx_category_id` (`id` ASC),
81+
INDEX `idx_category_refid` (`refid` ASC),
82+
INDEX `idx_category_orgid` (`orgid` ASC))
83+
DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci
84+
ENGINE = MyISAM;
85+
86+
-- role member records user role membership
87+
DROP TABLE IF EXISTS `rolemember`;
88+
89+
CREATE TABLE IF NOT EXISTS `rolemember` (
90+
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
91+
`orgid` CHAR(16) NOT NULL COLLATE utf8_bin,
92+
`roleid` CHAR(16) NOT NULL COLLATE utf8_bin,
93+
`userid` CHAR(16) NOT NULL COLLATE utf8_bin,
94+
UNIQUE INDEX `idx_category_id` (`id` ASC))
95+
DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci
96+
ENGINE = MyISAM;
97+
98+
CREATE INDEX idx_rolemember_1 ON rolemember(roleid,userid);
99+
CREATE INDEX idx_rolemember_2 ON rolemember(orgid,roleid,userid);
100+
101+
-- user account can have global permssion to state if user can see all other users
102+
-- provides granular control for external users
103+
ALTER TABLE account ADD COLUMN `users` BOOL NOT NULL DEFAULT 1 AFTER `admin`;
104+
105+
-- migrate space/document permissions
106+
107+
-- space own
108+
INSERT INTO permission (orgid, who, whoid, `action`, scope, location, refid)
109+
SELECT orgid, 'user' as who, userid as whois, 'own' as `action`, 'object' as scope, 'space' as location, refid
110+
FROM label;
111+
112+
-- space manage (same as owner)
113+
INSERT INTO permission (orgid, who, whoid, `action`, scope, location, refid)
114+
SELECT orgid, 'user' as who, userid as whois, 'manage' as `action`, 'object' as scope, 'space' as location, refid
115+
FROM label;
116+
117+
-- view space
118+
INSERT INTO permission (orgid, who, whoid, `action`, scope, location, refid)
119+
SELECT orgid, 'user' as who, userid as whois, 'view' as `action`, 'object' as scope, 'space' as location, labelid as refid
120+
FROM labelrole WHERE canview=1;
121+
122+
-- edit space => add/edit/delete/move/copy/template documents
123+
INSERT INTO permission (orgid, who, whoid, `action`, scope, location, refid)
124+
SELECT orgid, 'user' as who, userid as whois, 'doc-add' as `action`, 'object' as scope, 'space' as location, labelid as refid
125+
FROM labelrole WHERE canedit=1;
126+
INSERT INTO permission (orgid, who, whoid, `action`, scope, location, refid)
127+
SELECT orgid, 'user' as who, userid as whois, 'doc-edit' as `action`, 'object' as scope, 'space' as location, labelid as refid
128+
FROM labelrole WHERE canedit=1;
129+
INSERT INTO permission (orgid, who, whoid, `action`, scope, location, refid)
130+
SELECT orgid, 'user' as who, userid as whois, 'doc-delete' as `action`, 'object' as scope, 'space' as location, labelid as refid
131+
FROM labelrole WHERE canedit=1;
132+
INSERT INTO permission (orgid, who, whoid, `action`, scope, location, refid)
133+
SELECT orgid, 'user' as who, userid as whois, 'doc-move' as `action`, 'object' as scope, 'space' as location, labelid as refid
134+
FROM labelrole WHERE canedit=1;
135+
INSERT INTO permission (orgid, who, whoid, `action`, scope, location, refid)
136+
SELECT orgid, 'user' as who, userid as whois, 'doc-copy' as `action`, 'object' as scope, 'space' as location, labelid as refid
137+
FROM labelrole WHERE canedit=1;
138+
INSERT INTO permission (orgid, who, whoid, `action`, scope, location, refid)
139+
SELECT orgid, 'user' as who, userid as whois, 'doc-template' as `action`, 'object' as scope, 'space' as location, labelid as refid
140+
FROM labelrole WHERE canedit=1;
141+
142+
-- everyone users ID changed to 0
143+
UPDATE permission SET whoid='0' WHERE whoid='';

0 commit comments

Comments
 (0)