Skip to content

Commit

Permalink
Merge pull request #1959 from slntopp/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
SazukinPavel authored Jan 14, 2025
2 parents 51c88ff + 783396a commit 8585ff7
Show file tree
Hide file tree
Showing 13 changed files with 288 additions and 37 deletions.
2 changes: 1 addition & 1 deletion admin-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"jodit-vue": "^2.6.0",
"js-cookie": "^3.0.5",
"json-schema": "^0.4.0",
"nocloud-proto": "https://github.com/slntopp/nocloud-proto#7e286b620c82aeb0b1b43889d4b7eb67d5bc1410",
"nocloud-proto": "https://github.com/slntopp/nocloud-proto#36f115ce6bf0d0c2615c2c00e970df0c7e450882",
"nocloud-ui": "^1.0.16",
"nocloudjsrest": "^1.5.17",
"nth-check": "^2.1.1",
Expand Down
24 changes: 17 additions & 7 deletions admin-ui/src/components/ServicesProvider/info.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,7 @@
<plans-table
no-search
show-select
:custom-params="{
showDeleted: false,
excludeUuids: relatedPlans?.map((p) => p.uuid) || [],
filters: {
type: [provider.type],
},
}"
:custom-params="plansParams"
table-name="plans-sp-table"
v-model="selectedNewPlans"
:plans="plans"
Expand Down Expand Up @@ -223,6 +217,22 @@ const fetchSelectedPlans = async () => {
}
};
const plansParams = computed(() => {
const type = [provider.value.type];
if (provider.value.type === "ione") {
type.push("ione-vpn");
}
return {
showDeleted: false,
excludeUuids: relatedPlans.value?.map((p) => p.uuid) || [],
filters: {
type,
},
};
});
const spTypes = computed(() => {
switch (provider.value.type) {
case "ione":
Expand Down
2 changes: 1 addition & 1 deletion admin-ui/src/components/ui/antIcon.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default {
} else if (displayName.endsWith("Filled")) {
displayName = displayName.replace("Filled", "Fill");
}
const [name, icon] = Object.entries(iconsRes).find(
const [name, icon] = Object.entries(iconsRes)?.find(
([name]) => name === displayName
);
this.icon = { name, ...icon };
Expand Down
2 changes: 1 addition & 1 deletion admin-ui/src/views/PlanPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export default {
title: "Info",
component: () => import("@/views/PlansCreate.vue"),
},
this.plan?.type === "ione" && {
["ione", "ione-vpn"].includes(this.plan?.type) && {
title: "Configuration",
component: () =>
import("@/components/modules/ione/planConfiguration.vue"),
Expand Down
22 changes: 21 additions & 1 deletion admin-ui/src/views/PlansCreate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,14 @@ export default {
if (matched && matched.length > 1) {
if (matched[1] === "ovh") {
this.types.push("ovh vps", "ovh dedicated", "ovh cloud");
}
if (matched[1] === "ione") {
this.types.push("ione", "ione-vpn",);
}
if (matched[1] === "empty") {
this.types.push("empty", "vpn");
} else {
this.types.push(matched[1]);
}
Expand Down Expand Up @@ -570,6 +578,8 @@ export default {
case "ovh cloud":
case "opensrs":
case "empty":
case "vpn":
case "ione-vpn":
case "cpanel": {
allowed.push("STATIC");
break;
Expand All @@ -583,9 +593,19 @@ export default {
},
typedSp() {
return this.$store.getters["servicesProviders/all"].filter(
(sp) => sp.type == this.plan.type.split(" ")[0]
(sp) => sp.type == this.spType
);
},
spType() {
if (this.plan.type == "vpn") {
return "empty";
}
if (this.plan.type == "ione-vpn") {
return "ione";
}
return this.plan.type.split(" ")[0];
},
isDeleted() {
return this.plan.status === "DEL";
},
Expand Down
54 changes: 39 additions & 15 deletions admin-ui/src/views/ShowcaseCreate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@
<v-switch label="Is primary" v-model="showcase.primary" />
<v-switch label="Enabled" v-model="showcase.public" />
</v-col>
<v-col cols="6">
<v-col cols="3">
<icons-autocomplete
label="Preview icon"
:value="showcase.icon"
@input:value="showcase.icon = $event"
/>
</v-col>
<v-col cols="6">
<v-col cols="3">
<v-autocomplete
clearable
item-text="title"
Expand All @@ -45,6 +45,10 @@
:items="allLocations"
/>
</v-col>

<v-col cols="2">
<v-select v-model="showcase.meta.type" label="Type" :items="types" />
</v-col>
</v-row>

<v-expansion-panels :value="0">
Expand Down Expand Up @@ -97,7 +101,8 @@
<locations-autocomplete
label="Locations"
v-model="item.locations"
:locations="filteredLocations[i]"
:loading="isPlansLoading"
:locations="isPlansLoading ? [] : filteredLocations[i]"
/>
</v-col>
</v-row>
Expand Down Expand Up @@ -128,13 +133,23 @@ const props = defineProps({
realShowcase: {},
isEdit: { type: Boolean, default: false },
});
// const emits=defineEmits(['input'])
const { realShowcase, isEdit } = toRefs(props);
const store = useStore();
const router = useRouter();
const types = [
"cloud",
"custom",
"virtual",
"openai",
"vpn",
"ione-vpn",
"domains",
"acronis",
"ssl",
];
const showcase = ref({
primary: false,
title: "",
Expand All @@ -150,6 +165,9 @@ const showcase = ref({
promo: {},
locations: [],
public: true,
meta: {
type: "",
},
});
const currentLang = ref("en");
Expand All @@ -168,7 +186,7 @@ const serviceProviders = computed(() => store.getters["servicesProviders/all"]);
const locations = computed(() =>
showcase.value.items.reduce((result, { servicesProvider }, i) => {
const { uuid, locations = [] } =
serviceProviders.value.find((sp) => sp.uuid === servicesProvider) ?? {};
serviceProviders.value?.find((sp) => sp.uuid === servicesProvider) ?? {};
return {
...result,
Expand All @@ -182,8 +200,8 @@ const locations = computed(() =>
);
const filteredLocations = computed(() => {
if(isPlansLoading.value || isLoading.value){
return {}
if (isPlansLoading.value || isLoading.value) {
return {};
}
const result = {};
Expand All @@ -195,7 +213,7 @@ const filteredLocations = computed(() => {
);
if (!plan) return;
result[i] = value.filter(({ type }) => plan.type === type);
result[i] = value.filter(({ type }) => plan.type.split("-")[0] === type);
});
return result;
Expand All @@ -206,7 +224,7 @@ const allLocations = computed(() =>
(result, [i, locations]) => [
...result,
...locations.filter(({ id }) =>
showcase.value.items[i].locations.find(
showcase.value.items[i].locations?.find(
(location) => id === (location.id ?? location)
)
),
Expand All @@ -220,6 +238,10 @@ watch(realShowcase, () => {
showcase.value = JSON.parse(JSON.stringify(realShowcase.value));
showcase.value.newTitle = showcase.value.title;
if (!showcase.value.meta) {
showcase.value.meta = {};
}
if (!Array.isArray(showcase.value.items)) {
showcase.value.items = [];
}
Expand Down Expand Up @@ -253,7 +275,7 @@ const save = async () => {
const item = data.items[i];
const locs = value
.filter(({ id }) =>
item.locations.find((location) => (location.id ?? location) === id)
item.locations?.find((location) => (location.id ?? location) === id)
)
.map((location) => ({
...location,
Expand All @@ -265,7 +287,7 @@ const save = async () => {
}));
locs.forEach((location) => {
if (!data.locations.find(({ id }) => id === location.id)) {
if (!data.locations?.find(({ id }) => id === location.id)) {
data.locations.push(location);
}
});
Expand Down Expand Up @@ -326,7 +348,7 @@ const getPlan = (sp, uuid) => {
const plans = plansBySpMap.value.get(sp) ?? [];
if (Array.isArray(plans)) {
return plans.find((plan) => plan.uuid === uuid);
return plans?.find((plan) => plan.uuid === uuid);
}
};
Expand All @@ -339,7 +361,7 @@ const getPlans = (sp) => {
const getProviderTitle = (uuid) => {
return (
serviceProviders.value.find((provider) => provider.uuid === uuid)?.title ??
serviceProviders.value?.find((provider) => provider.uuid === uuid)?.title ??
uuid
);
};
Expand Down Expand Up @@ -368,7 +390,9 @@ const fetchPlans = async () => {
})
);
} finally {
isPlansLoading.value = false;
setTimeout(() => {
isPlansLoading.value = false;
}, 100);
}
};
Expand Down
2 changes: 1 addition & 1 deletion admin-ui/src/views/ShowcasePage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ onMounted(async () => {
isFetchLoading.value = false;
}
showcase.value = showcases.value.find((n) => n.uuid == showcaseId.value);
showcase.value = showcases.value?.find((n) => n.uuid == showcaseId.value);
document.title = `${showcase.value.title} | NoCloud`;
});
</script>
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0
github.com/rabbitmq/amqp091-go v1.9.0
github.com/rs/cors v1.10.1
github.com/slntopp/nocloud-proto v0.0.0-20241226123624-36f115ce6bf0
github.com/slntopp/nocloud-proto v0.0.0-20250111091130-cef7b71e8db5
github.com/spf13/viper v1.18.2
github.com/stoewer/go-strcase v1.3.0
github.com/stretchr/testify v1.8.4
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6Mwd
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/slntopp/nocloud-proto v0.0.0-20241226123624-36f115ce6bf0 h1:G0cFfUU8f2gR3Tdeq0TIdf+R/ZW5Woup/P7kOAlOXss=
github.com/slntopp/nocloud-proto v0.0.0-20241226123624-36f115ce6bf0/go.mod h1:qPbslPB2J9Q7qm6H9Jaqf/Ysf61YlPL0DUFhIdAEikI=
github.com/slntopp/nocloud-proto v0.0.0-20250111091130-cef7b71e8db5 h1:YER/mdWPB5BpwGxCtFo5uyhN2cD7bULscXen/MXggtc=
github.com/slntopp/nocloud-proto v0.0.0-20250111091130-cef7b71e8db5/go.mod h1:qPbslPB2J9Q7qm6H9Jaqf/Ysf61YlPL0DUFhIdAEikI=
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0=
github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8=
Expand Down
4 changes: 4 additions & 0 deletions pkg/billing/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,10 @@ func (s *BillingServiceServer) ProcessInstanceCreation(log *zap.Logger, ctx cont
return fmt.Errorf("failed getting exchange rate: %w", err)
}
initCost, _ := s.instances.CalculateInstanceEstimatePrice(instance.Instance, true)
if initCost <= 0 {
log.Info("Skipping creation of 0 invoice for instance with 0 price")
return nil
}
_, summary, err := s.promocodes.GetDiscountPriceByInstance(instance.Instance, true)
if err != nil {
log.Error("Failed to calculate instance cost", zap.Error(err))
Expand Down
9 changes: 9 additions & 0 deletions pkg/billing/invoices.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,15 @@ func (s *BillingServiceServer) CreateInvoice(ctx context.Context, req *connect.R
Requestor: requester,
})

if t.Total <= 0 {
if _, err = s.UpdateInvoiceStatus(ctx, connect.NewRequest(&pb.UpdateInvoiceStatusRequest{
Uuid: r.GetUuid(),
Status: pb.BillingStatus_PAID,
})); err != nil {
log.Error("Failed to auto-pay 0 or less total invoice", zap.Error(err))
}
}

resp := connect.NewResponse(r.Invoice)
return resp, nil
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/eventbus/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package eventbus

import (
"context"
"fmt"
"github.com/slntopp/nocloud/pkg/nocloud/rabbitmq"
"github.com/spf13/viper"
"google.golang.org/protobuf/proto"
Expand Down Expand Up @@ -107,7 +108,11 @@ func (s *EventBusServer) HandleEventOverride(log *zap.Logger, event *pb.Event) (
log.Debug("Custom events", zap.Any("events", customEvents))

for _, ce := range customEvents {

if ce.Override == event.Key {
if ce.Key == "-" {
return nil, fmt.Errorf("event cancelled by override")
}
log.Debug("Event override", zap.Any("old_key", event.Key), zap.Any("new_key", ce.Override))
event.Key = ce.Key
return event, nil
Expand Down
Loading

0 comments on commit 8585ff7

Please sign in to comment.