Пример #1
0
func Delete(c *echo.Context) error {
	userId := c.Param("id")
	if len(userId) == 0 {
		return c.JSON(http.StatusBadRequest, hash{
			"error": [1]hash{
				hash{
					"detail": "User id needed for deletion",
				},
			},
		})
	}

	user, err := users.GetUser(userId)
	if err != nil {
		return err
	}

	if user == nil {
		return c.JSON(http.StatusNotFound, hash{
			"error": [1]hash{
				hash{
					"detail": "User not found",
				},
			},
		})
	}

	if user.IsAdmin {
		return c.JSON(http.StatusUnauthorized, hash{
			"error": [1]hash{
				hash{
					"detail": "Admins cannot be deleted",
				},
			},
		})
	}

	err = users.DeleteUser(user.Id)
	if err != nil {
		log.Errorf("Unable to delete user: "******"meta": hash{},
	})
}
Пример #2
0
func TestFindAll(t *testing.T) {
	var expected_num_rows int = history_num

	startDate = append(startDate, time.Now().Format(time.RFC3339))
	endDate = append(endDate, time.Now().Format(time.RFC3339))
	_, err := CreateHistory(user.GetID(), user.Email, user.FirstName, user.LastName, connectionId, startDate[history_num], endDate[history_num])
	if err != nil {
		log.Panicln("Can't add historic:", err.Error())
	}

	if total-expected_num_rows+1 != 0 {
		t.Errorf("Unexpected number of rows returned: Expected %d, have %d", expected_num_rows+1, total)
	}

	err = users.DeleteUser(user.GetID())
	if err != nil {
		t.Errorf("Can't delete user: %s\n", err.Error())
	}
}
Пример #3
0
func TestGetUserApps(t *testing.T) {
	id = uuid.NewV4().String()
	new_app := &App{Id: id, CollectionName: collectionName, Alias: "Libre Office", DisplayName: displayName, FilePath: filePath}
	i := 0

	new_app, err := CreateApp(new_app)
	if err != nil {
		log.Fatalln("Cannot create the app:", err.Error())
	}
	list_apps = append(list_apps, new_app)
	app_num++

	apps, err := GetUserApps(user.GetID())
	if err != nil {
		t.Error("Unable to get user apps")
	}

	for _, get_app := range apps {
		if get_app == nil {
			t.Error("A nil app was returned")
		}
		if get_app.Alias != "hapticDesktop" {
			compareApp(get_app, i)
			err = get_app.Delete()
			if err != nil {
				log.Fatalln("Can't delete application:", err.Error())
			}
			i++
		}
	}

	err = users.DeleteUser(user.GetID())
	if err != nil {
		t.Errorf("Can't delete user: %s\n", err.Error())
	}
}
Пример #4
0
func Delete(c *echo.Context) error {
	userId := c.Param("id")
	if len(userId) == 0 {
		return c.JSON(http.StatusBadRequest, hash{
			"error": [1]hash{
				hash{
					"detail": "User id needed for deletion",
				},
			},
		})
	}

	user, err := users.GetUser(userId)
	if err != nil {
		return err
	}

	if user == nil {
		return c.JSON(http.StatusNotFound, hash{
			"error": [1]hash{
				hash{
					"detail": "User not found",
				},
			},
		})
	}

	if user.IsAdmin {
		return c.JSON(http.StatusUnauthorized, hash{
			"error": [1]hash{
				hash{
					"detail": "Admins cannot be deleted",
				},
			},
		})
	}

	err = ldap.DeleteAccount(user.Id)
	if err != nil {
		log.Errorf("Unable to delete user in ad: %s", err.Error())
		switch err {
		case ldap.DeleteFailed:
			return c.JSON(http.StatusInternalServerError, hash{
				"error": [1]hash{
					hash{
						"detail": err.Error(),
					},
				},
			})
		case ldap.UnknownUser:
			log.Info("User doesn't exist in AD")
			break
		default:
			return err
		}
	}

	err = users.DeleteUser(user.Id)
	if err != nil {
		log.Errorf("Unable to delete user: "******"data": hash{
			"success": true,
		},
	})
}