iobroker.time-tracker 0.4.1 → 0.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -813,7 +813,7 @@ function createApi(deps) {
813
813
  });
814
814
  });
815
815
  route("POST", "/absences", { permission: "absence.request", csrf: true }, (context) => {
816
- var _a2, _b2, _c2, _d2, _e;
816
+ var _a2, _b2, _c2, _d2, _e, _f, _g;
817
817
  if (!context.auth) {
818
818
  throw (0, import_problem.problem)(401, "no_session", "request rejected (no_session)");
819
819
  }
@@ -825,19 +825,35 @@ function createApi(deps) {
825
825
  }
826
826
  const mayDecide = context.auth.permissions.includes("absence.edit_other");
827
827
  const approval = mayDecide ? "approved" : "requested";
828
+ if (!mayDecide) {
829
+ const wanted = absences.findType(
830
+ (_b2 = (_a2 = optionalNumber(body, "typeId")) != null ? _a2 : optionalString(body, "typeCode")) != null ? _b2 : "",
831
+ userId
832
+ );
833
+ if (!wanted) {
834
+ throw new import_errors.ValidationError("unknown absence type");
835
+ }
836
+ if (!wanted.isActive) {
837
+ throw (0, import_problem.problem)(
838
+ 403,
839
+ "permission_denied",
840
+ "request rejected (permission_denied: absence type is not public)"
841
+ );
842
+ }
843
+ }
828
844
  const created = absences.create({
829
845
  userId,
830
- typeCode: (_a2 = optionalString(body, "typeCode")) != null ? _a2 : void 0,
831
- typeId: (_b2 = optionalNumber(body, "typeId")) != null ? _b2 : void 0,
846
+ typeCode: (_c2 = optionalString(body, "typeCode")) != null ? _c2 : void 0,
847
+ typeId: (_d2 = optionalNumber(body, "typeId")) != null ? _d2 : void 0,
832
848
  dateFrom: requireString(body, "dateFrom"),
833
- dateTo: (_c2 = optionalString(body, "dateTo")) != null ? _c2 : void 0,
834
- dayPortion: (_d2 = optionalNumber(body, "dayPortion")) != null ? _d2 : void 0,
849
+ dateTo: (_e = optionalString(body, "dateTo")) != null ? _e : void 0,
850
+ dayPortion: (_f = optionalNumber(body, "dayPortion")) != null ? _f : void 0,
835
851
  hours: optionalNumber(body, "hours"),
836
852
  status: status != null ? status : void 0,
837
853
  approval,
838
854
  note: optionalString(body, "note"),
839
855
  actorId: context.auth.user.id,
840
- actorIp: (_e = context.request.remoteAddress) != null ? _e : null,
856
+ actorIp: (_g = context.request.remoteAddress) != null ? _g : null,
841
857
  now: now()
842
858
  });
843
859
  emit({ type: "absence.change", userId, data: { absenceId: created.id, action: "created" } });
@@ -897,7 +913,7 @@ function createApi(deps) {
897
913
  return absence;
898
914
  };
899
915
  route("PATCH", "/absences/:id", { permission: "absence.request", csrf: true }, (context) => {
900
- var _a2, _b2, _c2, _d2, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
916
+ var _a2, _b2, _c2, _d2, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
901
917
  const absence = changeableAbsence(context);
902
918
  const body = context.jsonBody();
903
919
  const status = optionalString(body, "status");
@@ -917,12 +933,25 @@ function createApi(deps) {
917
933
  ...Object.prototype.hasOwnProperty.call(body, "note") ? { note: optionalString(body, "note") } : {}
918
934
  };
919
935
  const hasFields = Object.values(patch).some((value) => value !== void 0);
936
+ if (hasFields && !((_g = context.auth) == null ? void 0 : _g.permissions.includes("absence.edit_other")) && (patch.typeId !== void 0 || patch.typeCode !== void 0)) {
937
+ const wanted = absences.findType((_i = (_h = patch.typeId) != null ? _h : patch.typeCode) != null ? _i : "", absence.userId);
938
+ if (!wanted) {
939
+ throw new import_errors.ValidationError("unknown absence type");
940
+ }
941
+ if (!wanted.isActive) {
942
+ throw (0, import_problem.problem)(
943
+ 403,
944
+ "permission_denied",
945
+ "request rejected (permission_denied: absence type is not public)"
946
+ );
947
+ }
948
+ }
920
949
  if (status !== null) {
921
950
  absences.setStatus({
922
951
  id: absence.id,
923
952
  status,
924
- actorId: (_h = (_g = context.auth) == null ? void 0 : _g.user.id) != null ? _h : 0,
925
- actorIp: (_i = context.request.remoteAddress) != null ? _i : null,
953
+ actorId: (_k = (_j = context.auth) == null ? void 0 : _j.user.id) != null ? _k : 0,
954
+ actorIp: (_l = context.request.remoteAddress) != null ? _l : null,
926
955
  now: now()
927
956
  });
928
957
  }
@@ -930,16 +959,16 @@ function createApi(deps) {
930
959
  id: absence.id,
931
960
  patch,
932
961
  reason: optionalString(body, "reason"),
933
- actorId: (_k = (_j = context.auth) == null ? void 0 : _j.user.id) != null ? _k : 0,
934
- actorIp: (_l = context.request.remoteAddress) != null ? _l : null,
962
+ actorId: (_n = (_m = context.auth) == null ? void 0 : _m.user.id) != null ? _n : 0,
963
+ actorIp: (_o = context.request.remoteAddress) != null ? _o : null,
935
964
  now: now()
936
- }) : (_m = absences.findById(absence.id)) != null ? _m : absence;
937
- const updated = hasFields && !((_n = context.auth) == null ? void 0 : _n.permissions.includes("absence.edit_other")) && changed.approval !== "requested" ? absences.setApproval({
965
+ }) : (_p = absences.findById(absence.id)) != null ? _p : absence;
966
+ const updated = hasFields && !((_q = context.auth) == null ? void 0 : _q.permissions.includes("absence.edit_other")) && changed.approval !== "requested" ? absences.setApproval({
938
967
  id: changed.id,
939
968
  approval: "requested",
940
969
  note: null,
941
- actorId: (_p = (_o = context.auth) == null ? void 0 : _o.user.id) != null ? _p : 0,
942
- actorIp: (_q = context.request.remoteAddress) != null ? _q : null,
970
+ actorId: (_s = (_r = context.auth) == null ? void 0 : _r.user.id) != null ? _s : 0,
971
+ actorIp: (_t = context.request.remoteAddress) != null ? _t : null,
943
972
  now: now()
944
973
  }) : changed;
945
974
  emit({ type: "absence.change", userId: updated.userId, data: { absenceId: updated.id, action: "updated" } });
@@ -960,15 +989,13 @@ function createApi(deps) {
960
989
  emit({ type: "absence.change", userId: absence.userId, data: { absenceId: absence.id, action: "deleted" } });
961
990
  return (0, import_router.noContent)();
962
991
  });
963
- route(
964
- "GET",
965
- "/absence-types",
966
- {},
967
- (context) => {
968
- var _a2, _b2;
969
- return (0, import_router.json)(200, { types: absences.types({ userId: (_b2 = (_a2 = context.auth) == null ? void 0 : _a2.user.id) != null ? _b2 : null }) });
970
- }
971
- );
992
+ route("GET", "/absence-types", {}, (context) => {
993
+ var _a2, _b2, _c2, _d2;
994
+ const includeInactive = context.query("includeInactive") === "true" && ((_b2 = (_a2 = context.auth) == null ? void 0 : _a2.permissions.includes("absence.manage_types")) != null ? _b2 : false);
995
+ return (0, import_router.json)(200, {
996
+ types: absences.types({ userId: (_d2 = (_c2 = context.auth) == null ? void 0 : _c2.user.id) != null ? _d2 : null, includeInactive })
997
+ });
998
+ });
972
999
  route("POST", "/absence-types", { permission: "absence.manage_types", csrf: true }, (context) => {
973
1000
  var _a2, _b2, _c2, _d2, _e;
974
1001
  if (!context.auth) {
@@ -989,6 +1016,22 @@ function createApi(deps) {
989
1016
  });
990
1017
  return (0, import_router.json)(result.created ? 201 : 200, { type: result.type, created: result.created });
991
1018
  });
1019
+ route("DELETE", "/absence-types/:id", { permission: "absence.manage_types", csrf: true }, (context) => {
1020
+ var _a2;
1021
+ if (!context.auth) {
1022
+ throw (0, import_problem.problem)(401, "no_session", "request rejected (no_session)");
1023
+ }
1024
+ const removed = absences.removeType({
1025
+ id: numberParam(context, "id"),
1026
+ actorId: context.auth.user.id,
1027
+ actorIp: (_a2 = context.request.remoteAddress) != null ? _a2 : null,
1028
+ now: now()
1029
+ });
1030
+ if (!removed) {
1031
+ throw new import_errors.NotFoundError(`absence type ${context.params.id} not found`);
1032
+ }
1033
+ return (0, import_router.noContent)();
1034
+ });
992
1035
  route("GET", "/holidays", { permission: "report.view_own" }, (context) => {
993
1036
  var _a2;
994
1037
  const year = numberQuery(context, "year");