Skip to content

Commit

Permalink
Merge pull request #980 from pateljannat/member-addition
Browse files Browse the repository at this point in the history
feat: Add users from the portal
  • Loading branch information
pateljannat authored Aug 19, 2024
2 parents 0170fcc + 98b8464 commit e69cc9a
Show file tree
Hide file tree
Showing 7 changed files with 265 additions and 88 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ui-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ jobs:
cd ~/frappe-bench/
bench --site lms.test execute frappe.utils.install.complete_setup_wizard
bench --site lms.test execute frappe.tests.ui_test_helpers.create_test_user
bench --site lms.test set-password [email protected] admin
- name: cypress pre-requisites
run: |
Expand Down
183 changes: 183 additions & 0 deletions frontend/src/components/Members.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
<template>
<div class="text-base p-4">
<div class="flex items-center justify-between">
<div>
<div class="font-semibold mb-1">
{{ __(label) }}
</div>
<div class="text-xs text-gray-600">
{{ __(description) }}
</div>
</div>
<div class="flex item-center space-x-2">
<FormControl
v-model="search"
:placeholder="__('Search')"
type="text"
:debounce="300"
/>
<Button @click="() => (showForm = true)">
<template #icon>
<Plus class="h-3 w-3 stroke-1.5" />
</template>
</Button>
</div>
</div>
<div class="my-4">
<!-- Form to add new member -->
<div v-if="showForm" class="flex items-center space-x-2 mb-4">
<FormControl
v-model="member.email"
:placeholder="__('Email')"
type="email"
class="w-full"
/>
<FormControl
v-model="member.first_name"
:placeholder="__('First Name')"
type="test"
class="w-full"
/>
<Button @click="addMember()" variant="subtle">
{{ __('Add') }}
</Button>
</div>

