-
Notifications
You must be signed in to change notification settings - Fork 329
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ef46fc7
commit 965e66e
Showing
8 changed files
with
148 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<template> | ||
<div | ||
v-if="avatars?.length" | ||
class="mr-1.5 flex cursor-pointer items-center" | ||
:class="[ | ||
avatars?.length > 1 ? 'flex-row-reverse' : 'truncate [&>div]:truncate', | ||
]" | ||
> | ||
<Tooltip | ||
v-if="avatars?.length == 1" | ||
:text="avatars[0].name" | ||
class="flex items-center gap-2 text-base" | ||
> | ||
<Avatar | ||
shape="circle" | ||
:image="avatars[0].image" | ||
:label="avatars[0].label" | ||
size="sm" | ||
/> | ||
<div class="truncate">{{ avatars[0].label }}</div> | ||
</Tooltip> | ||
<Tooltip | ||
v-for="avatar in reverseAvatars" | ||
v-else | ||
:key="avatar.name" | ||
:text="avatar.name" | ||
> | ||
<Avatar | ||
class="-mr-1.5 ring-2 ring-white transition hover:z-10 hover:scale-110" | ||
shape="circle" | ||
:image="avatar.image" | ||
:label="avatar.label" | ||
:size="size" | ||
/> | ||
</Tooltip> | ||
</div> | ||
</template> | ||
<script setup lang="ts"> | ||
import { Avatar, Tooltip } from "frappe-ui"; | ||
import { computed } from "vue"; | ||
const props = defineProps({ | ||
avatars: { | ||
type: Array, | ||
default: [], | ||
}, | ||
size: { | ||
type: String, | ||
default: "md", | ||
}, | ||
}); | ||
const reverseAvatars = computed(() => props.avatars.reverse()); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { defineStore } from "pinia"; | ||
import { createResource } from "frappe-ui"; | ||
import { useAuthStore } from "./auth"; | ||
import { reactive } from "vue"; | ||
import { router } from "@/router"; | ||
|
||
export const useUserStore = defineStore("user", () => { | ||
const auth = useAuthStore(); | ||
const usersByName = reactive({}); | ||
|
||
const users = createResource({ | ||
url: "helpdesk.api.session.get_users", | ||
cache: "Users", | ||
initialData: [], | ||
transform(users) { | ||
for (const user of users) { | ||
usersByName[user.name] = user; | ||
} | ||
return users; | ||
}, | ||
onError(error) { | ||
if (error && error.exc_type === "AuthenticationError") { | ||
router.push("/login"); | ||
} | ||
}, | ||
}); | ||
|
||
const init = users.fetch; | ||
|
||
function getUser(email) { | ||
if (!email || email === "sessionUser") { | ||
email = auth.username; | ||
} | ||
if (!usersByName[email]) { | ||
usersByName[email] = { | ||
name: email, | ||
email: email, | ||
full_name: email.split("@")[0], | ||
user_image: null, | ||
role: null, | ||
}; | ||
} | ||
return usersByName[email]; | ||
} | ||
|
||
return { | ||
users, | ||
getUser, | ||
init, | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import frappe | ||
|
||
@frappe.whitelist() | ||
def get_users(): | ||
if frappe.session.user == "Guest": | ||
frappe.throw("Authentication failed", exc=frappe.AuthenticationError) | ||
|
||
users = frappe.qb.get_query( | ||
"User", | ||
fields=["name", "email", "enabled", "user_image", "full_name", "user_type"], | ||
order_by="full_name asc", | ||
distinct=True, | ||
).run(as_dict=1) | ||
|
||
for user in users: | ||
if frappe.session.user == user.name: | ||
user.session_user = True | ||
|
||
return users |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters