users

package
v0.0.0-...-4436486 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 17, 2020 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const OwnerTypeOrg string = "organizations"

OwnerTypeOrg represents the 'organizations' OwnerType value.

View Source
const OwnerTypeUser string = "users"

OwnerTypeUser represents the 'users' OwnerType value.

Variables

This section is empty.

Functions

func AccessTokenCreate

func AccessTokenCreate(jwtUser *User, tx *gorm.DB, accessTokenCreateRequest ign.AccessTokenCreateRequest) (interface{}, *ign.ErrMsg)

AccessTokenCreate creates a new access token for a user.

func AccessTokenDelete

func AccessTokenDelete(jwtUser *User, tx *gorm.DB, accessToken ign.AccessToken) (interface{}, *ign.ErrMsg)

AccessTokenDelete removes a personal access token. This function requires the user's JWT, which means that a personal access token cannot be used to remove access token.

func AccessTokenList

func AccessTokenList(p *ign.PaginationRequest, tx *gorm.DB,
	reqUser *User) (*ign.AccessTokens, *ign.PaginationResult, *ign.ErrMsg)

AccessTokenList returns a list of paginated AccessTokens.

func CanPerformWithRole

func CanPerformWithRole(tx *gorm.DB, owner, user string,
	role permissions.Role) (bool, *ign.ErrMsg)

CanPerformWithRole checks to see if the 'owner' arg is an organization or a user. If the 'owner' is an organization, it verifies that the given 'user' arg is authorized to act as the given Role (or above) in the organization. If the 'owner' is a user, it verifies that the 'user' arg is the same as the owner.

func CheckPermissions

func CheckPermissions(tx *gorm.DB, resource string, user *User, isPrivate bool,
	per permissions.Action) (bool, *ign.ErrMsg)

CheckPermissions validates if the given user has the requested permission on the resource. The resource can be public or private, and that is extracted from the argument isPrivate.

func CreateOwnerFolder

func CreateOwnerFolder(ctx context.Context, owner string, failIfDirExist bool) (*string, *ign.ErrMsg)

CreateOwnerFolder creates a folder for the given owner. The folder will have models and worls subfolders. Fails if already exists. Returns the path pointing to the created owner's folder (eg. /fuel/owner)

func GetOrganizationsAndRolesForUser

func GetOrganizationsAndRolesForUser(tx *gorm.DB, user,
	requestor *User) (map[string]string, *ign.ErrMsg)

GetOrganizationsAndRolesForUser returns a map with the Organizations and associated roles of a user. It only returns non-deleted organizations. If the requestor is the same user then it will include all details. Otherwise the returned organizations will include only those that the requestor can Read or are Public. Roles will be included for those that requestor can Write.

func GetResourcePath

func GetResourcePath(owner, uuidStr, resType string) string

GetResourcePath returns a os path to a resource (eg. user/models/uuid)

func NewUUID

func NewUUID(owner string, resType string) (uuidStr, resPath string, err error)

NewUUID creates a new valid UUID for for a resource type (eg. "models"). Returns the generated UUID and a resource path using that UUID. The resource path will exist within the user folder.

func QueryForTeams

func QueryForTeams(q *gorm.DB) *gorm.DB

QueryForTeams returns a gorm query configured to query Teams with preloaded Users and owning Organization.

func VerifyOwner

func VerifyOwner(tx *gorm.DB, owner, user string,
	per permissions.Action) (bool, *ign.ErrMsg)

VerifyOwner checks to see if the 'owner' arg is an organization or a user. If the 'owner' is an organization, it verifies that the given 'user' arg has the expected permission in the organization. If the 'owner' is a user, it verifies that the 'user' arg is the same as the owner.

Types

type AddUserToOrgInput

type AddUserToOrgInput struct {
	Username string `json:"username" validate:"required,alphanum" form:"username"`
	Role     string `json:"role" validate:"required,oneof=owner admin member" form:"role"`
}

AddUserToOrgInput is the input data to add a user to an org.

type CreateOrganization

type CreateOrganization struct {
	// The name of the Organization
	// required: true
	Name string `json:"name" validate:"required,min=3,alphanumspace,notinblacklist" form:"name"`
	// The email of the Organization
	Email string `json:"email" validate:"omitempty,email" form:"email"`
	// Optional description
	Description string `json:"description" form:"description"`
}

CreateOrganization encapsulates data required to create an organization

type CreateTeamForm

type CreateTeamForm struct {
	// The name of the team
	// required: true
	Name    string `json:"name" validate:"required" form:"name"`
	Visible *bool  `validate:"required" form:"visible"`
	// Optional description
	Description *string `json:"description" form:"description"`
}

CreateTeamForm encapsulates data required to create a team

type Organization

