<commit_before>package streamdb

import (
	"errors"
	"streamdb/users"
)

/*
These functions allow Database to conform to the Operator interface
*/

var (
	//ErrAdmin is thrown when trying to get the user or device of the Admin operator
	ErrAdmin = errors.New("An administrative operator has no user or device")

	//ErrNotChangeable is thrown when changing a field that can't be changed
	ErrNotChangeable = errors.New("The given fields are not modifiable.")
)

//User returns the current user
func (o *Database) User() (usr *users.User, err error) {
	return nil, ErrAdmin
}

//Device returns the current device
func (o *Database) Device() (*users.Device, error) {
	return nil, ErrAdmin
}

//Permissions returns whether the operator has permissions given by the string
func (o *Database) Permissions(perm users.PermissionLevel) bool {
	return true
}

//The following functions are direct mirrors of Userdb

//CreateUser makes a new user
func (o *Database) CreateUser(username, email, password string) error {
	return o.Userdb.CreateUser(username, email, password)
}

//ReadAllUsers reads all the users
func (o *Database) ReadAllUsers() ([]users.User, error) {
	return o.Userdb.ReadAllUsers()
}

//ReadUser reads a user - or rather reads any user that this device has permissions to read
func (o *Database) ReadUser(username string) (*users.User, error) {
	return o.Userdb.ReadUserByName(username)
}

//ReadUserByEmail reads a user - or rather reads any user that this device has permissions to read
func (o *Database) ReadUserByEmail(email string) (*users.User, error) {
	return o.Userdb.ReadUserByEmail(email)
}

//DeleteUser deletes the given user - only admin can delete
func (o *Database) DeleteUser(username string) error {
	return o.Userdb.DeleteUserByName(username)
}

//UpdateUser performs the given modifications
func (o *Database) UpdateUser(user *users.User, modifieduser users.User) error {
	if modifieduser.RevertUneditableFields(*user, users.ROOT) > 0 {
		return ErrNotChangeable
	}

	return o.Userdb.UpdateUser(&modifieduser)
}

//SetAdmin does exactly what it claims
func (o *Database) SetAdmin(path string, isadmin bool) error {

	//TODO: Make this work with devices
	u, err := o.ReadUser(path)
	if err != nil {
		return err
	}

	modu := *u //Make a copy of the user
	modu.Admin = isadmin

	return o.UpdateUser(u, modu)
<commit_msg>REST: Workaround for #81<commit_after>package streamdb

import (
	"errors"
	"streamdb/users"
)

/*
These functions allow Database to conform to the Operator interface
*/

var (
	//ErrAdmin is thrown when trying to get the user or device of the Admin operator
	ErrAdmin = errors.New("An administrative operator has no user or device")

	//ErrNotChangeable is thrown when changing a field that can't be changed
	ErrNotChangeable = errors.New("The given fields are not modifiable.")
)

//User returns the current user
func (o *Database) User() (usr *users.User, err error) {
	return nil, ErrAdmin
}

//Device returns the current device
func (o *Database) Device() (*users.Device, error) {
	return nil, ErrAdmin
}

//Permissions returns whether the operator has permissions given by the string
func (o *Database) Permissions(perm users.PermissionLevel) bool {
	return true
}

//The following functions are direct mirrors of Userdb

//CreateUser makes a new user
func (o *Database) CreateUser(username, email, password string) error {
	return o.Userdb.CreateUser(username, email, password)
}

//ReadAllUsers reads all the users
func (o *Database) ReadAllUsers() ([]users.User, error) {
	return o.Userdb.ReadAllUsers()
}

//ReadUser reads a user - or rather reads any user that this device has permissions to read
func (o *Database) ReadUser(username string) (*users.User, error) {
	return o.Userdb.ReadUserByName(username)
}

//ReadUserByEmail reads a user - or rather reads any user that this device has permissions to read
func (o *Database) ReadUserByEmail(email string) (*users.User, error) {
	return o.Userdb.ReadUserByEmail(email)
}

//DeleteUser deletes the given user - only admin can delete
func (o *Database) DeleteUser(username string) error {
	_, err := o.ReadUser(username)
	if err != nil {
		return err //Workaround for issue #81
	}
	return o.Userdb.DeleteUserByName(username)
}

//UpdateUser performs the given modifications
func (o *Database) UpdateUser(user *users.User, modifieduser users.User) error {
	if modifieduser.RevertUneditableFields(*user, users.ROOT) > 0 {
		return ErrNotChangeable
	}

	return o.Userdb.UpdateUser(&modifieduser)
}

//SetAdmin does exactly what it claims
func (o *Database) SetAdmin(path string, isadmin bool) error {

	//TODO: Make this work with devices
	u, err := o.ReadUser(path)
	if err != nil {
		return err
	}

	modu := *u //Make a copy of the user
	modu.Admin = isadmin

	return o.UpdateUser(u, modu)

{'fraction_non_alphanumeric': 0.09651865749426725, 'fraction_numerical': 0.0012507817385866166, 'mean_word_length': 4.4771689497716896, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6697633', 'n_tokens_mistral': 1448, 'n_tokens_neox': 1427, 'n_words': 562}