Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Nocobase
Commits
93f22eca
Commit
93f22eca
authored
4 years ago
by
chenos
Browse files
Options
Download
Email Patches
Plain Diff
小细节补充
parent
6330521f
feature/plugin-permissions
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
packages/app/src/components/views/SortableTable/index.tsx
+30
-1
packages/app/src/components/views/SortableTable/index.tsx
packages/app/src/components/views/Table.tsx
+1
-1
packages/app/src/components/views/Table.tsx
packages/plugin-pages/src/actions/roles.pages.ts
+79
-0
packages/plugin-pages/src/actions/roles.pages.ts
packages/plugin-permissions/src/actions/roles.collections.ts
+18
-2
packages/plugin-permissions/src/actions/roles.collections.ts
with
128 additions
and
4 deletions
+128
-4
packages/app/src/components/views/SortableTable/index.tsx
+
30
-
1
View file @
93f22eca
...
...
@@ -8,6 +8,8 @@ import get from 'lodash/get';
import
'
./style.less
'
;
import
Field
from
'
../Field
'
;
import
cloneDeep
from
'
lodash/cloneDeep
'
;
import
{
Checkbox
,
message
}
from
'
antd
'
;
import
api
from
'
@/api-client
'
;
export
const
SortableItem
=
sortableElement
(
props
=>
<
tr
{
...
props
}
/>);
export
const
SortableContainer
=
sortableContainer
(
props
=>
<
tbody
{
...
props
}
/>);
...
...
@@ -58,11 +60,38 @@ export const components = ({data = {}, rowKey, mutate, onMoved, isFieldComponent
};
};
export
function
fields2columns
(
fields
)
{
export
function
fields2columns
(
fields
,
ctx
:
any
=
{}
)
{
const
columns
:
any
[]
=
fields
.
map
(
item
=>
{
const
field
=
cloneDeep
(
item
);
field
.
render
=
(
value
,
record
)
=>
field
.
interface
===
'
sort
'
?
<
DragHandle
/>
:
<
Field
data
=
{
record
}
viewType
=
{
'
table
'
}
schema
=
{
field
}
value
=
{
value
}
/>;
field
.
className
=
`
${
field
.
className
||
''
}
noco-field-
${
field
.
interface
}
`
;
if
(
field
.
editable
&&
field
.
interface
===
'
boolean
'
)
{
field
.
title
=
(
<
span
>
<
Checkbox
onChange
=
{
async
(
e
)
=>
{
try
{
await
api
.
resource
(
field
.
resource
).
update
({
associatedKey
:
ctx
.
associatedKey
,
// resourceKey: data.id,
// tableName: data.tableName||'pages',
values
:
{
accessible
:
e
.
target
.
checked
,
},
});
message
.
success
(
'
保存成功
'
);
if
(
ctx
.
refresh
)
{
ctx
.
refresh
();
}
}
catch
(
error
)
{
message
.
error
(
'
保存失败
'
);
}
}
}
/>
{
'
'
}
{
field
.
title
}
</
span
>
);
}
return
{
...
field
,
...(
field
.
component
||
{}),
...
...
This diff is collapsed.
Click to expand it.
packages/app/src/components/views/Table.tsx
+
1
-
1
View file @
93f22eca
...
...
@@ -154,7 +154,7 @@ export function Table(props: TableProps) {
indicator
:
icon
,
// className: 'spinning--absolute m32',
}
}
columns
=
{
fields2columns
(
fields
)
}
columns
=
{
fields2columns
(
fields
,
{
associatedKey
,
refresh
}
)
}
dataSource
=
{
data
?.
list
||
(
data
as
any
)
}
onChange
=
{
(
pagination
,
filters
,
sorter
,
extra
)
=>
{
run
({...
params
[
0
],
sorter
});
...
...
This diff is collapsed.
Click to expand it.
packages/plugin-pages/src/actions/roles.pages.ts
+
79
-
0
View file @
93f22eca
...
...
@@ -3,6 +3,69 @@ import Database from '@nocobase/database';
import
{
flatToTree
}
from
'
../utils
'
;
import
{
Op
}
from
'
sequelize
'
;
async
function
getRoutes
(
ctx
)
{
const
database
:
Database
=
ctx
.
db
;
const
Page
=
database
.
getModel
(
'
pages
'
);
const
Collection
=
database
.
getModel
(
'
collections
'
);
let
pages
=
await
Page
.
findAll
(
Page
.
parseApiJson
(
ctx
.
state
.
developerMode
?
{
filter
:
{
'
parent_id.$notNull
'
:
true
,
},
sort
:
[
'
sort
'
],
}
:
{
filter
:
{
'
parent_id.$notNull
'
:
true
,
developerMode
:
{
'
$isFalsy
'
:
true
},
},
sort
:
[
'
sort
'
],
}));
const
items
=
[];
for
(
const
page
of
pages
)
{
items
.
push
({
routable_type
:
'
pages
'
,
routable_id
:
page
.
id
,
});
if
(
page
.
get
(
'
path
'
)
===
'
/collections
'
)
{
const
collections
=
await
Collection
.
findAll
(
Collection
.
parseApiJson
(
ctx
.
state
.
developerMode
?
{
filter
:
{
showInDataMenu
:
true
,
},
sort
:
[
'
sort
'
],
}:
{
filter
:
{
developerMode
:
{
'
$isFalsy
'
:
true
},
showInDataMenu
:
true
,
},
sort
:
[
'
sort
'
],
}));
for
(
const
collection
of
collections
)
{
items
.
push
({
routable_type
:
'
collections
'
,
routable_id
:
collection
.
id
,
});
const
views
=
await
collection
.
getViews
({
where
:
{
[
Op
.
or
]:
[
{
showInDataMenu
:
true
},
{
default
:
true
}
]
},
order
:
[[
'
sort
'
,
'
asc
'
]]
});
if
(
views
.
length
>
1
)
{
for
(
const
view
of
views
)
{
items
.
push
({
routable_id
:
view
.
id
,
routable_type
:
'
views
'
,
});
}
}
}
}
}
return
items
;
}
export
async
function
list
(
ctx
:
actions
.
Context
,
next
:
actions
.
Next
)
{
const
database
:
Database
=
ctx
.
db
;
const
{
associatedKey
,
associated
}
=
ctx
.
action
.
params
;
...
...
@@ -125,6 +188,22 @@ export async function update(ctx: actions.Context, next: actions.Next) {
}
}
=
ctx
.
action
.
params
;
if
(
!
resourceKey
)
{
if
(
accessible
===
false
)
{
await
associated
.
updateAssociations
({
routes
:
[],
});
}
else
if
(
accessible
===
true
)
{
const
routes
=
await
getRoutes
(
ctx
);
// console.log(routes);
await
associated
.
updateAssociations
({
routes
,
});
}
ctx
.
body
=
{};
return
next
();
}
console
.
log
(
ctx
.
action
.
params
,
{
routable_type
:
tableName
,
routable_id
:
resourceKey
});
let
[
route
]
=
await
associated
.
getRoutes
({
where
:
{
routable_type
:
tableName
,
routable_id
:
resourceKey
},
...
...
This diff is collapsed.
Click to expand it.
packages/plugin-permissions/src/actions/roles.collections.ts
+
18
-
2
View file @
93f22eca
import
{
Op
}
from
'
sequelize
'
;
import
{
actions
}
from
'
@nocobase/actions
'
;
import
_
from
'
lodash
'
;
export
async
function
list
(
ctx
:
actions
.
Context
,
next
:
actions
.
Next
)
{
const
{
associated
}
=
ctx
.
action
.
params
;
...
...
@@ -16,8 +17,8 @@ export async function list(ctx: actions.Context, next: actions.Next) {
item
.
set
(
'
permissions
'
,
[
permission
]);
// 输出
}
});
next
();
});
await
next
();
}
export
async
function
get
(
ctx
:
actions
.
Context
,
next
:
actions
.
Next
)
{
...
...
@@ -26,7 +27,22 @@ export async function get(ctx: actions.Context, next: actions.Next) {
associated
}
=
ctx
.
action
.
params
;
ctx
.
body
=
await
ctx
.
ac
.
as
(
associated
).
can
(
resourceKey
).
permissions
();
const
permissions
=
await
ctx
.
ac
.
as
(
associated
).
can
(
resourceKey
).
permissions
();
const
permission
=
await
associated
.
getPermissions
({
where
:
{
collection_name
:
resourceKey
,
},
plain
:
true
,
limit
:
1
,
});
console
.
log
(
permission
);
ctx
.
body
=
{
...
permissions
,
description
:
_
.
get
(
permission
,
'
description
'
),
};
await
next
();
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help