type Organization struct {
	gorm.Model

	// Name of the organization
	// Name is unique in the Fuel community (including users)
	Name *string `gorm:"not null;unique" json:"name"`

	// Description of the organization
	Description *string `json:"description"`
	// Email
	Email *string `json:"email,omitempty"`

	// The username of the User that created this organization (usually got from the JWT)
	Creator *string `json:"-"`
}

Organization consists of a group of users/teams swagger:model

func ByOrganizationName

func ByOrganizationName(tx *gorm.DB, name string, deleted bool) (*Organization, *ign.ErrMsg)

ByOrganizationName queries an organization by name.

type OrganizationResponse

type OrganizationResponse struct {
	Name        string `json:"name,omitempty"`
	Description string `json:"description,omitempty"`
	Email       string `json:"email,omitempty"`
	Private     bool   `json:"private,omitempty"`
}

OrganizationResponse stores organization information used in REST responses.

swagger:model

type OrganizationResponses

type OrganizationResponses []OrganizationResponse

OrganizationResponses is a slice of OrganizationResponse swagger:model

type OrganizationService

type OrganizationService struct{}

OrganizationService is the main struct exported by this Organization Service. It was meant as a way to structure code and help future extensions.

func (*OrganizationService) AddUserToOrg

func (ms *OrganizationService) AddUserToOrg(ctx context.Context, tx *gorm.DB,
	orgName, username, role string, requestor *User) (*UserResponse, *ign.ErrMsg)

AddUserToOrg adds an user to an organization, using the given role.

func (*OrganizationService) CreateOrganization

func (ms *OrganizationService) CreateOrganization(ctx context.Context, tx *gorm.DB,
	co CreateOrganization, creator *User) (*OrganizationResponse, *ign.ErrMsg)

CreateOrganization creates a new Organization in DB using the data from the given Organization struct. Returns an OrganizationResponse.

func (*OrganizationService) CreateOrganizationResponse

func (ms *OrganizationService) CreateOrganizationResponse(organization *Organization,
	requestor *User, forceShowPrivate bool) OrganizationResponse

CreateOrganizationResponse creates a new OrganizationResponse struct based on the given Organization object. The returned OrganizationResponse will also include organization private fields if the requestor has Write access to those. But forceShowPrivate arg forces returning private data regardless of the requestor's permissions.

func (*OrganizationService) CreateTeam

func (ms *OrganizationService) CreateTeam(ctx context.Context, tx *gorm.DB,
	orgName string, t CreateTeamForm, creator *User) (*TeamResponse, *ign.ErrMsg)

CreateTeam creates a new team within an organization. Returns a Team

func (*OrganizationService) CreateTeamResponse

func (ms *OrganizationService) CreateTeamResponse(orgName string, team *Team) TeamResponse

CreateTeamResponse creates a new TeamResponse struct based on the given Team object.

func (*OrganizationService) GetOrgUsers

func (ms *OrganizationService) GetOrgUsers(p *ign.PaginationRequest, tx *gorm.DB,
	orgName string, user *User) (*UserResponses, *ign.PaginationResult, *ign.ErrMsg)

GetOrgUsers returns the list of users of an Organization. The result will be paginated. user argument is the user requesting the operation.

func (*OrganizationService) GetOrganization

func (ms *OrganizationService) GetOrganization(ctx context.Context, tx *gorm.DB,
	orgName string, deleted bool) (*Organization, *ign.ErrMsg)

GetOrganization returns the organization based on the name requested. param[in] The params key to look for. deleted[in] Whether to include deleted organizations in the search query.

func (*OrganizationService) GetTeamDetails

func (ms *OrganizationService) GetTeamDetails(ctx context.Context, tx *gorm.DB,
	orgName, teamName string, user *User) (*TeamResponse, *ign.ErrMsg)

GetTeamDetails returns a single team. The user argument is the requesting user.

func (*OrganizationService) GetTeams

func (ms *OrganizationService) GetTeams(p *ign.PaginationRequest, tx *gorm.DB,
	orgName string, user *User) (*TeamResponses, *ign.PaginationResult, *ign.ErrMsg)

GetTeams returns the list of teams of an Organization. The result will be paginated. user argument is the user requesting the operation.

func (*OrganizationService) OrganizationList

func (ms *OrganizationService) OrganizationList(p *ign.PaginationRequest, tx *gorm.DB,
	requestor *User, forceShowPrivate bool) (*OrganizationResponses, *ign.PaginationResult, *ign.ErrMsg)

OrganizationList returns a list of paginated OrganizationResponses. forceShowPrivate forces returning Org private data regardless of the requestor's permissions.

func (*OrganizationService) RemoveOrganization

func (ms *OrganizationService) RemoveOrganization(ctx context.Context, tx *gorm.DB, orgName string,
	user *User) (*OrganizationResponse, *ign.ErrMsg)