<!-- Member list -->
<div
v-for="member in memberList"
class="grid grid-cols-5 grid-flow-row py-2 cursor-pointer"
>
<div
@click="openProfile(member.username)"
class="flex items-center space-x-2 col-span-2"
>
<Avatar
:image="member.user_image"
:label="member.full_name"
size="sm"
/>
<div>
{{ member.full_name }}
</div>
</div>
<div class="text-sm text-gray-700 col-span-2">
{{ member.name }}
</div>
<div class="text-sm text-gray-700 justify-self-end">
{{ getRole(member.role) }}
</div>
</div>
</div>
<div v-if="hasNextPage" class="flex justify-center">
<Button variant="solid" @click="members.reload()">
<template #prefix>
<RefreshCw class="h-3 w-3 stroke-1.5" />
</template>
{{ __('Load More') }}
</Button>
</div>
</div>
</template>
<script setup lang="ts">
import { createResource, Avatar, Button, FormControl } from 'frappe-ui'
import { useRouter } from 'vue-router'
import { ref, watch, reactive } from 'vue'
import { RefreshCw, Plus } from 'lucide-vue-next'
const router = useRouter()
const show = defineModel('show')
const search = ref('')
const start = ref(0)
const memberList = ref([])
const hasNextPage = ref(false)
const showForm = ref(false)
const member = reactive({
email: '',
first_name: '',
})
const props = defineProps({
label: {
type: String,
required: true,
},
description: {
type: String,
default: '',
},
show: {
type: Boolean,
},
})
const members = createResource({
url: 'lms.lms.api.get_members',
makeParams: () => {
return {
search: search.value,
start: start.value,
}
},
onSuccess(data) {
memberList.value = memberList.value.concat(data)
start.value = start.value + 20
hasNextPage.value = data.length === 20
},
auto: true,
})
const openProfile = (username) => {
show.value = false
router.push({
name: 'Profile',
params: {
username: username,
},
})
}
const newMember = createResource({
url: 'frappe.client.insert',
makeParams(values) {
return {
doc: {
doctype: 'User',
first_name: member.first_name,
email: member.email,
},
}
},
auto: false,
onSuccess(data) {
show.value = false
router.push({
name: 'Profile',
params: {
username: data.username,
},
})
},
})
const addMember = () => {
newMember.reload()
}
watch(search, () => {
memberList.value = []
start.value = 0
members.reload()
})
const getRole = (role) => {
const map = {
'LMS Student': 'Student',
'Course Creator': 'Instructor',
Moderator: 'Moderator',
'Batch Evaluator': 'Evaluator',
}
return map[role]
}
</script>
40 changes: 25 additions & 15 deletions frontend/src/components/Modals/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,21 @@
</nav>
</div>
</div>
<div class="flex flex-1 flex-col overflow-y-auto">
<div
v-if="activeTab && data.doc"
class="flex flex-1 flex-col overflow-y-auto"
>
<Members
v-if="activeTab.label === 'Members'"
:label="activeTab.label"
:description="activeTab.description"
v-model:show="show"
/>
<SettingDetails
v-if="activeTab && data.doc"
v-else
:fields="activeTab.fields"
:label="activeTab.label"
:description="activeTab.description"
:data="data"
/>
</div>
Expand All @@ -44,6 +55,7 @@ import { Dialog, createDocumentResource } from 'frappe-ui'
import { ref, computed, watch } from 'vue'
import SettingDetails from '../SettingDetails.vue'
import SidebarLink from '@/components/SidebarLink.vue'
import Members from '@/components/Members.vue'
const show = defineModel()
const doctype = ref('LMS Settings')
Expand All @@ -63,9 +75,16 @@ const tabs = computed(() => {
label: 'Settings',
hideLabel: true,
items: [
{
label: 'Members',
description: 'Manage the members of your learning system',
icon: 'UserRoundPlus',
},
{
label: 'Payment Gateway',
icon: 'DollarSign',
description:
'Configure the payment gateway and other payment related settings',
fields: [
{
label: 'Razorpay Key',
Expand Down Expand Up @@ -112,6 +131,7 @@ const tabs = computed(() => {
{
label: 'Sidebar',
icon: 'PanelLeftIcon',
description: 'Customize the sidebar as per your needs',
fields: [
{
label: 'Courses',
Expand Down Expand Up @@ -157,6 +177,7 @@ const tabs = computed(() => {
{
label: 'Email Templates',
icon: 'MailPlus',
description: 'Create email templates with the content you want',
fields: [
{
label: 'Batch Confirmation Template',
Expand Down Expand Up @@ -187,6 +208,8 @@ const tabs = computed(() => {
{
label: 'Signup',
icon: 'LogIn',
description:
'Customize the signup page to inform users about your terms and policies',
fields: [
{
label: 'Show terms of use on signup',
Expand All @@ -210,11 +233,9 @@ const tabs = computed(() => {
type: 'Link',
doctype: 'Web Page',
},
{
type: 'Column Break',
},
{
label: 'Show cookie policy on signup',
name: 'cookie_policy',
Expand All @@ -235,17 +256,6 @@ const tabs = computed(() => {
},
],
},
/* {
label: 'Settings',
hideLabel: true,
items: [
{
label: 'Members',
icon: "UserRoundPlus",
component: markRaw(MemberSettings),
},
],
}, */
]
return _tabs.map((tab) => {
Expand Down
19 changes: 17 additions & 2 deletions frontend/src/components/SettingDetails.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
<template>
<div class="flex flex-col justify-between h-full p-8">
<div class="flex space-x-8">
<div class="flex flex-col justify-between h-full p-4">
<div>
<div class="font-semibold mb-1">
{{ __(label) }}
</div>
<div class="text-xs text-gray-600">
{{ __(description) }}
</div>
</div>
<div class="flex space-x-8 my-5">
<div v-for="(column, index) in columns" :key="index">
<div class="flex flex-col space-y-4 w-60">
<div v-for="field in column">
Expand Down Expand Up @@ -43,6 +51,13 @@ const props = defineProps({
type: Object,
required: true,
},
label: {
type: String,
required: true,
},
description: {
type: String,
},
})
const columns = computed(() => {
Expand Down
35 changes: 35 additions & 0 deletions lms/lms/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,3 +562,38 @@ def get_categories(doctype, filters):
categoryOptions.append({"label": category, "value": category})

return categoryOptions


@frappe.whitelist()
def get_members(start=0, search=""):
"""Get members for the given search term and start index.
Args: start (int): Start index for the query.
search (str): Search term to filter the results.
Returns: List of members.
"""

filters = {"enabled": 1, "name": ["not in", ["Administrator", "Guest"]]}

if search:
filters["full_name"] = ["like", f"%{search}%"]

members = frappe.get_all(
"User",
filters=filters,
fields=["name", "full_name", "user_image", "username"],
page_length=20,
start=start,
)

for member in members:
roles = frappe.get_roles(member.name)
if "Moderator" in roles:
member.role = "Moderator"
elif "Course Creator" in roles:
member.role = "Course Creator"
elif "Batch Evaluator" in roles:
member.role = "Batch Evaluator"
elif "LMS Student" in roles:
member.role = "LMS Student"

return members
Loading

0 comments on commit e69cc9a

Please sign in to comment.