Browse Source
data, logs, logs-content, story, story-content: Added permission check in UI to hide disallowed actions.
1.0
data, logs, logs-content, story, story-content: Added permission check in UI to hide disallowed actions.
1.0
Gisle Aune
6 years ago
22 changed files with 158 additions and 43 deletions
-
24marko/components/if-permitted/component.js
-
3marko/components/if-permitted/index.marko
-
8marko/components/menu/index.marko
-
12marko/page/data/components/add-character-modal/index.marko
-
2marko/page/data/components/channel-list/index.marko
-
4marko/page/data/components/channel/index.marko
-
2marko/page/data/components/channels-page/index.marko
-
1marko/page/data/components/character-list/index.marko
-
8marko/page/data/components/character/index.marko
-
2marko/page/data/components/characters-page/index.marko
-
12marko/page/data/components/data-menu/index.marko
-
9marko/page/logs-content/components/logs-content-menu/index.marko
-
9marko/page/logs-content/components/page/index.marko
-
14marko/page/logs-content/components/post/index.marko
-
13marko/page/logs/components/logs-menu/index.marko
-
8marko/page/story-content/components/chapter/index.marko
-
14marko/page/story-content/components/page/index.marko
-
11marko/page/story-content/components/story-content-menu/index.marko
-
4marko/page/story-content/components/story-tags/index.marko
-
2marko/page/story-content/components/story-tags/style.less
-
4marko/page/story/components/story-menu/index.marko
-
35middleware/locals.js
@ -0,0 +1,24 @@ |
|||||
|
module.exports = class { |
||||
|
onCreate() { |
||||
|
this.state = { |
||||
|
permitted: false |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
onInput(input) { |
||||
|
console.log(input.user, input.permission) |
||||
|
|
||||
|
if (!input.user || !input.user.loggedIn) { |
||||
|
this.state.permitted = false |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
if (input.author != null && input.author != "" && input.user.name === input.author) { |
||||
|
this.state.permitted = input.user.permissions.includes("member") |
||||
|
} else if (Array.isArray(input.permission)) { |
||||
|
this.state.permitted = input.user.permissions.find(p => input.permission.includes(p)) |
||||
|
} else { |
||||
|
this.state.permitted = input.user.permissions.includes(input.permission) |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,3 @@ |
|||||
|
<if(state.permitted)> |
||||
|
<include(input.renderBody) /> |
||||
|
</if> |
@ -1,5 +1,5 @@ |
|||||
<compact-list> |
<compact-list> |
||||
<compact-list-item for(channel in input.channels) key=(channel.name.replace("'", "_APOS_"))> |
<compact-list-item for(channel in input.channels) key=(channel.name.replace("'", "_APOS_"))> |
||||
<channel data=channel on-edited("emit", "edited", channel)/> |
|
||||
|
<channel data=channel user=input.user on-edited("emit", "edited", channel)/> |
||||
</compact-list-item> |
</compact-list-item> |
||||
</compact-list> |
</compact-list> |
@ -1,6 +1,6 @@ |
|||||
<data-menu categories=input.categories selected=(input.selected || {}) user=input.user on-open("open") /> |
<data-menu categories=input.categories selected=(input.selected || {}) user=input.user on-open("open") /> |
||||
<main> |
<main> |
||||
<channel-list channels=state.channels on-edited("channelEdited") /> |
|
||||
|
<channel-list channels=state.channels user=input.user on-edited("channelEdited") /> |
||||
</main> |
</main> |
||||
<add-channel-modal enabled=(state.modal === "channel.add") user=input.user on-added("channelAdded") on-close("close") /> |
<add-channel-modal enabled=(state.modal === "channel.add") user=input.user on-added("channelAdded") on-close("close") /> |
||||
<add-character-modal enabled=(state.modal === "character.add") user=input.user on-close("close") /> |
<add-character-modal enabled=(state.modal === "character.add") user=input.user on-close("close") /> |
@ -1,6 +1,6 @@ |
|||||
<data-menu categories=input.categories selected=(input.selected || {}) user=input.user on-open("open") /> |
<data-menu categories=input.categories selected=(input.selected || {}) user=input.user on-open("open") /> |
||||
<main> |
<main> |
||||
<character-list characters=state.characters on-removed("characterRemoved") on-edited("characterEdited") on-nicks("characterNicksChanged") /> |
|
||||
|
<character-list user=input.user characters=state.characters on-removed("characterRemoved") on-edited("characterEdited") on-nicks("characterNicksChanged") /> |
||||
</main> |
</main> |
||||
<add-character-modal enabled=(state.modal === "character.add") user=input.user on-added("characterAdded") on-close("close") /> |
<add-character-modal enabled=(state.modal === "character.add") user=input.user on-added("characterAdded") on-close("close") /> |
||||
<add-channel-modal enabled=(state.modal === "channel.add") user=input.user on-close("close") /> |
<add-channel-modal enabled=(state.modal === "channel.add") user=input.user on-close("close") /> |
@ -1,11 +1,10 @@ |
|||||
<menu user=input.user> |
<menu user=input.user> |
||||
<menu-header>Logs</menu-header> |
|
||||
<menu-link selected=input.selected.index icon="L" href="/logs/">All</menu-link> |
|
||||
<menu-link dark on-click("select", "add") icon="+">Add Log</menu-link> |
|
||||
|
<menu-header key="logs">Logs</menu-header> |
||||
|
<menu-link key="logs" selected=input.selected.index icon="L" href="/logs/">All</menu-link> |
||||
|
<if-permitted key="if-permitted" user=input.user permission="log.add"> |
||||
|
<menu-link key="add_log" dark on-click("select", "add") icon="+">Add Log</menu-link> |
||||
|
</if-permitted> |
||||
<menu-gap /> |
<menu-gap /> |
||||
<menu-header>Filters</menu-header> |
|
||||
|
<menu-header key="filters">Filters</menu-header> |
||||
<menu-gap /> |
<menu-gap /> |
||||
<menu-header>Data</menu-header> |
|
||||
<menu-link selected=input.selected.channels icon="C" href="/logs/characters/">Characters</menu-link> |
|
||||
<menu-link selected=input.selected.channels icon="#" href="/logs/channels">Channels</menu-link> |
|
||||
</menu> |
</menu> |
@ -1,4 +1,6 @@ |
|||||
<div class="story-tags"> |
<div class="story-tags"> |
||||
<a for(tag in input.tags) href=("/story/by-tag/" + tag.kind + "/" + encodeURIComponent(tag.name)) class=["tag", "color-tag-" + tag.kind.toLowerCase()]>${tag.name}</a> |
<a for(tag in input.tags) href=("/story/by-tag/" + tag.kind + "/" + encodeURIComponent(tag.name)) class=["tag", "color-tag-" + tag.kind.toLowerCase()]>${tag.name}</a> |
||||
<a on-click("select", "edit") class="option color-menu">Edit</a> |
|
||||
|
<if-permitted user=input.user author=input.author permission="story.edit"> |
||||
|
<a on-click("select", "edit") class="option color-menu">Manage Tags</a> |
||||
|
</if-permitted> |
||||
</div> |
</div> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue