Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redirect to private link after log in #1900

Merged
merged 1 commit into from
Sep 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions apps/files/src/components/FileList.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div class="uk-height-1-1">
<div class="uk-flex uk-flex-column uk-height-1-1">
<div class="uk-overflow-auto uk-flex-auto">
<div id="files-list-container" class="uk-overflow-auto uk-flex-auto">
<oc-table middle divider class="oc-filelist uk-margin-remove-bottom" id="files-list" v-show="!loadingFolder">
<thead>
<oc-table-row>
Expand Down Expand Up @@ -146,19 +146,18 @@ export default {
absolutePath = !this.item ? this.configuration.rootFolder : this.item
}

const self = this
this.loadFolder({
client: this.$client,
absolutePath: absolutePath,
$gettext: this.$gettext,
routeName: this.$route.name
}).then(() => {
const scrollTo = self.$route.query.scrollTo
if (scrollTo) {
self.$nextTick(() => {
self.setHighlightedFile(scrollTo)
const file = self.highlightedFile
self.$scrollTo(`#file-row-${file.id}`, 500, {
const scrollTo = this.$route.query.scrollTo
if (scrollTo && this.activeFiles.length > 0) {
this.$nextTick(() => {
const file = this.activeFiles.find(item => item.name === scrollTo)
this.setHighlightedFile(file)
this.$scrollTo(`#file-row-${file.id}`, 500, {
container: '#files-list-container'
})
})
Expand Down
15 changes: 12 additions & 3 deletions apps/files/src/components/FilesApp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div id="files">
<files-app-bar />
<oc-grid class="uk-height-1-1" oc-scroll-offset=".oc-app-bar">
<div class="uk-width-expand uk-overflow-auto uk-height-1-1" @dragover="$_ocApp_dragOver" :class="{ 'uk-visible@m' : _sidebarOpen }" id="files-list-container">
<div class="uk-width-expand uk-overflow-auto uk-height-1-1" @dragover="$_ocApp_dragOver" :class="{ 'uk-visible@m' : _sidebarOpen }">
<oc-loader id="files-list-progress" v-if="loadingFolder"></oc-loader>
<trash-bin v-if="$route.name === 'files-trashbin'" :fileData="activeFiles" />
<SharedFilesList v-else-if="sharedList" @toggle="toggleFileSelect" :fileData="activeFiles" />
Expand Down Expand Up @@ -53,7 +53,7 @@ export default {
},
methods: {
...mapActions('Files', ['resetFileSelection', 'addFileSelection', 'removeFileSelection', 'dragOver', 'setHighlightedFile', 'toggleFileSelect']),
...mapActions(['openFile', 'showMessage']),
...mapActions(['openFile', 'showMessage', 'setPrivateLinkUrlPath']),

trace () {
console.info('trace', arguments)
Expand Down Expand Up @@ -122,7 +122,7 @@ export default {

computed: {
...mapGetters('Files', ['selectedFiles', 'activeFiles', 'dropzone', 'loadingFolder', 'highlightedFile']),
...mapGetters(['extensions']),
...mapGetters(['extensions', 'privateLinkUrlPath']),

_sidebarOpen () {
return this.highlightedFile !== null
Expand All @@ -136,6 +136,15 @@ export default {
$route () {
this.setHighlightedFile(null)
}
},
beforeMount () {
// Redirect to private link after authorization
if (this.privateLinkUrlPath) {
this.$router.push(this.privateLinkUrlPath)
// Resets private link path in store
// Needed due to persistance of that state
this.setPrivateLinkUrlPath(null)
}
}
}
</script>
2 changes: 1 addition & 1 deletion apps/files/src/components/FilesAppBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<div class="uk-width-expand">
<oc-breadcrumb id="files-breadcrumb" :items="breadcrumbs" v-if="showBreadcrumb" home></oc-breadcrumb>
<span class="uk-flex uk-flex-middle" v-if="!showBreadcrumb">
<oc-icon :name="pageIcon" class="uk-margin-small-right"></oc-icon>
<oc-icon v-if="pageIcon" :name="pageIcon" class="uk-margin-small-right" />
<span class="uk-text-lead">{{pageTitle}}</span>
</span>
</div>
Expand Down
5 changes: 4 additions & 1 deletion src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const router = new Router({
path: '/f/:fileId',
name: 'privateLink',
redirect: '/files/private-link/:fileId',
meta: { auth: false, hideHeadbar: true }
meta: { hideHeadbar: true }
},
{
path: '/s/:token',
Expand All @@ -66,6 +66,9 @@ const router = new Router({
})

router.beforeEach(function (to, from, next) {
if (to.name === 'private-link') {
store.dispatch('setPrivateLinkUrlPath', to.path)
}
let authRequired = true
if (to.meta.auth === false) {
authRequired = false
Expand Down
8 changes: 5 additions & 3 deletions src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import app from './app'
import apps from './apps'
import config from './config'
import user from './user'
import links from './links'

Vue.use(Vuex)

const vuexPersist = new VuexPersistence({
key: 'phoenixState',
storage: window.localStorage,
filter: (mutation) => (['SET_USER', 'SET_TOKEN'].indexOf(mutation.type) > -1),
modules: ['user']
filter: (mutation) => (['SET_USER', 'SET_TOKEN', 'SET_PRIVATE_LINK_URL_PATH'].indexOf(mutation.type) > -1),
modules: ['user', 'links']
})

const strict = process.env.NODE_ENV === 'development'
Expand All @@ -29,7 +30,8 @@ export const Store = new Vuex.Store({
app,
apps,
user,
config
config,
links
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be it's own module due to vuex-persist. Since we are using modules in options we can't use reducer to persist only specific states. This would mean the only option of adding it to existing module would be user module which doesn't seem right to me to contain info about private link.

},
strict
})
Expand Down
30 changes: 30 additions & 0 deletions src/store/links.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const state = {
/**
* Private link path in case user needs to log in first
* @return {string} path to the file/folder
*/
privateLinkUrlPath: null
}

const actions = {
setPrivateLinkUrlPath ({ commit }, path) {
commit('SET_PRIVATE_LINK_URL_PATH', path)
}
}

const mutations = {
SET_PRIVATE_LINK_URL_PATH (state, path) {
state.privateLinkUrlPath = path
}
}

const getters = {
privateLinkUrlPath: state => state.privateLinkUrlPath
}

export default {
state,
actions,
mutations,
getters
}