Skip to content

Commit

Permalink
297 roles (AplaProject#118)
Browse files Browse the repository at this point in the history
* Checked role tables

* Fixed notifications table

* Changed username to member_name

* Added notifications in tables

* Change tables

* Fixed parenthesis bug

* Fixed member name

* Removed rb_id
  • Loading branch information
gentee committed Jan 22, 2018
1 parent 3908c4c commit 5f0536c
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 107 deletions.
138 changes: 80 additions & 58 deletions packages/migration/ecosysystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -673,8 +673,7 @@ var (
"urlname" varchar(255) NOT NULL DEFAULT '',
"page" varchar(255) NOT NULL DEFAULT '',
"roles_access" text NOT NULL DEFAULT '',
"delete" bigint NOT NULL DEFAULT '0',
"rb_id" bigint NOT NULL DEFAULT '0'
"delete" bigint NOT NULL DEFAULT '0'
);
ALTER TABLE ONLY "%[1]d_sections" ADD CONSTRAINT "%[1]d_sections_pkey" PRIMARY KEY (id);
Expand Down Expand Up @@ -832,39 +831,60 @@ var (
"conditions": "ContractConditions(\"MainCondition\")"
}', 'ContractAccess("@1EditTable")'),
('9', 'member',
'{"insert": "ContractConditions(\"MainCondition\")", "update": "ContractConditions(\"MainCondition\")",
'{"insert": "ContractAccess(\"Profile_Edit\")", "update": "ContractAccess(\"Profile_Edit\")",
"new_column": "ContractConditions(\"MainCondition\")"}',
'{"username": "ContractConditions(\"MainCondition\")",
"avatar": "ContractConditions(\"MainCondition\")"}', 'ContractConditions(\"MainCondition\")'),
'{"member_name": "ContractAccess(\"Profile_Edit\")",
"avatar": "ContractAccess(\"Profile_Edit\")"}', 'ContractConditions(\"MainCondition\")'),
('10', 'roles_list',
'{"insert": "ContractConditions(\"MainCondition\")", "update": "ContractConditions(\"MainCondition\")",
'{"insert": "ContractAccess(\"Roles_Create\")", "update": "ContractAccess(\"Roles_Del\")",
"new_column": "ContractConditions(\"MainCondition\")"}',
'{"default_page": "ContractConditions(\"MainCondition\")",
"role_name": "ContractConditions(\"MainCondition\")",
"delete": "ContractConditions(\"MainCondition\")",
"role_type": "ContractConditions(\"MainCondition\")",
"creator_id": "ContractConditions(\"MainCondition\")",
"date_create": "ContractConditions(\"MainCondition\")",
"date_delete": "ContractConditions(\"MainCondition\")",
"creator_name": "ContractConditions(\"MainCondition\")",
"creator_avatar": "ContractConditions(\"MainCondition\")"}',
'{"default_page": "false",
"role_name": "false",
"delete": "ContractAccess(\"Roles_Del\")",
"role_type": "false",
"creator_id": "false",
"date_create": "false",
"date_delete": "ContractAccess(\"Roles_Del\")",
"creator_name": "false",
"creator_avatar": "false"}',
'ContractConditions(\"MainCondition\")'),
('11', 'roles_assign',
'{"insert": "ContractConditions(\"MainCondition\")", "update": "ContractConditions(\"MainCondition\")",
'{"insert": "ContractAccess(\"Roles_Assign\", \"voting_CheckDecision\")", "update": "ContractAccess(\"Roles_Unassign\")",
"new_column": "ContractConditions(\"MainCondition\")"}',
'{"role_id": "ContractConditions(\"MainCondition\")",
"role_type": "ContractConditions(\"MainCondition\")",
"role_name": "ContractConditions(\"MainCondition\")",
"member_id": "ContractConditions(\"MainCondition\")",
"member_username": "ContractConditions(\"MainCondition\")",
"member_avatar": "ContractConditions(\"MainCondition\")",
"appointed_by_id": "ContractConditions(\"MainCondition\")",
"appointed_by_name": "ContractConditions(\"MainCondition\")",
"date_start": "ContractConditions(\"MainCondition\")",
"date_end": "ContractConditions(\"MainCondition\")",
"delete": "ContractConditions(\"MainCondition\")"}',
'{"role_id": "false",
"role_type": "false",
"role_name": "false",
"member_id": "false",
"member_name": "false",
"member_avatar": "false",
"appointed_by_id": "false",
"appointed_by_name": "false",
"date_start": "false",
"date_end": "ContractAccess(\"Roles_Unassign\")",
"delete": "ContractAccess(\"Roles_Unassign\")"}',
'ContractConditions(\"MainCondition\")'),
('12', 'sections',
('12', 'notifications',
'{"insert": "ContractAccess(\"Notifications_Single_Send\",\"Notifications_Roles_Send\")", "update": "true",
"new_column": "ContractConditions(\"MainCondition\")"}',
'{"icon": "false",
"started_processing_time": "ContractAccess(\"Notifications_Roles_Processing\")",
"date_create": "false",
"page_params": "ContractAccess(\"Notifications_Single_Send\",\"Notifications_Roles_Send\")",
"body_text": "false",
"recipient_id": "false",
"started_processing_id": "ContractAccess(\"Notifications_Roles_Processing\")",
"role_id": "false",
"role_name": "false",
"recipient_name": "false",
"closed": "ContractAccess(\"Notifications_Single_Close\",\"Notifications_Roles_Finishing\")",
"header_text": "false",
"recipient_avatar": "false",
"notification_type": "false",
"finished_processing_id": "ContractAccess(\"Notifications_Single_Close\",\"Notifications_Roles_Finishing\")",
"finished_processing_time": "ContractAccess(\"Notifications_Single_Close\",\"Notifications_Roles_Finishing\")",
"page_name": "false"}',
'ContractAccess(\"@1EditTable\")'),
('13', 'sections',
'{"insert": "ContractConditions(\"MainCondition\")", "update": "ContractConditions(\"MainCondition\")",
"new_column": "ContractConditions(\"MainCondition\")"}',
'{"title": "ContractConditions(\"MainCondition\")",
Expand All @@ -877,24 +897,23 @@ var (
DROP TABLE IF EXISTS "%[1]d_notifications";
CREATE TABLE "%[1]d_notifications" (
"id" bigint NOT NULL DEFAULT '0',
"icon" varchar(255) NOT NULL DEFAULT '',
"closed" bigint NOT NULL DEFAULT '0',
"notification_type" bigint NOT NULL DEFAULT '0',
"started_processing_time" timestamp,
"started_time" timestamp,
"body_text" text NOT NULL DEFAULT '',
"recipient_id" bigint NOT NULL DEFAULT '0',
"started_processing_id" bigint NOT NULL DEFAULT '0',
"name" varchar(255) NOT NULL DEFAULT '',
"role_id" bigint NOT NULL DEFAULT '0',
"role_name" varchar(255) NOT NULL DEFAULT '',
"page_val_int" bigint NOT NULL DEFAULT '0',
"page_val_str" varchar(255) NOT NULL DEFAULT '',
"page_name" varchar(255) NOT NULL DEFAULT '',
"recipient_avatar" bytea NOT NULL DEFAULT '',
"date_create" timestamp,
"page_params" text NOT NULL DEFAULT '',
"recipient_name" varchar(255) NOT NULL DEFAULT '',
"closed" boolean,
"header_text" text NOT NULL DEFAULT '',
"recipient_avatar" text NOT NULL DEFAULT '',
"notification_type" bigint NOT NULL DEFAULT '0',
"finished_processing_id" bigint NOT NULL DEFAULT '0',
"finished_processing_time" timestamp,
"page_name" varchar(255) NOT NULL DEFAULT ''
"role_id" bigint NOT NULL DEFAULT '0',
"role_name" varchar(255) NOT NULL DEFAULT '',
"recipient_id" bigint NOT NULL DEFAULT '0',
"started_processing_id" bigint NOT NULL DEFAULT '0',
"body_text" text NOT NULL DEFAULT '',
"header_text" text NOT NULL DEFAULT ''
);
ALTER TABLE ONLY "%[1]d_notifications" ADD CONSTRAINT "%[1]d_notifications_pkey" PRIMARY KEY ("id");
Expand All @@ -904,58 +923,61 @@ var (
"id" bigint NOT NULL DEFAULT '0',
"default_page" varchar(255) NOT NULL DEFAULT '',
"role_name" varchar(255) NOT NULL DEFAULT '',
"delete" boolean,
"delete" bigint NOT NULL DEFAULT '0',
"role_type" bigint NOT NULL DEFAULT '0',
"creator_id" bigint NOT NULL DEFAULT '0',
"date_create" timestamp,
"date_delete" timestamp,
"creator_name" varchar(255) NOT NULL DEFAULT '',
"creator_avatar" varchar(255) NOT NULL DEFAULT ''
"creator_avatar" bytea NOT NULL DEFAULT ''
);
ALTER TABLE ONLY "%[1]d_roles_list" ADD CONSTRAINT "%[1]d_roles_list_pkey" PRIMARY KEY ("id");
CREATE INDEX "%[1]d_roles_list_index_delete" ON "%[1]d_roles_list" (delete);
CREATE INDEX "%[1]d_roles_list_index_type" ON "%[1]d_roles_list" (role_type);
INSERT INTO "%[1]d_roles_list" ("id", "default_page", "role_name", "delete", "role_type",
"date_create","creator_name") VALUES('1','default_ecosystem_page',
'Admin', '0', '3', NOW(), '');
DROP TABLE IF EXISTS "%[1]d_roles_assign";
CREATE TABLE "%[1]d_roles_assign" (
"id" bigint NOT NULL DEFAULT '0',
"role_id" bigint NOT NULL DEFAULT '0',
"role_type" bigint NOT NULL DEFAULT '0',
"role_name" varchar(255) NOT NULL DEFAULT '',
"member_id" bigint NOT NULL DEFAULT '0',
"member_username" varchar(255) NOT NULL DEFAULT '',
"member_avatar" varchar(255) NOT NULL DEFAULT '',
"member_name" varchar(255) NOT NULL DEFAULT '',
"member_avatar" bytea NOT NULL DEFAULT '',
"appointed_by_id" bigint NOT NULL DEFAULT '0',
"appointed_by_name" varchar(255) NOT NULL DEFAULT '',
"date_start" timestamp,
"date_end" timestamp,
"delete" boolean
"delete" bigint NOT NULL DEFAULT '0'
);
ALTER TABLE ONLY "%[1]d_roles_assign" ADD CONSTRAINT "%[1]d_roles_assign_pkey" PRIMARY KEY ("id");
CREATE INDEX "%[1]d_roles_assign_index_role" ON "%[1]d_roles_assign" (role_id);
CREATE INDEX "%[1]d_roles_assign_index_type" ON "%[1]d_roles_assign" (role_type);
CREATE INDEX "%[1]d_roles_assign_index_member" ON "%[1]d_roles_assign" (member_id);
INSERT INTO "%[1]d_roles_assign" ("id","role_id","role_type","role_name","member_id",
"member_name","date_start") VALUES('1','1','3','Admin','%[4]d','founder', NOW());
DROP TABLE IF EXISTS "%[1]d_member";
CREATE TABLE "%[1]d_member" (
"id" bigint NOT NULL DEFAULT '0',
"username" varchar(255) NOT NULL DEFAULT '',
"avatar" text NOT NULL DEFAULT ''
"member_name" varchar(255) NOT NULL DEFAULT '',
"avatar" bytea NOT NULL DEFAULT ''
);
ALTER TABLE ONLY "%[1]d_member" ADD CONSTRAINT "%[1]d_member_pkey" PRIMARY KEY ("id");
INSERT INTO "%[1]d_member" ("id", "member_name") VALUES('%[4]d', 'founder');
`

SchemaFirstEcosystem = `INSERT INTO "system_states" ("id") VALUES ('1');
INSERT INTO "1_member" ("id", "username") VALUES('%[1]d', 'founder');
INSERT INTO "1_roles_list" ("id", "default_page", "role_name", "delete", "role_type",
"creator_id","date_create","creator_name") VALUES('1','default_ecosystem_page',
'Admin', 'false', '1', '%[1]d', NOW(), 'founder');
INSERT INTO "1_roles_assign" ("id","role_id","role_type","role_name","member_id",
"member_username","appointed_by_id","appointed_by_name",
"date_start","delete") VALUES('1','1','1','Admin','%[1]d','founder','%[1]d', 'founder',
NOW(), 'false');
INSERT INTO "1_contracts" ("id","value", "wallet_id", "conditions") VALUES
('2','contract SystemFunctions {
}
Expand Down
4 changes: 2 additions & 2 deletions packages/model/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ func GetRecordsCount(tableName string) (int64, error) {
}

// ExecSchemaEcosystem is executing ecosystem schema
func ExecSchemaEcosystem(db *DbTransaction, id int, wallet int64, name string) error {
err := GetDB(db).Exec(fmt.Sprintf(migration.SchemaEcosystem, id, wallet, name)).Error
func ExecSchemaEcosystem(db *DbTransaction, id int, wallet int64, name string, founder int64) error {
err := GetDB(db).Exec(fmt.Sprintf(migration.SchemaEcosystem, id, wallet, name, founder)).Error
if err != nil {
log.WithFields(log.Fields{"type": consts.DBError, "error": err}).Error("executing ecosystem schema")
return err
Expand Down
2 changes: 1 addition & 1 deletion packages/model/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
// GetAllNotifications is retrieving all notifications by params
func GetAllNotifications(ecosystemID int64, lastNotificationID int64, userIDs []int64) ([]map[string]string, error) {
query := `select * from "` + strconv.FormatInt(ecosystemID, 10) +
`_notifications" where closed = false and id > ` + strconv.FormatInt(lastNotificationID, 10) +
`_notifications" where closed = 0 and id > ` + strconv.FormatInt(lastNotificationID, 10) +
` and recipient_id in (`
for _, userID := range userIDs {
query += strconv.FormatInt(int64(userID), 10) + ", "
Expand Down
2 changes: 1 addition & 1 deletion packages/parser/first_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (p *FirstBlockParser) Action() error {
logger := p.GetLogger()
data := p.TxPtr.(*consts.FirstBlock)
myAddress := crypto.Address(data.PublicKey)
err := model.ExecSchemaEcosystem(nil, 1, myAddress, ``)
err := model.ExecSchemaEcosystem(nil, 1, myAddress, ``, myAddress)
if err != nil {
logger.WithFields(log.Fields{"type": consts.DBError, "error": err}).Error("executing ecosystem schema")
return p.ErrInfo(err)
Expand Down
58 changes: 13 additions & 45 deletions packages/smart/smart_p.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,19 @@ func CreateEcosystem(sc *SmartContract, wallet int64, name string) (int64, error
log.WithFields(log.Fields{"type": consts.DBError}).Error("CreateEcosystem")
return 0, err
}
err = model.ExecSchemaEcosystem(sc.DbTransaction, converter.StrToInt(id), wallet, name)
var sp model.StateParameter
sp.SetTablePrefix(`1`)
found, err := sp.Get(sc.DbTransaction, `founder_account`)
if err != nil {
log.WithFields(log.Fields{"type": consts.DBError, "error": err}).Error("getting founder")
return 0, err
}
if !found || len(sp.Value) == 0 {
log.WithFields(log.Fields{"type": consts.NotFound, "error": ErrFounderAccount}).Error("founder not found")
return 0, ErrFounderAccount
}
err = model.ExecSchemaEcosystem(sc.DbTransaction, converter.StrToInt(id), wallet, name,
converter.StrToInt64(sp.Value))
if err != nil {
log.WithFields(log.Fields{"type": consts.DBError, "error": err}).Error("executing ecosystem schema")
return 0, err
Expand Down Expand Up @@ -401,50 +413,6 @@ func CreateEcosystem(sc *SmartContract, wallet int64, name string) (int64, error
log.WithFields(log.Fields{"type": consts.DBError, "error": err}).Error("inserting default page")
return 0, err
}
var sp model.StateParameter
sp.SetTablePrefix(`1`)
found, err := sp.Get(sc.DbTransaction, `founder_account`)
if err != nil {
log.WithFields(log.Fields{"type": consts.DBError, "error": err}).Error("getting founder")
return 0, err
}
if !found || len(sp.Value) == 0 {
log.WithFields(log.Fields{"type": consts.NotFound, "error": ErrFounderAccount}).Error("founder not found")
return 0, ErrFounderAccount
}
founder := sp.Value
_, ret, err = DBSelect(sc, "1_member", "id,username,avatar", converter.StrToInt64(founder), `id`,
0, 1, 0, ``, []interface{}{})
if err != nil {
log.WithFields(log.Fields{"type": consts.DBError, "error": err}).Error("getting founder username")
return 0, err
}
if Len(ret) == 0 {
log.WithFields(log.Fields{"type": consts.NotFound, "error": ErrFounderAccount}).Error("getting founder info")
return 0, ErrFounderAccount
}
founderInfo := ret[0].(map[string]string)
_, _, err = DBInsert(sc, id+"_member", "id,username,avatar", founderInfo[`id`],
founderInfo[`username`], founderInfo[`avatar`])
if err != nil {
log.WithFields(log.Fields{"type": consts.DBError, "error": err}).Error("inserting member info")
return 0, err
}
_, _, err = DBInsert(sc, id+"_roles_list", "default_page,role_name,delete,role_type,creator_id,date_create,creator_name,creator_avatar",
`default_ecosystem_page`, `Admin`, `false`, `1`, founder, `NOW()`, founderInfo[`username`],
founderInfo[`avatar`])
if err != nil {
log.WithFields(log.Fields{"type": consts.DBError, "error": err}).Error("inserting into role list")
return 0, err
}
_, _, err = DBInsert(sc, id+"_roles_assign", "role_id,role_type,role_name,member_id,member_username,member_avatar,appointed_by_id,appointed_by_name,date_start,delete",
`1`, `1`, `Admin`, founder, founderInfo[`username`], founderInfo[`avatar`],
founder, founderInfo[`username`], `NOW()`, `false`)
if err != nil {
log.WithFields(log.Fields{"type": consts.DBError, "error": err}).Error("inserting into role assign")
return 0, err
}

return converter.StrToInt64(id), err
}

Expand Down
3 changes: 3 additions & 0 deletions packages/template/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,9 @@ main:
if ch == '"' || ch == '`' {
pair = ch
} else {
if ch == modes[mode][0] {
level++
}
params[curp] = append(params[curp], ch)
}
}
Expand Down
2 changes: 2 additions & 0 deletions packages/template/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ func TestJSON(t *testing.T) {
}

var forTest = tplList{
{`Span((span text), ok )Span(((span text), ok) )Div(){{My body}}`,
`[{"tag":"span","attr":{"class":"ok"},"children":[{"tag":"text","text":"(span text)"}]},{"tag":"span","children":[{"tag":"text","text":"((span text), ok)"}]},{"tag":"div","children":[{"tag":"text","text":"{My body}"}]}]`},
{`Code(P(Some text)
Div(myclass){
Span(Strong("Bold text"))
Expand Down

0 comments on commit 5f0536c

Please sign in to comment.