RemoveOrganization removes the given organization. Returns a OrganizationResponse with the removed organization. The user argument is the requesting user. It is used to check if the user can perform the operation. NOTE: It does not remove the Group or its permissions from the Permissions DB (casbin), in case we want to revert.

func (*OrganizationService) RemoveTeam

func (ms *OrganizationService) RemoveTeam(ctx context.Context, tx *gorm.DB,
	orgName, teamName string, user *User) (*TeamResponse, *ign.ErrMsg)

RemoveTeam removes the given team. Returns the removed Team The user argument is the requesting user. It is used to check if the user can perform the operation. NOTE: It does not remove the team role from the Permissions DB (casbin), in case we want to revert.

func (*OrganizationService) RemoveUserFromOrg

func (ms *OrganizationService) RemoveUserFromOrg(ctx context.Context, tx *gorm.DB, orgName, username string,
	requestor *User) (*UserResponse, *ign.ErrMsg)

RemoveUserFromOrg removes an user from an organization. NOTE: the owner of an Org cannot be removed (will return ErrorUnexpected)

func (*OrganizationService) UpdateOrganization

func (ms *OrganizationService) UpdateOrganization(ctx context.Context, tx *gorm.DB,
	orgName string, uo *UpdateOrganization, user *User) (*Organization, *ign.ErrMsg)

UpdateOrganization updates an organization. Fields that can be currently updated: desc, email The user argument is the requesting user. It is used to check if the user can perform the operation.

func (*OrganizationService) UpdateTeam

func (ms *OrganizationService) UpdateTeam(ctx context.Context, tx *gorm.DB,
	orgName, teamName string, ut UpdateTeamForm, requestor *User) (*TeamResponse, *ign.ErrMsg)

UpdateTeam updates a team , and sets the list of users The user argument is the requesting user. It is used to check if the user can perform the operation.

type Organizations

type Organizations []Organization

Organizations is an array of Organization

type OwnerProfile

type OwnerProfile struct {
	// The type: 'users' or 'organizations'
	OwnerType string
	// Optional UserResponse
	User *UserResponse
	// Optional OrganizationResponse
	Org *OrganizationResponse
}

OwnerProfile stores information about a user OR an organization.

swagger:model

func GetOwnerProfile

func GetOwnerProfile(tx *gorm.DB, owner string, user *User) (*OwnerProfile, *ign.ErrMsg)

GetOwnerProfile returns the details of a user or an organization.

type Team

type Team struct {
	gorm.Model

	// Name of the team. Team names within an Org cannot be duplicated (even when soft-deleted)
	Name *string `gorm:"not null;unique_index:idx_org_name" json:"name" validate:"required,alphanumspace"`

	// Whether this team is visible to non-members
	Visible bool `gorm:"not null" json:"visible"`

	// (optional) Description of the team
	Description *string `json:"description"`

	// The Organization to which this team belongs
	Organization   Organization `gorm:"save_associations:false" json:"-"`
	OrganizationID uint         `gorm:"not nulll;unique_index:idx_org_name" json:"-"`

	// The username of the User that created this team (usually got from the JWT)
	Creator *string `json:"-"`
}

Team is a group of users within an Organization

func ByTeamName

func ByTeamName(tx *gorm.DB, name string, deleted bool) (*Team, *ign.ErrMsg)

ByTeamName finds a team by name.

type TeamResponse

type TeamResponse struct {
	Name        string   `json:"name"`
	Description *string  `json:"description"`
	Visible     bool     `json:"visible"`
	Usernames   []string `json:"usernames"`
}

TeamResponse represents a team for API responses. swagger:model

type TeamResponses

type TeamResponses []TeamResponse

TeamResponses is a slice of TeamResponse swagger:model

type Teams

type Teams []Team

Teams is an array of Team

type UniqueOwner

type UniqueOwner struct {
	Name *string `gorm:"primary_key:true"`

	CreatedAt time.Time `gorm:"type:timestamp(3) NULL"`

	UpdatedAt time.Time

	DeletedAt *time.Time `sql:"index"`

	OwnerType string
}

UniqueOwner is a separate table to help ensure cross table username (and org) uniqueness. Each record here will be 'a user' or 'an org' (orgs and users cannot repeat names). In the future we can add more common data to this table.

func OwnerByName

func OwnerByName(tx *gorm.DB, name string, deleted bool) (*UniqueOwner, *ign.ErrMsg)

OwnerByName queries a the unique owner names.

type UpdateOrganization

type UpdateOrganization struct {
	// Optional email
	Email *string `json:"email" validate:"omitempty,email" form:"email"`
	// Optional description
	Description *string `json:"description" form:"description"`
}

UpdateOrganization encapsulates data that can be updated in an organization

func (UpdateOrganization) IsEmpty

func (uo UpdateOrganization) IsEmpty() bool

IsEmpty returns true is the struct is empty.

type UpdateTeamForm

type UpdateTeamForm struct {
	Visible  *bool    `form:"visible"`
	NewUsers []string `form:"new_users"`
	RmUsers  []string `form:"rm_users"`
	// Optional description
	Description *string `json:"description" form:"description"`
}

UpdateTeamForm encapsulates data required to update a team

type UpdateUserInput

type UpdateUserInput struct {
	// Optional name
	Name *string `json:"name,omitempty"`
	// Optional email
	Email       *string `json:"email" validate:"omitempty,email"`
	ExpFeatures *string `json:"exp_features,omitempty" validate:"omitempty,expfeatures,max=255"`
}

UpdateUserInput encapsulates data that can be updated in an user

func (UpdateUserInput) IsEmpty

func (uu UpdateUserInput) IsEmpty() bool

IsEmpty returns true is the struct is empty.

type User

type User struct {
	gorm.Model

	Identity *string `json:"identity,omitempty"`

	// Person name
	Name *string `json:"name,omitempty"`

	// Username is unique in the Fuel community (including organizations)
	Username *string `gorm:"not null;unique" json:"username,omitempty" validate:"required,min=3,alphanum,notinblacklist"`

	// DEPRECATED: Organization is an ignored field.
	Organization *string `json:"org,omitempty"`

	Email *string `json:"email,omitempty" validate:"required,email"`

	// A comma separated list of features enabled for the user.
	ExpFeatures *string `json:"exp_features,omitempty" validate:"omitempty,expfeatures,max=255"`

	ModelCount       *uint `json:"model_count,omitempty"`
	LikedModels      *uint `json:"liked_models,omitempty"`
	DownloadedModels *uint `json:"downloaded_models,omitempty"`

	WorldCount       *uint `json:"world_count,omitempty"`
	LikedWorlds      *uint `json:"liked_worlds,omitempty"`
	DownloadedWorlds *uint `json:"downloaded_worlds,omitempty"`

	// AccessTokens are personal access tokens granted to a user by a user.
	AccessTokens ign.AccessTokens
}

User information

swagger:model

func ByIdentity

func ByIdentity(tx *gorm.DB, identity string, deleted bool) (*User, *ign.ErrMsg)

ByIdentity queries a user by identity.

func ByUsername

func ByUsername(tx *gorm.DB, username string, deleted bool) (*User, *ign.ErrMsg)

ByUsername queries a user by username.

type UserResponse

type UserResponse struct {
	Name     string `json:"name"`
	Username string `json:"username"`
	// private
	Email         string   `json:"email"`
	Organizations []string `json:"orgs"`
	// private
	OrgRoles map[string]string `json:"orgRoles"`
	// private
	ID uint `json:"id"`
	// private
	ExpFeatures string `json:"exp_features,omitempty"`
	// True if the user is a system administrator
	SysAdmin bool `json:"sysAdmin"`
}

UserResponse stores user information used in REST responses.

swagger:model

func CreateUser

func CreateUser(ctx context.Context, tx *gorm.DB, u *User, failIfDirExist bool) (*UserResponse, *ign.ErrMsg)

CreateUser creates a new User in filesystem and DB using the data from the given User struct. Returns a UserResponse.

func CreateUserResponse

func CreateUserResponse(tx *gorm.DB, user, requestor *User) UserResponse

CreateUserResponse creates a new UserResponse struct based on the given User object. The returned UserResponse will also include user private fields if the requestor can access those

func GetUserByIdentity

func GetUserByIdentity(tx *gorm.DB, identity string) (*UserResponse, *ign.ErrMsg)

GetUserByIdentity returns a user given an identity. This method will fail if the identify does not correspond to an active user.

func RemoveUser

func RemoveUser(ctx context.Context, tx *gorm.DB, username string, reqUser *User) (*UserResponse, *ign.ErrMsg)

RemoveUser removes the given user. Returns a UserResponse with the removed user. The reqUser argument is the requesting user. It is used to check if the reqUser can perform the operation.

func UpdateUser

func UpdateUser(ctx context.Context, tx *gorm.DB, username string,
	uu *UpdateUserInput, reqUser *User) (*UserResponse, *ign.ErrMsg)

UpdateUser updates an user. Fields that can be currently updated: name, email The reqUser argument is the requesting user. It is used to check if the reqUser can perform the operation.

type UserResponses

type UserResponses []UserResponse

UserResponses is a slice of UserResponse swagger:model

func UserList

func UserList(p *ign.PaginationRequest, tx *gorm.DB,
	reqUser *User) (*UserResponses, *ign.PaginationResult, *ign.ErrMsg)

UserList returns a list of paginated UserResponses.

type Users

type Users []User

Users is an slice of User

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL