Skip to content

Commit

Permalink
implement role assignment on sso user signups and log ip for sso logins
Browse files Browse the repository at this point in the history
  • Loading branch information
sadnub committed Oct 8, 2024
1 parent 8c56cf5 commit e8332db
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 4 deletions.
26 changes: 25 additions & 1 deletion src/composables/accounts.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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,
};
}
3 changes: 1 addition & 2 deletions src/ee/sso/api/sso.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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,
Expand Down
24 changes: 23 additions & 1 deletion src/ee/sso/components/SSOProvidersForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]);
Expand All @@ -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({
Expand All @@ -100,6 +121,7 @@ const localProvider: SSOProvider = props.provider
client_id: "",
secret: "",
server_url: "",
role: null,
} as SSOProvider);

async function submit() {
Expand Down
1 change: 1 addition & 0 deletions src/ee/sso/components/SSOProvidersTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ For details, see: https://license.tacticalrmm.com/ee
"
no-caps
color="primary"
size="sm"
/>
</template>
<!-- body slots -->
Expand Down
1 change: 1 addition & 0 deletions src/ee/sso/types/sso.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface SSOProvider {
client_id: string;
secret: string;
server_url: string;
role: number | null;
}

export interface SSOAccount {
Expand Down

0 comments on commit e8332db

Please sign in to comment.