implement role assignment on sso user signups and log ip for sso logins

This commit is contained in:
sadnub
2024-10-08 07:21:44 -04:00
committed by wh1te909
parent c31ed666b5
commit 65096e6b88
5 changed files with 51 additions and 4 deletions

View File

@@ -1,5 +1,5 @@
import { ref, onMounted } from "vue";
import { fetchUsers } from "@/api/accounts";
import { fetchUsers, fetchRoles } from "@/api/accounts";
import { formatUserOptions } from "@/utils/format";
export function useUserDropdown(onMount = false) {
@@ -44,3 +44,27 @@ export function useUserDropdown(onMount = false) {
getDynamicUserOptions,
};
}
export function useRoleDropdown(opts = {}) {
const roleOptions = ref([]);
async function getRoleOptions() {
const roles = await fetchRoles();
console.log(roles);
roleOptions.value = roles.map((role) => ({
value: role.id,
label: role.name,
}));
}
if (opts.onMount) {
onMounted(getRoleOptions);
}
return {
//data
roleOptions,
//methods
getRoleOptions,
};
}

View File

@@ -36,7 +36,7 @@ function postForm(url: string, data: FormData) {
// sso providers
export async function fetchSSOProviders(): Promise<SSOProvider> {
export async function fetchSSOProviders(): Promise<SSOProvider[]> {
const { data } = await axios.get(`${baseUrl}/ssoproviders/`);
return data;
}
@@ -66,7 +66,6 @@ export async function fetchSSOSettings(): Promise<SSOSettings> {
}
export async function updateSSOSettings(settings: SSOSettings) {
console.log(settings);
const { data } = await axios.post(
`${baseUrl}/ssoproviders/settings/`,
settings,

View File

@@ -60,6 +60,19 @@ For details, see: https://license.tacticalrmm.com/ee
/>
</q-card-section>
<q-card-section>
<tactical-dropdown
label="Default Role"
:options="roleOptions"
outlined
dense
clearable
mapOptions
filled
v-model="localProvider.role"
/>
</q-card-section>
<q-card-actions align="right">
<q-btn flat label="Cancel" v-close-popup />
<q-btn
@@ -80,7 +93,13 @@ import { ref, reactive } from "vue";
import { useDialogPluginComponent, extend } from "quasar";
import { editSSOProvider, addSSOProvider } from "@/ee/sso/api/sso";
import { notifySuccess } from "@/utils/notify";
import { SSOProvider } from "@/types/accounts";
import { useRoleDropdown } from "@/composables/accounts";
// components
import TacticalDropdown from "@/components/ui/TacticalDropdown.vue";
// types
import type { SSOProvider } from "@/ee/sso/types/sso";
// define emits
defineEmits([...useDialogPluginComponent.emits]);
@@ -92,6 +111,8 @@ const { dialogRef, onDialogHide, onDialogOK } = useDialogPluginComponent();
const loading = ref(false);
const { roleOptions } = useRoleDropdown({ onMount: true });
const localProvider: SSOProvider = props.provider
? reactive(extend({}, props.provider))
: reactive({
@@ -100,6 +121,7 @@ const localProvider: SSOProvider = props.provider
client_id: "",
secret: "",
server_url: "",
role: null,
} as SSOProvider);
async function submit() {

View File

@@ -47,6 +47,7 @@ For details, see: https://license.tacticalrmm.com/ee
"
no-caps
color="primary"
size="sm"
/>
</template>
<!-- body slots -->

View File

@@ -12,6 +12,7 @@ export interface SSOProvider {
client_id: string;
secret: string;
server_url: string;
role: number | null;
}
export interface SSOAccount {