Automatic Merge
Этот коммит содержится в:
166
app/app_iface.go
166
app/app_iface.go
@@ -184,7 +184,7 @@ type AppIface interface {
|
|||||||
// GetSanitizedConfig gets the configuration for a system admin without any secrets.
|
// GetSanitizedConfig gets the configuration for a system admin without any secrets.
|
||||||
GetSanitizedConfig() *model.Config
|
GetSanitizedConfig() *model.Config
|
||||||
// GetSchemeRolesForChannel Checks if a channel or its team has an override scheme for channel roles and returns the scheme roles or default channel roles.
|
// GetSchemeRolesForChannel Checks if a channel or its team has an override scheme for channel roles and returns the scheme roles or default channel roles.
|
||||||
GetSchemeRolesForChannel(channelId string) (guestRoleName string, userRoleName string, adminRoleName string, err *model.AppError)
|
GetSchemeRolesForChannel(channelID string) (guestRoleName string, userRoleName string, adminRoleName string, err *model.AppError)
|
||||||
// GetSessionLengthInMillis returns the session length, in milliseconds,
|
// GetSessionLengthInMillis returns the session length, in milliseconds,
|
||||||
// based on the type of session (Mobile, SSO, Web/LDAP).
|
// based on the type of session (Mobile, SSO, Web/LDAP).
|
||||||
GetSessionLengthInMillis(session *model.Session) int64
|
GetSessionLengthInMillis(session *model.Session) int64
|
||||||
@@ -334,17 +334,17 @@ type AppIface interface {
|
|||||||
// UpdateWebConnUserActivity sets the LastUserActivityAt of the hub for the given session.
|
// UpdateWebConnUserActivity sets the LastUserActivityAt of the hub for the given session.
|
||||||
UpdateWebConnUserActivity(session model.Session, activityAt int64)
|
UpdateWebConnUserActivity(session model.Session, activityAt int64)
|
||||||
// UploadFile uploads a single file in form of a completely constructed byte array for a channel.
|
// UploadFile uploads a single file in form of a completely constructed byte array for a channel.
|
||||||
UploadFile(data []byte, channelId string, filename string) (*model.FileInfo, *model.AppError)
|
UploadFile(data []byte, channelID string, filename string) (*model.FileInfo, *model.AppError)
|
||||||
// UploadFileX uploads a single file as specified in t. It applies the upload
|
// UploadFileX uploads a single file as specified in t. It applies the upload
|
||||||
// constraints, executes plugins and image processing logic as needed. It
|
// constraints, executes plugins and image processing logic as needed. It
|
||||||
// returns a filled-out FileInfo and an optional error. A plugin may reject the
|
// returns a filled-out FileInfo and an optional error. A plugin may reject the
|
||||||
// upload, returning a rejection error. In this case FileInfo would have
|
// upload, returning a rejection error. In this case FileInfo would have
|
||||||
// contained the last "good" FileInfo before the execution of that plugin.
|
// contained the last "good" FileInfo before the execution of that plugin.
|
||||||
UploadFileX(channelId, name string, input io.Reader, opts ...func(*UploadFileTask)) (*model.FileInfo, *model.AppError)
|
UploadFileX(channelID, name string, input io.Reader, opts ...func(*UploadFileTask)) (*model.FileInfo, *model.AppError)
|
||||||
// Uploads some files to the given team and channel as the given user. files and filenames should have
|
// Uploads some files to the given team and channel as the given user. files and filenames should have
|
||||||
// the same length. clientIds should either not be provided or have the same length as files and filenames.
|
// the same length. clientIds should either not be provided or have the same length as files and filenames.
|
||||||
// The provided files should be closed by the caller so that they are not leaked.
|
// The provided files should be closed by the caller so that they are not leaked.
|
||||||
UploadFiles(teamID string, channelId string, userID string, files []io.ReadCloser, filenames []string, clientIds []string, now time.Time) (*model.FileUploadResponse, *model.AppError)
|
UploadFiles(teamID string, channelID string, userID string, files []io.ReadCloser, filenames []string, clientIds []string, now time.Time) (*model.FileUploadResponse, *model.AppError)
|
||||||
// UserIsInAdminRoleGroup returns true at least one of the user's groups are configured to set the members as
|
// UserIsInAdminRoleGroup returns true at least one of the user's groups are configured to set the members as
|
||||||
// admins in the given syncable.
|
// admins in the given syncable.
|
||||||
UserIsInAdminRoleGroup(userID, syncableID string, syncableType model.GroupSyncableType) (bool, *model.AppError)
|
UserIsInAdminRoleGroup(userID, syncableID string, syncableType model.GroupSyncableType) (bool, *model.AppError)
|
||||||
@@ -379,16 +379,16 @@ type AppIface interface {
|
|||||||
AllowOAuthAppAccessToUser(userID string, authRequest *model.AuthorizeRequest) (string, *model.AppError)
|
AllowOAuthAppAccessToUser(userID string, authRequest *model.AuthorizeRequest) (string, *model.AppError)
|
||||||
AppendFile(fr io.Reader, path string) (int64, *model.AppError)
|
AppendFile(fr io.Reader, path string) (int64, *model.AppError)
|
||||||
AsymmetricSigningKey() *ecdsa.PrivateKey
|
AsymmetricSigningKey() *ecdsa.PrivateKey
|
||||||
AttachDeviceId(sessionId string, deviceId string, expiresAt int64) *model.AppError
|
AttachDeviceId(sessionID string, deviceID string, expiresAt int64) *model.AppError
|
||||||
AttachSessionCookies(w http.ResponseWriter, r *http.Request)
|
AttachSessionCookies(w http.ResponseWriter, r *http.Request)
|
||||||
AuthenticateUserForLogin(id, loginId, password, mfaToken, cwsToken string, ldapOnly bool) (user *model.User, err *model.AppError)
|
AuthenticateUserForLogin(id, loginId, password, mfaToken, cwsToken string, ldapOnly bool) (user *model.User, err *model.AppError)
|
||||||
AuthorizeOAuthUser(w http.ResponseWriter, r *http.Request, service, code, state, redirectUri string) (io.ReadCloser, string, map[string]string, *model.User, *model.AppError)
|
AuthorizeOAuthUser(w http.ResponseWriter, r *http.Request, service, code, state, redirectUri string) (io.ReadCloser, string, map[string]string, *model.User, *model.AppError)
|
||||||
AutocompleteChannels(teamID string, term string) (*model.ChannelList, *model.AppError)
|
AutocompleteChannels(teamID string, term string) (*model.ChannelList, *model.AppError)
|
||||||
AutocompleteChannelsForSearch(teamID string, userID string, term string) (*model.ChannelList, *model.AppError)
|
AutocompleteChannelsForSearch(teamID string, userID string, term string) (*model.ChannelList, *model.AppError)
|
||||||
AutocompleteUsersInChannel(teamID string, channelId string, term string, options *model.UserSearchOptions) (*model.UserAutocompleteInChannel, *model.AppError)
|
AutocompleteUsersInChannel(teamID string, channelID string, term string, options *model.UserSearchOptions) (*model.UserAutocompleteInChannel, *model.AppError)
|
||||||
AutocompleteUsersInTeam(teamID string, term string, options *model.UserSearchOptions) (*model.UserAutocompleteInTeam, *model.AppError)
|
AutocompleteUsersInTeam(teamID string, term string, options *model.UserSearchOptions) (*model.UserAutocompleteInTeam, *model.AppError)
|
||||||
BroadcastStatus(status *model.Status)
|
BroadcastStatus(status *model.Status)
|
||||||
BuildPostReactions(postId string) (*[]ReactionImportData, *model.AppError)
|
BuildPostReactions(postID string) (*[]ReactionImportData, *model.AppError)
|
||||||
BuildPushNotificationMessage(contentsConfig string, post *model.Post, user *model.User, channel *model.Channel, channelName string, senderName string, explicitMention bool, channelWideMention bool, replyToThreadType string) (*model.PushNotification, *model.AppError)
|
BuildPushNotificationMessage(contentsConfig string, post *model.Post, user *model.User, channel *model.Channel, channelName string, senderName string, explicitMention bool, channelWideMention bool, replyToThreadType string) (*model.PushNotification, *model.AppError)
|
||||||
BuildSamlMetadataObject(idpMetadata []byte) (*model.SamlMetadataResponse, *model.AppError)
|
BuildSamlMetadataObject(idpMetadata []byte) (*model.SamlMetadataResponse, *model.AppError)
|
||||||
BulkExport(writer io.Writer, outPath string, opts BulkExportOpts) *model.AppError
|
BulkExport(writer io.Writer, outPath string, opts BulkExportOpts) *model.AppError
|
||||||
@@ -417,14 +417,14 @@ type AppIface interface {
|
|||||||
ClientConfigHash() string
|
ClientConfigHash() string
|
||||||
Cloud() einterfaces.CloudInterface
|
Cloud() einterfaces.CloudInterface
|
||||||
Cluster() einterfaces.ClusterInterface
|
Cluster() einterfaces.ClusterInterface
|
||||||
CompareAndDeletePluginKey(pluginId string, key string, oldValue []byte) (bool, *model.AppError)
|
CompareAndDeletePluginKey(pluginID string, key string, oldValue []byte) (bool, *model.AppError)
|
||||||
CompareAndSetPluginKey(pluginId string, key string, oldValue, newValue []byte) (bool, *model.AppError)
|
CompareAndSetPluginKey(pluginID string, key string, oldValue, newValue []byte) (bool, *model.AppError)
|
||||||
CompleteOAuth(service string, body io.ReadCloser, teamID string, props map[string]string, tokenUser *model.User) (*model.User, *model.AppError)
|
CompleteOAuth(service string, body io.ReadCloser, teamID string, props map[string]string, tokenUser *model.User) (*model.User, *model.AppError)
|
||||||
CompleteSwitchWithOAuth(service string, userData io.Reader, email string, tokenUser *model.User) (*model.User, *model.AppError)
|
CompleteSwitchWithOAuth(service string, userData io.Reader, email string, tokenUser *model.User) (*model.User, *model.AppError)
|
||||||
Compliance() einterfaces.ComplianceInterface
|
Compliance() einterfaces.ComplianceInterface
|
||||||
Config() *model.Config
|
Config() *model.Config
|
||||||
Context() context.Context
|
Context() context.Context
|
||||||
CopyFileInfos(userID string, fileIds []string) ([]string, *model.AppError)
|
CopyFileInfos(userID string, fileIDs []string) ([]string, *model.AppError)
|
||||||
CreateChannel(channel *model.Channel, addMember bool) (*model.Channel, *model.AppError)
|
CreateChannel(channel *model.Channel, addMember bool) (*model.Channel, *model.AppError)
|
||||||
CreateChannelWithUser(channel *model.Channel, userID string) (*model.Channel, *model.AppError)
|
CreateChannelWithUser(channel *model.Channel, userID string) (*model.Channel, *model.AppError)
|
||||||
CreateCommand(cmd *model.Command) (*model.Command, *model.AppError)
|
CreateCommand(cmd *model.Command) (*model.Command, *model.AppError)
|
||||||
@@ -461,24 +461,24 @@ type AppIface interface {
|
|||||||
DataRetention() einterfaces.DataRetentionInterface
|
DataRetention() einterfaces.DataRetentionInterface
|
||||||
DeactivateGuests() *model.AppError
|
DeactivateGuests() *model.AppError
|
||||||
DeactivateMfa(userID string) *model.AppError
|
DeactivateMfa(userID string) *model.AppError
|
||||||
DeauthorizeOAuthAppForUser(userID, appId string) *model.AppError
|
DeauthorizeOAuthAppForUser(userID, appID string) *model.AppError
|
||||||
DeleteAllExpiredPluginKeys() *model.AppError
|
DeleteAllExpiredPluginKeys() *model.AppError
|
||||||
DeleteAllKeysForPlugin(pluginId string) *model.AppError
|
DeleteAllKeysForPlugin(pluginID string) *model.AppError
|
||||||
DeleteBrandImage() *model.AppError
|
DeleteBrandImage() *model.AppError
|
||||||
DeleteChannel(channel *model.Channel, userID string) *model.AppError
|
DeleteChannel(channel *model.Channel, userID string) *model.AppError
|
||||||
DeleteCommand(commandID string) *model.AppError
|
DeleteCommand(commandID string) *model.AppError
|
||||||
DeleteEmoji(emoji *model.Emoji) *model.AppError
|
DeleteEmoji(emoji *model.Emoji) *model.AppError
|
||||||
DeleteEphemeralPost(userID, postId string)
|
DeleteEphemeralPost(userID, postID string)
|
||||||
DeleteExport(name string) *model.AppError
|
DeleteExport(name string) *model.AppError
|
||||||
DeleteFlaggedPosts(postId string)
|
DeleteFlaggedPosts(postID string)
|
||||||
DeleteGroup(groupID string) (*model.Group, *model.AppError)
|
DeleteGroup(groupID string) (*model.Group, *model.AppError)
|
||||||
DeleteGroupMember(groupID string, userID string) (*model.GroupMember, *model.AppError)
|
DeleteGroupMember(groupID string, userID string) (*model.GroupMember, *model.AppError)
|
||||||
DeleteGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) (*model.GroupSyncable, *model.AppError)
|
DeleteGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) (*model.GroupSyncable, *model.AppError)
|
||||||
DeleteIncomingWebhook(hookID string) *model.AppError
|
DeleteIncomingWebhook(hookID string) *model.AppError
|
||||||
DeleteOAuthApp(appId string) *model.AppError
|
DeleteOAuthApp(appID string) *model.AppError
|
||||||
DeleteOutgoingWebhook(hookID string) *model.AppError
|
DeleteOutgoingWebhook(hookID string) *model.AppError
|
||||||
DeletePluginKey(pluginId string, key string) *model.AppError
|
DeletePluginKey(pluginID string, key string) *model.AppError
|
||||||
DeletePost(postId, deleteByID string) (*model.Post, *model.AppError)
|
DeletePost(postID, deleteByID string) (*model.Post, *model.AppError)
|
||||||
DeletePostFiles(post *model.Post)
|
DeletePostFiles(post *model.Post)
|
||||||
DeletePreferences(userID string, preferences model.Preferences) *model.AppError
|
DeletePreferences(userID string, preferences model.Preferences) *model.AppError
|
||||||
DeleteReactionForPost(reaction *model.Reaction) *model.AppError
|
DeleteReactionForPost(reaction *model.Reaction) *model.AppError
|
||||||
@@ -492,9 +492,9 @@ type AppIface interface {
|
|||||||
DoEmojisPermissionsMigration()
|
DoEmojisPermissionsMigration()
|
||||||
DoGuestRolesCreationMigration()
|
DoGuestRolesCreationMigration()
|
||||||
DoLocalRequest(rawURL string, body []byte) (*http.Response, *model.AppError)
|
DoLocalRequest(rawURL string, body []byte) (*http.Response, *model.AppError)
|
||||||
DoLogin(w http.ResponseWriter, r *http.Request, user *model.User, deviceId string, isMobile, isOAuthUser, isSaml bool) *model.AppError
|
DoLogin(w http.ResponseWriter, r *http.Request, user *model.User, deviceID string, isMobile, isOAuthUser, isSaml bool) *model.AppError
|
||||||
DoPostAction(postId, actionId, userID, selectedOption string) (string, *model.AppError)
|
DoPostAction(postID, actionId, userID, selectedOption string) (string, *model.AppError)
|
||||||
DoPostActionWithCookie(postId, actionId, userID, selectedOption string, cookie *model.PostActionCookie) (string, *model.AppError)
|
DoPostActionWithCookie(postID, actionId, userID, selectedOption string, cookie *model.PostActionCookie) (string, *model.AppError)
|
||||||
DoSystemConsoleRolesCreationMigration()
|
DoSystemConsoleRolesCreationMigration()
|
||||||
DoUploadFile(now time.Time, rawTeamId string, rawChannelId string, rawUserId string, rawFilename string, data []byte) (*model.FileInfo, *model.AppError)
|
DoUploadFile(now time.Time, rawTeamId string, rawChannelId string, rawUserId string, rawFilename string, data []byte) (*model.FileInfo, *model.AppError)
|
||||||
DoUploadFileExpectModification(now time.Time, rawTeamId string, rawChannelId string, rawUserId string, rawFilename string, data []byte) (*model.FileInfo, []byte, *model.AppError)
|
DoUploadFileExpectModification(now time.Time, rawTeamId string, rawChannelId string, rawUserId string, rawFilename string, data []byte) (*model.FileInfo, []byte, *model.AppError)
|
||||||
@@ -534,21 +534,21 @@ type AppIface interface {
|
|||||||
GetAuthorizationCode(w http.ResponseWriter, r *http.Request, service string, props map[string]string, loginHint string) (string, *model.AppError)
|
GetAuthorizationCode(w http.ResponseWriter, r *http.Request, service string, props map[string]string, loginHint string) (string, *model.AppError)
|
||||||
GetAuthorizedAppsForUser(userID string, page, perPage int) ([]*model.OAuthApp, *model.AppError)
|
GetAuthorizedAppsForUser(userID string, page, perPage int) ([]*model.OAuthApp, *model.AppError)
|
||||||
GetBrandImage() ([]byte, *model.AppError)
|
GetBrandImage() ([]byte, *model.AppError)
|
||||||
GetBulkReactionsForPosts(postIds []string) (map[string][]*model.Reaction, *model.AppError)
|
GetBulkReactionsForPosts(postIDs []string) (map[string][]*model.Reaction, *model.AppError)
|
||||||
GetChannel(channelId string) (*model.Channel, *model.AppError)
|
GetChannel(channelID string) (*model.Channel, *model.AppError)
|
||||||
GetChannelByName(channelName, teamID string, includeDeleted bool) (*model.Channel, *model.AppError)
|
GetChannelByName(channelName, teamID string, includeDeleted bool) (*model.Channel, *model.AppError)
|
||||||
GetChannelByNameForTeamName(channelName, teamName string, includeDeleted bool) (*model.Channel, *model.AppError)
|
GetChannelByNameForTeamName(channelName, teamName string, includeDeleted bool) (*model.Channel, *model.AppError)
|
||||||
GetChannelCounts(teamID string, userID string) (*model.ChannelCounts, *model.AppError)
|
GetChannelCounts(teamID string, userID string) (*model.ChannelCounts, *model.AppError)
|
||||||
GetChannelGuestCount(channelId string) (int64, *model.AppError)
|
GetChannelGuestCount(channelID string) (int64, *model.AppError)
|
||||||
GetChannelMember(channelId string, userID string) (*model.ChannelMember, *model.AppError)
|
GetChannelMember(channelID string, userID string) (*model.ChannelMember, *model.AppError)
|
||||||
GetChannelMemberCount(channelId string) (int64, *model.AppError)
|
GetChannelMemberCount(channelID string) (int64, *model.AppError)
|
||||||
GetChannelMembersByIds(channelId string, userIDs []string) (*model.ChannelMembers, *model.AppError)
|
GetChannelMembersByIds(channelID string, userIDs []string) (*model.ChannelMembers, *model.AppError)
|
||||||
GetChannelMembersForUser(teamID string, userID string) (*model.ChannelMembers, *model.AppError)
|
GetChannelMembersForUser(teamID string, userID string) (*model.ChannelMembers, *model.AppError)
|
||||||
GetChannelMembersForUserWithPagination(teamID, userID string, page, perPage int) ([]*model.ChannelMember, *model.AppError)
|
GetChannelMembersForUserWithPagination(teamID, userID string, page, perPage int) ([]*model.ChannelMember, *model.AppError)
|
||||||
GetChannelMembersPage(channelId string, page, perPage int) (*model.ChannelMembers, *model.AppError)
|
GetChannelMembersPage(channelID string, page, perPage int) (*model.ChannelMembers, *model.AppError)
|
||||||
GetChannelMembersTimezones(channelId string) ([]string, *model.AppError)
|
GetChannelMembersTimezones(channelID string) ([]string, *model.AppError)
|
||||||
GetChannelPinnedPostCount(channelId string) (int64, *model.AppError)
|
GetChannelPinnedPostCount(channelID string) (int64, *model.AppError)
|
||||||
GetChannelUnread(channelId, userID string) (*model.ChannelUnread, *model.AppError)
|
GetChannelUnread(channelID, userID string) (*model.ChannelUnread, *model.AppError)
|
||||||
GetChannelsByNames(channelNames []string, teamID string) ([]*model.Channel, *model.AppError)
|
GetChannelsByNames(channelNames []string, teamID string) ([]*model.Channel, *model.AppError)
|
||||||
GetChannelsForScheme(scheme *model.Scheme, offset int, limit int) (model.ChannelList, *model.AppError)
|
GetChannelsForScheme(scheme *model.Scheme, offset int, limit int) (model.ChannelList, *model.AppError)
|
||||||
GetChannelsForSchemePage(scheme *model.Scheme, page int, perPage int) (model.ChannelList, *model.AppError)
|
GetChannelsForSchemePage(scheme *model.Scheme, page int, perPage int) (model.ChannelList, *model.AppError)
|
||||||
@@ -570,13 +570,13 @@ type AppIface interface {
|
|||||||
GetEmojiImage(emojiId string) ([]byte, string, *model.AppError)
|
GetEmojiImage(emojiId string) ([]byte, string, *model.AppError)
|
||||||
GetEmojiList(page, perPage int, sort string) ([]*model.Emoji, *model.AppError)
|
GetEmojiList(page, perPage int, sort string) ([]*model.Emoji, *model.AppError)
|
||||||
GetErrorListForEmailsOverLimit(emailList []string, cloudUserLimit int64) ([]string, []*model.EmailInviteWithError, *model.AppError)
|
GetErrorListForEmailsOverLimit(emailList []string, cloudUserLimit int64) ([]string, []*model.EmailInviteWithError, *model.AppError)
|
||||||
GetFile(fileId string) ([]byte, *model.AppError)
|
GetFile(fileID string) ([]byte, *model.AppError)
|
||||||
GetFileInfo(fileId string) (*model.FileInfo, *model.AppError)
|
GetFileInfo(fileID string) (*model.FileInfo, *model.AppError)
|
||||||
GetFileInfos(page, perPage int, opt *model.GetFileInfosOptions) ([]*model.FileInfo, *model.AppError)
|
GetFileInfos(page, perPage int, opt *model.GetFileInfosOptions) ([]*model.FileInfo, *model.AppError)
|
||||||
GetFileInfosForPost(postId string, fromMaster bool) ([]*model.FileInfo, *model.AppError)
|
GetFileInfosForPost(postID string, fromMaster bool) ([]*model.FileInfo, *model.AppError)
|
||||||
GetFileInfosForPostWithMigration(postId string) ([]*model.FileInfo, *model.AppError)
|
GetFileInfosForPostWithMigration(postID string) ([]*model.FileInfo, *model.AppError)
|
||||||
GetFlaggedPosts(userID string, offset int, limit int) (*model.PostList, *model.AppError)
|
GetFlaggedPosts(userID string, offset int, limit int) (*model.PostList, *model.AppError)
|
||||||
GetFlaggedPostsForChannel(userID, channelId string, offset int, limit int) (*model.PostList, *model.AppError)
|
GetFlaggedPostsForChannel(userID, channelID string, offset int, limit int) (*model.PostList, *model.AppError)
|
||||||
GetFlaggedPostsForTeam(userID, teamID string, offset int, limit int) (*model.PostList, *model.AppError)
|
GetFlaggedPostsForTeam(userID, teamID string, offset int, limit int) (*model.PostList, *model.AppError)
|
||||||
GetGroup(id string) (*model.Group, *model.AppError)
|
GetGroup(id string) (*model.Group, *model.AppError)
|
||||||
GetGroupByName(name string, opts model.GroupSearchOpts) (*model.Group, *model.AppError)
|
GetGroupByName(name string, opts model.GroupSearchOpts) (*model.Group, *model.AppError)
|
||||||
@@ -589,7 +589,7 @@ type AppIface interface {
|
|||||||
GetGroupSyncables(groupID string, syncableType model.GroupSyncableType) ([]*model.GroupSyncable, *model.AppError)
|
GetGroupSyncables(groupID string, syncableType model.GroupSyncableType) ([]*model.GroupSyncable, *model.AppError)
|
||||||
GetGroups(page, perPage int, opts model.GroupSearchOpts) ([]*model.Group, *model.AppError)
|
GetGroups(page, perPage int, opts model.GroupSearchOpts) ([]*model.Group, *model.AppError)
|
||||||
GetGroupsAssociatedToChannelsByTeam(teamID string, opts model.GroupSearchOpts) (map[string][]*model.GroupWithSchemeAdmin, *model.AppError)
|
GetGroupsAssociatedToChannelsByTeam(teamID string, opts model.GroupSearchOpts) (map[string][]*model.GroupWithSchemeAdmin, *model.AppError)
|
||||||
GetGroupsByChannel(channelId string, opts model.GroupSearchOpts) ([]*model.GroupWithSchemeAdmin, int, *model.AppError)
|
GetGroupsByChannel(channelID string, opts model.GroupSearchOpts) ([]*model.GroupWithSchemeAdmin, int, *model.AppError)
|
||||||
GetGroupsByIDs(groupIDs []string) ([]*model.Group, *model.AppError)
|
GetGroupsByIDs(groupIDs []string) ([]*model.Group, *model.AppError)
|
||||||
GetGroupsBySource(groupSource model.GroupSource) ([]*model.Group, *model.AppError)
|
GetGroupsBySource(groupSource model.GroupSource) ([]*model.Group, *model.AppError)
|
||||||
GetGroupsByUserId(userID string) ([]*model.Group, *model.AppError)
|
GetGroupsByUserId(userID string) ([]*model.Group, *model.AppError)
|
||||||
@@ -616,7 +616,7 @@ type AppIface interface {
|
|||||||
GetNumberOfChannelsOnTeam(teamID string) (int, *model.AppError)
|
GetNumberOfChannelsOnTeam(teamID string) (int, *model.AppError)
|
||||||
GetOAuthAccessTokenForCodeFlow(clientId, grantType, redirectUri, code, secret, refreshToken string) (*model.AccessResponse, *model.AppError)
|
GetOAuthAccessTokenForCodeFlow(clientId, grantType, redirectUri, code, secret, refreshToken string) (*model.AccessResponse, *model.AppError)
|
||||||
GetOAuthAccessTokenForImplicitFlow(userID string, authRequest *model.AuthorizeRequest) (*model.Session, *model.AppError)
|
GetOAuthAccessTokenForImplicitFlow(userID string, authRequest *model.AuthorizeRequest) (*model.Session, *model.AppError)
|
||||||
GetOAuthApp(appId string) (*model.OAuthApp, *model.AppError)
|
GetOAuthApp(appID string) (*model.OAuthApp, *model.AppError)
|
||||||
GetOAuthApps(page, perPage int) ([]*model.OAuthApp, *model.AppError)
|
GetOAuthApps(page, perPage int) ([]*model.OAuthApp, *model.AppError)
|
||||||
GetOAuthAppsByCreator(userID string, page, perPage int) ([]*model.OAuthApp, *model.AppError)
|
GetOAuthAppsByCreator(userID string, page, perPage int) ([]*model.OAuthApp, *model.AppError)
|
||||||
GetOAuthCodeRedirect(userID string, authRequest *model.AuthorizeRequest) (string, *model.AppError)
|
GetOAuthCodeRedirect(userID string, authRequest *model.AuthorizeRequest) (string, *model.AppError)
|
||||||
@@ -627,26 +627,26 @@ type AppIface interface {
|
|||||||
GetOpenGraphMetadata(requestURL string) *opengraph.OpenGraph
|
GetOpenGraphMetadata(requestURL string) *opengraph.OpenGraph
|
||||||
GetOrCreateDirectChannel(userID, otherUserID string) (*model.Channel, *model.AppError)
|
GetOrCreateDirectChannel(userID, otherUserID string) (*model.Channel, *model.AppError)
|
||||||
GetOutgoingWebhook(hookID string) (*model.OutgoingWebhook, *model.AppError)
|
GetOutgoingWebhook(hookID string) (*model.OutgoingWebhook, *model.AppError)
|
||||||
GetOutgoingWebhooksForChannelPageByUser(channelId string, userID string, page, perPage int) ([]*model.OutgoingWebhook, *model.AppError)
|
GetOutgoingWebhooksForChannelPageByUser(channelID string, userID string, page, perPage int) ([]*model.OutgoingWebhook, *model.AppError)
|
||||||
GetOutgoingWebhooksForTeamPage(teamID string, page, perPage int) ([]*model.OutgoingWebhook, *model.AppError)
|
GetOutgoingWebhooksForTeamPage(teamID string, page, perPage int) ([]*model.OutgoingWebhook, *model.AppError)
|
||||||
GetOutgoingWebhooksForTeamPageByUser(teamID string, userID string, page, perPage int) ([]*model.OutgoingWebhook, *model.AppError)
|
GetOutgoingWebhooksForTeamPageByUser(teamID string, userID string, page, perPage int) ([]*model.OutgoingWebhook, *model.AppError)
|
||||||
GetOutgoingWebhooksPage(page, perPage int) ([]*model.OutgoingWebhook, *model.AppError)
|
GetOutgoingWebhooksPage(page, perPage int) ([]*model.OutgoingWebhook, *model.AppError)
|
||||||
GetOutgoingWebhooksPageByUser(userID string, page, perPage int) ([]*model.OutgoingWebhook, *model.AppError)
|
GetOutgoingWebhooksPageByUser(userID string, page, perPage int) ([]*model.OutgoingWebhook, *model.AppError)
|
||||||
GetPasswordRecoveryToken(token string) (*model.Token, *model.AppError)
|
GetPasswordRecoveryToken(token string) (*model.Token, *model.AppError)
|
||||||
GetPermalinkPost(postId string, userID string) (*model.PostList, *model.AppError)
|
GetPermalinkPost(postID string, userID string) (*model.PostList, *model.AppError)
|
||||||
GetPinnedPosts(channelId string) (*model.PostList, *model.AppError)
|
GetPinnedPosts(channelID string) (*model.PostList, *model.AppError)
|
||||||
GetPluginKey(pluginId string, key string) ([]byte, *model.AppError)
|
GetPluginKey(pluginID string, key string) ([]byte, *model.AppError)
|
||||||
GetPlugins() (*model.PluginsResponse, *model.AppError)
|
GetPlugins() (*model.PluginsResponse, *model.AppError)
|
||||||
GetPostAfterTime(channelId string, time int64) (*model.Post, *model.AppError)
|
GetPostAfterTime(channelID string, time int64) (*model.Post, *model.AppError)
|
||||||
GetPostIdAfterTime(channelId string, time int64) (string, *model.AppError)
|
GetPostIdAfterTime(channelID string, time int64) (string, *model.AppError)
|
||||||
GetPostIdBeforeTime(channelId string, time int64) (string, *model.AppError)
|
GetPostIdBeforeTime(channelID string, time int64) (string, *model.AppError)
|
||||||
GetPostThread(postId string, skipFetchThreads, collapsedThreads, collapsedThreadsExtended bool) (*model.PostList, *model.AppError)
|
GetPostThread(postID string, skipFetchThreads, collapsedThreads, collapsedThreadsExtended bool) (*model.PostList, *model.AppError)
|
||||||
GetPosts(channelId string, offset int, limit int) (*model.PostList, *model.AppError)
|
GetPosts(channelID string, offset int, limit int) (*model.PostList, *model.AppError)
|
||||||
GetPostsAfterPost(options model.GetPostsOptions) (*model.PostList, *model.AppError)
|
GetPostsAfterPost(options model.GetPostsOptions) (*model.PostList, *model.AppError)
|
||||||
GetPostsAroundPost(before bool, options model.GetPostsOptions) (*model.PostList, *model.AppError)
|
GetPostsAroundPost(before bool, options model.GetPostsOptions) (*model.PostList, *model.AppError)
|
||||||
GetPostsBeforePost(options model.GetPostsOptions) (*model.PostList, *model.AppError)
|
GetPostsBeforePost(options model.GetPostsOptions) (*model.PostList, *model.AppError)
|
||||||
GetPostsEtag(channelId string, collapsedThreads bool) string
|
GetPostsEtag(channelID string, collapsedThreads bool) string
|
||||||
GetPostsForChannelAroundLastUnread(channelId, userID string, limitBefore, limitAfter int, skipFetchThreads bool, collapsedThreads, collapsedThreadsExtended bool) (*model.PostList, *model.AppError)
|
GetPostsForChannelAroundLastUnread(channelID, userID string, limitBefore, limitAfter int, skipFetchThreads bool, collapsedThreads, collapsedThreadsExtended bool) (*model.PostList, *model.AppError)
|
||||||
GetPostsPage(options model.GetPostsOptions) (*model.PostList, *model.AppError)
|
GetPostsPage(options model.GetPostsOptions) (*model.PostList, *model.AppError)
|
||||||
GetPostsSince(options model.GetPostsSinceOptions) (*model.PostList, *model.AppError)
|
GetPostsSince(options model.GetPostsSinceOptions) (*model.PostList, *model.AppError)
|
||||||
GetPreferenceByCategoryAndNameForUser(userID string, category string, preferenceName string) (*model.Preference, *model.AppError)
|
GetPreferenceByCategoryAndNameForUser(userID string, category string, preferenceName string) (*model.Preference, *model.AppError)
|
||||||
@@ -655,9 +655,9 @@ type AppIface interface {
|
|||||||
GetPrevPostIdFromPostList(postList *model.PostList) string
|
GetPrevPostIdFromPostList(postList *model.PostList) string
|
||||||
GetPrivateChannelsForTeam(teamID string, offset int, limit int) (*model.ChannelList, *model.AppError)
|
GetPrivateChannelsForTeam(teamID string, offset int, limit int) (*model.ChannelList, *model.AppError)
|
||||||
GetProfileImage(user *model.User) ([]byte, bool, *model.AppError)
|
GetProfileImage(user *model.User) ([]byte, bool, *model.AppError)
|
||||||
GetPublicChannelsByIdsForTeam(teamID string, channelIds []string) (*model.ChannelList, *model.AppError)
|
GetPublicChannelsByIdsForTeam(teamID string, channelIDs []string) (*model.ChannelList, *model.AppError)
|
||||||
GetPublicChannelsForTeam(teamID string, offset int, limit int) (*model.ChannelList, *model.AppError)
|
GetPublicChannelsForTeam(teamID string, offset int, limit int) (*model.ChannelList, *model.AppError)
|
||||||
GetReactionsForPost(postId string) ([]*model.Reaction, *model.AppError)
|
GetReactionsForPost(postID string) ([]*model.Reaction, *model.AppError)
|
||||||
GetRecentlyActiveUsersForTeam(teamID string) (map[string]*model.User, *model.AppError)
|
GetRecentlyActiveUsersForTeam(teamID string) (map[string]*model.User, *model.AppError)
|
||||||
GetRecentlyActiveUsersForTeamPage(teamID string, page, perPage int, asAdmin bool, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError)
|
GetRecentlyActiveUsersForTeamPage(teamID string, page, perPage int, asAdmin bool, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError)
|
||||||
GetRole(id string) (*model.Role, *model.AppError)
|
GetRole(id string) (*model.Role, *model.AppError)
|
||||||
@@ -673,12 +673,12 @@ type AppIface interface {
|
|||||||
GetSchemes(scope string, offset int, limit int) ([]*model.Scheme, *model.AppError)
|
GetSchemes(scope string, offset int, limit int) ([]*model.Scheme, *model.AppError)
|
||||||
GetSchemesPage(scope string, page int, perPage int) ([]*model.Scheme, *model.AppError)
|
GetSchemesPage(scope string, page int, perPage int) ([]*model.Scheme, *model.AppError)
|
||||||
GetSession(token string) (*model.Session, *model.AppError)
|
GetSession(token string) (*model.Session, *model.AppError)
|
||||||
GetSessionById(sessionId string) (*model.Session, *model.AppError)
|
GetSessionById(sessionID string) (*model.Session, *model.AppError)
|
||||||
GetSessions(userID string) ([]*model.Session, *model.AppError)
|
GetSessions(userID string) ([]*model.Session, *model.AppError)
|
||||||
GetSidebarCategories(userID, teamID string) (*model.OrderedSidebarCategories, *model.AppError)
|
GetSidebarCategories(userID, teamID string) (*model.OrderedSidebarCategories, *model.AppError)
|
||||||
GetSidebarCategory(categoryId string) (*model.SidebarCategoryWithChannels, *model.AppError)
|
GetSidebarCategory(categoryId string) (*model.SidebarCategoryWithChannels, *model.AppError)
|
||||||
GetSidebarCategoryOrder(userID, teamID string) ([]string, *model.AppError)
|
GetSidebarCategoryOrder(userID, teamID string) ([]string, *model.AppError)
|
||||||
GetSinglePost(postId string) (*model.Post, *model.AppError)
|
GetSinglePost(postID string) (*model.Post, *model.AppError)
|
||||||
GetSiteURL() string
|
GetSiteURL() string
|
||||||
GetStatus(userID string) (*model.Status, *model.AppError)
|
GetStatus(userID string) (*model.Status, *model.AppError)
|
||||||
GetStatusFromCache(userID string) *model.Status
|
GetStatusFromCache(userID string) *model.Status
|
||||||
@@ -717,7 +717,7 @@ type AppIface interface {
|
|||||||
GetUserForLogin(id, loginId string) (*model.User, *model.AppError)
|
GetUserForLogin(id, loginId string) (*model.User, *model.AppError)
|
||||||
GetUserTermsOfService(userID string) (*model.UserTermsOfService, *model.AppError)
|
GetUserTermsOfService(userID string) (*model.UserTermsOfService, *model.AppError)
|
||||||
GetUsers(options *model.UserGetOptions) ([]*model.User, *model.AppError)
|
GetUsers(options *model.UserGetOptions) ([]*model.User, *model.AppError)
|
||||||
GetUsersByGroupChannelIds(channelIds []string, asAdmin bool) (map[string][]*model.User, *model.AppError)
|
GetUsersByGroupChannelIds(channelIDs []string, asAdmin bool) (map[string][]*model.User, *model.AppError)
|
||||||
GetUsersByIds(userIDs []string, options *store.UserGetByIdsOpts) ([]*model.User, *model.AppError)
|
GetUsersByIds(userIDs []string, options *store.UserGetByIdsOpts) ([]*model.User, *model.AppError)
|
||||||
GetUsersByUsernames(usernames []string, asAdmin bool, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError)
|
GetUsersByUsernames(usernames []string, asAdmin bool, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError)
|
||||||
GetUsersEtag(restrictionsHash string) string
|
GetUsersEtag(restrictionsHash string) string
|
||||||
@@ -729,9 +729,9 @@ type AppIface interface {
|
|||||||
GetUsersInTeam(options *model.UserGetOptions) ([]*model.User, *model.AppError)
|
GetUsersInTeam(options *model.UserGetOptions) ([]*model.User, *model.AppError)
|
||||||
GetUsersInTeamEtag(teamID string, restrictionsHash string) string
|
GetUsersInTeamEtag(teamID string, restrictionsHash string) string
|
||||||
GetUsersInTeamPage(options *model.UserGetOptions, asAdmin bool) ([]*model.User, *model.AppError)
|
GetUsersInTeamPage(options *model.UserGetOptions, asAdmin bool) ([]*model.User, *model.AppError)
|
||||||
GetUsersNotInChannel(teamID string, channelId string, groupConstrained bool, offset int, limit int, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError)
|
GetUsersNotInChannel(teamID string, channelID string, groupConstrained bool, offset int, limit int, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError)
|
||||||
GetUsersNotInChannelMap(teamID string, channelId string, groupConstrained bool, offset int, limit int, asAdmin bool, viewRestrictions *model.ViewUsersRestrictions) (map[string]*model.User, *model.AppError)
|
GetUsersNotInChannelMap(teamID string, channelID string, groupConstrained bool, offset int, limit int, asAdmin bool, viewRestrictions *model.ViewUsersRestrictions) (map[string]*model.User, *model.AppError)
|
||||||
GetUsersNotInChannelPage(teamID string, channelId string, groupConstrained bool, page int, perPage int, asAdmin bool, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError)
|
GetUsersNotInChannelPage(teamID string, channelID string, groupConstrained bool, page int, perPage int, asAdmin bool, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError)
|
||||||
GetUsersNotInTeam(teamID string, groupConstrained bool, offset int, limit int, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError)
|
GetUsersNotInTeam(teamID string, groupConstrained bool, offset int, limit int, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError)
|
||||||
GetUsersNotInTeamEtag(teamID string, restrictionsHash string) string
|
GetUsersNotInTeamEtag(teamID string, restrictionsHash string) string
|
||||||
GetUsersNotInTeamPage(teamID string, groupConstrained bool, page int, perPage int, asAdmin bool, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError)
|
GetUsersNotInTeamPage(teamID string, groupConstrained bool, page int, perPage int, asAdmin bool, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError)
|
||||||
@@ -750,8 +750,8 @@ type AppIface interface {
|
|||||||
HandleIncomingWebhook(hookID string, req *model.IncomingWebhookRequest) *model.AppError
|
HandleIncomingWebhook(hookID string, req *model.IncomingWebhookRequest) *model.AppError
|
||||||
HandleMessageExportConfig(cfg *model.Config, appCfg *model.Config)
|
HandleMessageExportConfig(cfg *model.Config, appCfg *model.Config)
|
||||||
HasPermissionTo(askingUserId string, permission *model.Permission) bool
|
HasPermissionTo(askingUserId string, permission *model.Permission) bool
|
||||||
HasPermissionToChannel(askingUserId string, channelId string, permission *model.Permission) bool
|
HasPermissionToChannel(askingUserId string, channelID string, permission *model.Permission) bool
|
||||||
HasPermissionToChannelByPost(askingUserId string, postId string, permission *model.Permission) bool
|
HasPermissionToChannelByPost(askingUserId string, postID string, permission *model.Permission) bool
|
||||||
HasPermissionToTeam(askingUserId string, teamID string, permission *model.Permission) bool
|
HasPermissionToTeam(askingUserId string, teamID string, permission *model.Permission) bool
|
||||||
HasPermissionToUser(askingUserId string, userID string) bool
|
HasPermissionToUser(askingUserId string, userID string) bool
|
||||||
HubStop()
|
HubStop()
|
||||||
@@ -781,19 +781,19 @@ type AppIface interface {
|
|||||||
JoinDefaultChannels(teamID string, user *model.User, shouldBeAdmin bool, userRequestorId string) *model.AppError
|
JoinDefaultChannels(teamID string, user *model.User, shouldBeAdmin bool, userRequestorId string) *model.AppError
|
||||||
JoinUserToTeam(team *model.Team, user *model.User, userRequestorId string) *model.AppError
|
JoinUserToTeam(team *model.Team, user *model.User, userRequestorId string) *model.AppError
|
||||||
Ldap() einterfaces.LdapInterface
|
Ldap() einterfaces.LdapInterface
|
||||||
LeaveChannel(channelId string, userID string) *model.AppError
|
LeaveChannel(channelID string, userID string) *model.AppError
|
||||||
LeaveTeam(team *model.Team, user *model.User, requestorId string) *model.AppError
|
LeaveTeam(team *model.Team, user *model.User, requestorId string) *model.AppError
|
||||||
LimitedClientConfig() map[string]string
|
LimitedClientConfig() map[string]string
|
||||||
ListAllCommands(teamID string, T goi18n.TranslateFunc) ([]*model.Command, *model.AppError)
|
ListAllCommands(teamID string, T goi18n.TranslateFunc) ([]*model.Command, *model.AppError)
|
||||||
ListDirectory(path string) ([]string, *model.AppError)
|
ListDirectory(path string) ([]string, *model.AppError)
|
||||||
ListExports() ([]string, *model.AppError)
|
ListExports() ([]string, *model.AppError)
|
||||||
ListImports() ([]string, *model.AppError)
|
ListImports() ([]string, *model.AppError)
|
||||||
ListPluginKeys(pluginId string, page, perPage int) ([]string, *model.AppError)
|
ListPluginKeys(pluginID string, page, perPage int) ([]string, *model.AppError)
|
||||||
ListTeamCommands(teamID string) ([]*model.Command, *model.AppError)
|
ListTeamCommands(teamID string) ([]*model.Command, *model.AppError)
|
||||||
Log() *mlog.Logger
|
Log() *mlog.Logger
|
||||||
LoginByOAuth(service string, userData io.Reader, teamID string, tokenUser *model.User) (*model.User, *model.AppError)
|
LoginByOAuth(service string, userData io.Reader, teamID string, tokenUser *model.User) (*model.User, *model.AppError)
|
||||||
MakePermissionError(permissions []*model.Permission) *model.AppError
|
MakePermissionError(permissions []*model.Permission) *model.AppError
|
||||||
MarkChannelsAsViewed(channelIds []string, userID string, currentSessionId string) (map[string]int64, *model.AppError)
|
MarkChannelsAsViewed(channelIDs []string, userID string, currentSessionId string) (map[string]int64, *model.AppError)
|
||||||
MaxPostSize() int
|
MaxPostSize() int
|
||||||
MessageExport() einterfaces.MessageExportInterface
|
MessageExport() einterfaces.MessageExportInterface
|
||||||
Metrics() einterfaces.MetricsInterface
|
Metrics() einterfaces.MetricsInterface
|
||||||
@@ -808,7 +808,7 @@ type AppIface interface {
|
|||||||
OpenInteractiveDialog(request model.OpenDialogRequest) *model.AppError
|
OpenInteractiveDialog(request model.OpenDialogRequest) *model.AppError
|
||||||
OriginChecker() func(*http.Request) bool
|
OriginChecker() func(*http.Request) bool
|
||||||
PatchChannel(channel *model.Channel, patch *model.ChannelPatch, userID string) (*model.Channel, *model.AppError)
|
PatchChannel(channel *model.Channel, patch *model.ChannelPatch, userID string) (*model.Channel, *model.AppError)
|
||||||
PatchPost(postId string, patch *model.PostPatch) (*model.Post, *model.AppError)
|
PatchPost(postID string, patch *model.PostPatch) (*model.Post, *model.AppError)
|
||||||
PatchRole(role *model.Role, patch *model.RolePatch) (*model.Role, *model.AppError)
|
PatchRole(role *model.Role, patch *model.RolePatch) (*model.Role, *model.AppError)
|
||||||
PatchScheme(scheme *model.Scheme, patch *model.SchemePatch) (*model.Scheme, *model.AppError)
|
PatchScheme(scheme *model.Scheme, patch *model.SchemePatch) (*model.Scheme, *model.AppError)
|
||||||
PatchTeam(teamID string, patch *model.TeamPatch) (*model.Team, *model.AppError)
|
PatchTeam(teamID string, patch *model.TeamPatch) (*model.Team, *model.AppError)
|
||||||
@@ -834,7 +834,7 @@ type AppIface interface {
|
|||||||
ProcessSlackText(text string) string
|
ProcessSlackText(text string) string
|
||||||
Publish(message *model.WebSocketEvent)
|
Publish(message *model.WebSocketEvent)
|
||||||
PublishSkipClusterSend(message *model.WebSocketEvent)
|
PublishSkipClusterSend(message *model.WebSocketEvent)
|
||||||
PublishUserTyping(userID, channelId, parentId string) *model.AppError
|
PublishUserTyping(userID, channelID, parentId string) *model.AppError
|
||||||
PurgeBleveIndexes() *model.AppError
|
PurgeBleveIndexes() *model.AppError
|
||||||
PurgeElasticsearchIndexes() *model.AppError
|
PurgeElasticsearchIndexes() *model.AppError
|
||||||
ReadFile(path string) ([]byte, *model.AppError)
|
ReadFile(path string) ([]byte, *model.AppError)
|
||||||
@@ -843,7 +843,7 @@ type AppIface interface {
|
|||||||
RegenOutgoingWebhookToken(hook *model.OutgoingWebhook) (*model.OutgoingWebhook, *model.AppError)
|
RegenOutgoingWebhookToken(hook *model.OutgoingWebhook) (*model.OutgoingWebhook, *model.AppError)
|
||||||
RegenerateOAuthAppSecret(app *model.OAuthApp) (*model.OAuthApp, *model.AppError)
|
RegenerateOAuthAppSecret(app *model.OAuthApp) (*model.OAuthApp, *model.AppError)
|
||||||
RegenerateTeamInviteId(teamID string) (*model.Team, *model.AppError)
|
RegenerateTeamInviteId(teamID string) (*model.Team, *model.AppError)
|
||||||
RegisterPluginCommand(pluginId string, command *model.Command) error
|
RegisterPluginCommand(pluginID string, command *model.Command) error
|
||||||
ReloadConfig() error
|
ReloadConfig() error
|
||||||
RemoveAllDeactivatedMembersFromChannel(channel *model.Channel) *model.AppError
|
RemoveAllDeactivatedMembersFromChannel(channel *model.Channel) *model.AppError
|
||||||
RemoveConfigListener(id string)
|
RemoveConfigListener(id string)
|
||||||
@@ -874,8 +874,8 @@ type AppIface interface {
|
|||||||
RevokeAccessToken(token string) *model.AppError
|
RevokeAccessToken(token string) *model.AppError
|
||||||
RevokeAllSessions(userID string) *model.AppError
|
RevokeAllSessions(userID string) *model.AppError
|
||||||
RevokeSession(session *model.Session) *model.AppError
|
RevokeSession(session *model.Session) *model.AppError
|
||||||
RevokeSessionById(sessionId string) *model.AppError
|
RevokeSessionById(sessionID string) *model.AppError
|
||||||
RevokeSessionsForDeviceId(userID string, deviceId string, currentSessionId string) *model.AppError
|
RevokeSessionsForDeviceId(userID string, deviceID string, currentSessionId string) *model.AppError
|
||||||
RevokeUserAccessToken(token *model.UserAccessToken) *model.AppError
|
RevokeUserAccessToken(token *model.UserAccessToken) *model.AppError
|
||||||
RolesGrantPermission(roleNames []string, permissionId string) bool
|
RolesGrantPermission(roleNames []string, permissionId string) bool
|
||||||
Saml() einterfaces.SamlInterface
|
Saml() einterfaces.SamlInterface
|
||||||
@@ -901,10 +901,10 @@ type AppIface interface {
|
|||||||
SearchPublicTeams(term string) ([]*model.Team, *model.AppError)
|
SearchPublicTeams(term string) ([]*model.Team, *model.AppError)
|
||||||
SearchUserAccessTokens(term string) ([]*model.UserAccessToken, *model.AppError)
|
SearchUserAccessTokens(term string) ([]*model.UserAccessToken, *model.AppError)
|
||||||
SearchUsers(props *model.UserSearch, options *model.UserSearchOptions) ([]*model.User, *model.AppError)
|
SearchUsers(props *model.UserSearch, options *model.UserSearchOptions) ([]*model.User, *model.AppError)
|
||||||
SearchUsersInChannel(channelId string, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError)
|
SearchUsersInChannel(channelID string, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError)
|
||||||
SearchUsersInGroup(groupID string, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError)
|
SearchUsersInGroup(groupID string, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError)
|
||||||
SearchUsersInTeam(teamID, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError)
|
SearchUsersInTeam(teamID, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError)
|
||||||
SearchUsersNotInChannel(teamID string, channelId string, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError)
|
SearchUsersNotInChannel(teamID string, channelID string, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError)
|
||||||
SearchUsersNotInTeam(notInTeamId string, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError)
|
SearchUsersNotInTeam(notInTeamId string, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError)
|
||||||
SearchUsersWithoutTeam(term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError)
|
SearchUsersWithoutTeam(term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError)
|
||||||
SendAckToPushProxy(ack *model.PushNotificationAck) error
|
SendAckToPushProxy(ack *model.PushNotificationAck) error
|
||||||
@@ -922,13 +922,13 @@ type AppIface interface {
|
|||||||
SessionHasPermissionTo(session model.Session, permission *model.Permission) bool
|
SessionHasPermissionTo(session model.Session, permission *model.Permission) bool
|
||||||
SessionHasPermissionToAny(session model.Session, permissions []*model.Permission) bool
|
SessionHasPermissionToAny(session model.Session, permissions []*model.Permission) bool
|
||||||
SessionHasPermissionToCategory(session model.Session, userID, teamID, categoryId string) bool
|
SessionHasPermissionToCategory(session model.Session, userID, teamID, categoryId string) bool
|
||||||
SessionHasPermissionToChannel(session model.Session, channelId string, permission *model.Permission) bool
|
SessionHasPermissionToChannel(session model.Session, channelID string, permission *model.Permission) bool
|
||||||
SessionHasPermissionToChannelByPost(session model.Session, postId string, permission *model.Permission) bool
|
SessionHasPermissionToChannelByPost(session model.Session, postID string, permission *model.Permission) bool
|
||||||
SessionHasPermissionToTeam(session model.Session, teamID string, permission *model.Permission) bool
|
SessionHasPermissionToTeam(session model.Session, teamID string, permission *model.Permission) bool
|
||||||
SessionHasPermissionToUser(session model.Session, userID string) bool
|
SessionHasPermissionToUser(session model.Session, userID string) bool
|
||||||
SessionHasPermissionToUserOrBot(session model.Session, userID string) bool
|
SessionHasPermissionToUserOrBot(session model.Session, userID string) bool
|
||||||
SetAcceptLanguage(s string)
|
SetAcceptLanguage(s string)
|
||||||
SetActiveChannel(userID string, channelId string) *model.AppError
|
SetActiveChannel(userID string, channelID string) *model.AppError
|
||||||
SetAutoResponderStatus(user *model.User, oldNotifyProps model.StringMap)
|
SetAutoResponderStatus(user *model.User, oldNotifyProps model.StringMap)
|
||||||
SetContext(c context.Context)
|
SetContext(c context.Context)
|
||||||
SetCustomStatus(userID string, cs *model.CustomStatus) *model.AppError
|
SetCustomStatus(userID string, cs *model.CustomStatus) *model.AppError
|
||||||
@@ -936,9 +936,9 @@ type AppIface interface {
|
|||||||
SetIpAddress(s string)
|
SetIpAddress(s string)
|
||||||
SetPath(s string)
|
SetPath(s string)
|
||||||
SetPhase2PermissionsMigrationStatus(isComplete bool) error
|
SetPhase2PermissionsMigrationStatus(isComplete bool) error
|
||||||
SetPluginKey(pluginId string, key string, value []byte) *model.AppError
|
SetPluginKey(pluginID string, key string, value []byte) *model.AppError
|
||||||
SetPluginKeyWithExpiry(pluginId string, key string, value []byte, expireInSeconds int64) *model.AppError
|
SetPluginKeyWithExpiry(pluginID string, key string, value []byte, expireInSeconds int64) *model.AppError
|
||||||
SetPluginKeyWithOptions(pluginId string, key string, value []byte, options model.PluginKVSetOptions) (bool, *model.AppError)
|
SetPluginKeyWithOptions(pluginID string, key string, value []byte, options model.PluginKVSetOptions) (bool, *model.AppError)
|
||||||
SetPluginsEnvironment(pluginsEnvironment *plugin.Environment)
|
SetPluginsEnvironment(pluginsEnvironment *plugin.Environment)
|
||||||
SetProfileImage(userID string, imageData *multipart.FileHeader) *model.AppError
|
SetProfileImage(userID string, imageData *multipart.FileHeader) *model.AppError
|
||||||
SetProfileImageFromFile(userID string, file io.Reader) *model.AppError
|
SetProfileImageFromFile(userID string, file io.Reader) *model.AppError
|
||||||
@@ -979,16 +979,16 @@ type AppIface interface {
|
|||||||
TestLdap() *model.AppError
|
TestLdap() *model.AppError
|
||||||
TestSiteURL(siteURL string) *model.AppError
|
TestSiteURL(siteURL string) *model.AppError
|
||||||
Timezones() *timezones.Timezones
|
Timezones() *timezones.Timezones
|
||||||
ToggleMuteChannel(channelId, userID string) (*model.ChannelMember, *model.AppError)
|
ToggleMuteChannel(channelID, userID string) (*model.ChannelMember, *model.AppError)
|
||||||
TotalWebsocketConnections() int
|
TotalWebsocketConnections() int
|
||||||
TriggerWebhook(payload *model.OutgoingWebhookPayload, hook *model.OutgoingWebhook, post *model.Post, channel *model.Channel)
|
TriggerWebhook(payload *model.OutgoingWebhookPayload, hook *model.OutgoingWebhook, post *model.Post, channel *model.Channel)
|
||||||
UnregisterPluginCommand(pluginId, teamID, trigger string)
|
UnregisterPluginCommand(pluginID, teamID, trigger string)
|
||||||
UnregisterPluginCommands(pluginId string)
|
UnregisterPluginCommands(pluginID string)
|
||||||
UpdateActive(user *model.User, active bool) (*model.User, *model.AppError)
|
UpdateActive(user *model.User, active bool) (*model.User, *model.AppError)
|
||||||
UpdateChannelLastViewedAt(channelIds []string, userID string) *model.AppError
|
UpdateChannelLastViewedAt(channelIDs []string, userID string) *model.AppError
|
||||||
UpdateChannelMemberNotifyProps(data map[string]string, channelId string, userID string) (*model.ChannelMember, *model.AppError)
|
UpdateChannelMemberNotifyProps(data map[string]string, channelID string, userID string) (*model.ChannelMember, *model.AppError)
|
||||||
UpdateChannelMemberRoles(channelId string, userID string, newRoles string) (*model.ChannelMember, *model.AppError)
|
UpdateChannelMemberRoles(channelID string, userID string, newRoles string) (*model.ChannelMember, *model.AppError)
|
||||||
UpdateChannelMemberSchemeRoles(channelId string, userID string, isSchemeGuest bool, isSchemeUser bool, isSchemeAdmin bool) (*model.ChannelMember, *model.AppError)
|
UpdateChannelMemberSchemeRoles(channelID string, userID string, isSchemeGuest bool, isSchemeUser bool, isSchemeAdmin bool) (*model.ChannelMember, *model.AppError)
|
||||||
UpdateChannelPrivacy(oldChannel *model.Channel, user *model.User) (*model.Channel, *model.AppError)
|
UpdateChannelPrivacy(oldChannel *model.Channel, user *model.User) (*model.Channel, *model.AppError)
|
||||||
UpdateCommand(oldCmd, updatedCmd *model.Command) (*model.Command, *model.AppError)
|
UpdateCommand(oldCmd, updatedCmd *model.Command) (*model.Command, *model.AppError)
|
||||||
UpdateConfig(f func(*model.Config))
|
UpdateConfig(f func(*model.Config))
|
||||||
@@ -1032,7 +1032,7 @@ type AppIface interface {
|
|||||||
UpdateUserRolesWithUser(user *model.User, newRoles string, sendWebSocketEvent bool) (*model.User, *model.AppError)
|
UpdateUserRolesWithUser(user *model.User, newRoles string, sendWebSocketEvent bool) (*model.User, *model.AppError)
|
||||||
UploadData(us *model.UploadSession, rd io.Reader) (*model.FileInfo, *model.AppError)
|
UploadData(us *model.UploadSession, rd io.Reader) (*model.FileInfo, *model.AppError)
|
||||||
UploadEmojiImage(id string, imageData *multipart.FileHeader) *model.AppError
|
UploadEmojiImage(id string, imageData *multipart.FileHeader) *model.AppError
|
||||||
UploadMultipartFiles(teamID string, channelId string, userID string, fileHeaders []*multipart.FileHeader, clientIds []string, now time.Time) (*model.FileUploadResponse, *model.AppError)
|
UploadMultipartFiles(teamID string, channelID string, userID string, fileHeaders []*multipart.FileHeader, clientIds []string, now time.Time) (*model.FileUploadResponse, *model.AppError)
|
||||||
UpsertGroupMember(groupID string, userID string) (*model.GroupMember, *model.AppError)
|
UpsertGroupMember(groupID string, userID string) (*model.GroupMember, *model.AppError)
|
||||||
UpsertGroupSyncable(groupSyncable *model.GroupSyncable) (*model.GroupSyncable, *model.AppError)
|
UpsertGroupSyncable(groupSyncable *model.GroupSyncable) (*model.GroupSyncable, *model.AppError)
|
||||||
UserAgent() string
|
UserAgent() string
|
||||||
@@ -1040,6 +1040,6 @@ type AppIface interface {
|
|||||||
VerifyEmailFromToken(userSuppliedTokenString string) *model.AppError
|
VerifyEmailFromToken(userSuppliedTokenString string) *model.AppError
|
||||||
VerifyUserEmail(userID, email string) *model.AppError
|
VerifyUserEmail(userID, email string) *model.AppError
|
||||||
ViewChannel(view *model.ChannelView, userID string, currentSessionId string) (map[string]int64, *model.AppError)
|
ViewChannel(view *model.ChannelView, userID string, currentSessionId string) (map[string]int64, *model.AppError)
|
||||||
WaitForChannelMembership(channelId string, userID string)
|
WaitForChannelMembership(channelID string, userID string)
|
||||||
WriteFile(fr io.Reader, path string) (int64, *model.AppError)
|
WriteFile(fr io.Reader, path string) (int64, *model.AppError)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,8 +54,8 @@ func (a *App) SessionHasPermissionToTeam(session model.Session, teamID string, p
|
|||||||
return a.RolesGrantPermission(session.GetUserRoles(), permission.Id)
|
return a.RolesGrantPermission(session.GetUserRoles(), permission.Id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) SessionHasPermissionToChannel(session model.Session, channelId string, permission *model.Permission) bool {
|
func (a *App) SessionHasPermissionToChannel(session model.Session, channelID string, permission *model.Permission) bool {
|
||||||
if channelId == "" {
|
if channelID == "" {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,7 +63,7 @@ func (a *App) SessionHasPermissionToChannel(session model.Session, channelId str
|
|||||||
|
|
||||||
var channelRoles []string
|
var channelRoles []string
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if roles, ok := ids[channelId]; ok {
|
if roles, ok := ids[channelID]; ok {
|
||||||
channelRoles = strings.Fields(roles)
|
channelRoles = strings.Fields(roles)
|
||||||
if a.RolesGrantPermission(channelRoles, permission.Id) {
|
if a.RolesGrantPermission(channelRoles, permission.Id) {
|
||||||
return true
|
return true
|
||||||
@@ -71,7 +71,7 @@ func (a *App) SessionHasPermissionToChannel(session model.Session, channelId str
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
channel, appErr := a.GetChannel(channelId)
|
channel, appErr := a.GetChannel(channelID)
|
||||||
if appErr != nil && appErr.StatusCode == http.StatusNotFound {
|
if appErr != nil && appErr.StatusCode == http.StatusNotFound {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -87,15 +87,15 @@ func (a *App) SessionHasPermissionToChannel(session model.Session, channelId str
|
|||||||
return a.SessionHasPermissionTo(session, permission)
|
return a.SessionHasPermissionTo(session, permission)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) SessionHasPermissionToChannelByPost(session model.Session, postId string, permission *model.Permission) bool {
|
func (a *App) SessionHasPermissionToChannelByPost(session model.Session, postID string, permission *model.Permission) bool {
|
||||||
if channelMember, err := a.Srv().Store.Channel().GetMemberForPost(postId, session.UserId); err == nil {
|
if channelMember, err := a.Srv().Store.Channel().GetMemberForPost(postID, session.UserId); err == nil {
|
||||||
|
|
||||||
if a.RolesGrantPermission(channelMember.GetRoles(), permission.Id) {
|
if a.RolesGrantPermission(channelMember.GetRoles(), permission.Id) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if channel, err := a.Srv().Store.Channel().GetForPost(postId); err == nil {
|
if channel, err := a.Srv().Store.Channel().GetForPost(postID); err == nil {
|
||||||
if channel.TeamId != "" {
|
if channel.TeamId != "" {
|
||||||
return a.SessionHasPermissionToTeam(session, channel.TeamId, permission)
|
return a.SessionHasPermissionToTeam(session, channel.TeamId, permission)
|
||||||
}
|
}
|
||||||
@@ -170,12 +170,12 @@ func (a *App) HasPermissionToTeam(askingUserId string, teamID string, permission
|
|||||||
return a.HasPermissionTo(askingUserId, permission)
|
return a.HasPermissionTo(askingUserId, permission)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) HasPermissionToChannel(askingUserId string, channelId string, permission *model.Permission) bool {
|
func (a *App) HasPermissionToChannel(askingUserId string, channelID string, permission *model.Permission) bool {
|
||||||
if channelId == "" || askingUserId == "" {
|
if channelID == "" || askingUserId == "" {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
channelMember, err := a.GetChannelMember(channelId, askingUserId)
|
channelMember, err := a.GetChannelMember(channelID, askingUserId)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
roles := channelMember.GetRoles()
|
roles := channelMember.GetRoles()
|
||||||
if a.RolesGrantPermission(roles, permission.Id) {
|
if a.RolesGrantPermission(roles, permission.Id) {
|
||||||
@@ -184,7 +184,7 @@ func (a *App) HasPermissionToChannel(askingUserId string, channelId string, perm
|
|||||||
}
|
}
|
||||||
|
|
||||||
var channel *model.Channel
|
var channel *model.Channel
|
||||||
channel, err = a.GetChannel(channelId)
|
channel, err = a.GetChannel(channelID)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return a.HasPermissionToTeam(askingUserId, channel.TeamId, permission)
|
return a.HasPermissionToTeam(askingUserId, channel.TeamId, permission)
|
||||||
}
|
}
|
||||||
@@ -192,14 +192,14 @@ func (a *App) HasPermissionToChannel(askingUserId string, channelId string, perm
|
|||||||
return a.HasPermissionTo(askingUserId, permission)
|
return a.HasPermissionTo(askingUserId, permission)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) HasPermissionToChannelByPost(askingUserId string, postId string, permission *model.Permission) bool {
|
func (a *App) HasPermissionToChannelByPost(askingUserId string, postID string, permission *model.Permission) bool {
|
||||||
if channelMember, err := a.Srv().Store.Channel().GetMemberForPost(postId, askingUserId); err == nil {
|
if channelMember, err := a.Srv().Store.Channel().GetMemberForPost(postID, askingUserId); err == nil {
|
||||||
if a.RolesGrantPermission(channelMember.GetRoles(), permission.Id) {
|
if a.RolesGrantPermission(channelMember.GetRoles(), permission.Id) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if channel, err := a.Srv().Store.Channel().GetForPost(postId); err == nil {
|
if channel, err := a.Srv().Store.Channel().GetForPost(postID); err == nil {
|
||||||
return a.HasPermissionToTeam(askingUserId, channel.TeamId, permission)
|
return a.HasPermissionToTeam(askingUserId, channel.TeamId, permission)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
134
app/channel.go
134
app/channel.go
@@ -464,7 +464,7 @@ func (a *App) createDirectChannelWithUser(user, otherUser *model.User) (*model.C
|
|||||||
return channel, nil
|
return channel, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) WaitForChannelMembership(channelId string, userID string) {
|
func (a *App) WaitForChannelMembership(channelID string, userID string) {
|
||||||
if len(a.Config().SqlSettings.DataSourceReplicas) == 0 {
|
if len(a.Config().SqlSettings.DataSourceReplicas) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -475,7 +475,7 @@ func (a *App) WaitForChannelMembership(channelId string, userID string) {
|
|||||||
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
time.Sleep(100 * time.Millisecond)
|
||||||
|
|
||||||
_, err := a.Srv().Store.Channel().GetMember(channelId, userID)
|
_, err := a.Srv().Store.Channel().GetMember(channelID, userID)
|
||||||
|
|
||||||
// If the membership was found then return
|
// If the membership was found then return
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@@ -489,7 +489,7 @@ func (a *App) WaitForChannelMembership(channelId string, userID string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mlog.Error("WaitForChannelMembership giving up", mlog.String("channel_id", channelId), mlog.String("user_id", userID))
|
mlog.Error("WaitForChannelMembership giving up", mlog.String("channel_id", channelID), mlog.String("user_id", userID))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) CreateGroupChannel(userIDs []string, creatorId string) (*model.Channel, *model.AppError) {
|
func (a *App) CreateGroupChannel(userIDs []string, creatorId string) (*model.Channel, *model.AppError) {
|
||||||
@@ -811,8 +811,8 @@ func (a *App) PatchChannel(channel *model.Channel, patch *model.ChannelPatch, us
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetSchemeRolesForChannel Checks if a channel or its team has an override scheme for channel roles and returns the scheme roles or default channel roles.
|
// GetSchemeRolesForChannel Checks if a channel or its team has an override scheme for channel roles and returns the scheme roles or default channel roles.
|
||||||
func (a *App) GetSchemeRolesForChannel(channelId string) (guestRoleName, userRoleName, adminRoleName string, err *model.AppError) {
|
func (a *App) GetSchemeRolesForChannel(channelID string) (guestRoleName, userRoleName, adminRoleName string, err *model.AppError) {
|
||||||
channel, err := a.GetChannel(channelId)
|
channel, err := a.GetChannel(channelID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -1074,14 +1074,14 @@ func buildChannelModerations(channelType string, memberRole *model.Role, guestRo
|
|||||||
return channelModerations
|
return channelModerations
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) UpdateChannelMemberRoles(channelId string, userID string, newRoles string) (*model.ChannelMember, *model.AppError) {
|
func (a *App) UpdateChannelMemberRoles(channelID string, userID string, newRoles string) (*model.ChannelMember, *model.AppError) {
|
||||||
var member *model.ChannelMember
|
var member *model.ChannelMember
|
||||||
var err *model.AppError
|
var err *model.AppError
|
||||||
if member, err = a.GetChannelMember(channelId, userID); err != nil {
|
if member, err = a.GetChannelMember(channelID, userID); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
schemeGuestRole, schemeUserRole, schemeAdminRole, err := a.GetSchemeRolesForChannel(channelId)
|
schemeGuestRole, schemeUserRole, schemeAdminRole, err := a.GetSchemeRolesForChannel(channelID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -1133,8 +1133,8 @@ func (a *App) UpdateChannelMemberRoles(channelId string, userID string, newRoles
|
|||||||
return a.updateChannelMember(member)
|
return a.updateChannelMember(member)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) UpdateChannelMemberSchemeRoles(channelId string, userID string, isSchemeGuest bool, isSchemeUser bool, isSchemeAdmin bool) (*model.ChannelMember, *model.AppError) {
|
func (a *App) UpdateChannelMemberSchemeRoles(channelID string, userID string, isSchemeGuest bool, isSchemeUser bool, isSchemeAdmin bool) (*model.ChannelMember, *model.AppError) {
|
||||||
member, err := a.GetChannelMember(channelId, userID)
|
member, err := a.GetChannelMember(channelID, userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -1155,10 +1155,10 @@ func (a *App) UpdateChannelMemberSchemeRoles(channelId string, userID string, is
|
|||||||
return a.updateChannelMember(member)
|
return a.updateChannelMember(member)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) UpdateChannelMemberNotifyProps(data map[string]string, channelId string, userID string) (*model.ChannelMember, *model.AppError) {
|
func (a *App) UpdateChannelMemberNotifyProps(data map[string]string, channelID string, userID string) (*model.ChannelMember, *model.AppError) {
|
||||||
var member *model.ChannelMember
|
var member *model.ChannelMember
|
||||||
var err *model.AppError
|
var err *model.AppError
|
||||||
if member, err = a.GetChannelMember(channelId, userID); err != nil {
|
if member, err = a.GetChannelMember(channelID, userID); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1586,8 +1586,8 @@ func (a *App) PostUpdateChannelDisplayNameMessage(userID string, channel *model.
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetChannel(channelId string) (*model.Channel, *model.AppError) {
|
func (a *App) GetChannel(channelID string) (*model.Channel, *model.AppError) {
|
||||||
channel, err := a.Srv().Store.Channel().Get(channelId, true)
|
channel, err := a.Srv().Store.Channel().Get(channelID, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
var nfErr *store.ErrNotFound
|
var nfErr *store.ErrNotFound
|
||||||
switch {
|
switch {
|
||||||
@@ -1739,8 +1739,8 @@ func (a *App) GetChannelsUserNotIn(teamID string, userID string, offset int, lim
|
|||||||
return channels, nil
|
return channels, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetPublicChannelsByIdsForTeam(teamID string, channelIds []string) (*model.ChannelList, *model.AppError) {
|
func (a *App) GetPublicChannelsByIdsForTeam(teamID string, channelIDs []string) (*model.ChannelList, *model.AppError) {
|
||||||
list, err := a.Srv().Store.Channel().GetPublicChannelsByIdsForTeam(teamID, channelIds)
|
list, err := a.Srv().Store.Channel().GetPublicChannelsByIdsForTeam(teamID, channelIDs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
var nfErr *store.ErrNotFound
|
var nfErr *store.ErrNotFound
|
||||||
switch {
|
switch {
|
||||||
@@ -1772,8 +1772,8 @@ func (a *App) GetPrivateChannelsForTeam(teamID string, offset int, limit int) (*
|
|||||||
return list, nil
|
return list, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetChannelMember(channelId string, userID string) (*model.ChannelMember, *model.AppError) {
|
func (a *App) GetChannelMember(channelID string, userID string) (*model.ChannelMember, *model.AppError) {
|
||||||
channelMember, err := a.Srv().Store.Channel().GetMember(channelId, userID)
|
channelMember, err := a.Srv().Store.Channel().GetMember(channelID, userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
var nfErr *store.ErrNotFound
|
var nfErr *store.ErrNotFound
|
||||||
switch {
|
switch {
|
||||||
@@ -1787,8 +1787,8 @@ func (a *App) GetChannelMember(channelId string, userID string) (*model.ChannelM
|
|||||||
return channelMember, nil
|
return channelMember, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetChannelMembersPage(channelId string, page, perPage int) (*model.ChannelMembers, *model.AppError) {
|
func (a *App) GetChannelMembersPage(channelID string, page, perPage int) (*model.ChannelMembers, *model.AppError) {
|
||||||
channelMembers, err := a.Srv().Store.Channel().GetMembers(channelId, page*perPage, perPage)
|
channelMembers, err := a.Srv().Store.Channel().GetMembers(channelID, page*perPage, perPage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, model.NewAppError("GetChannelMembersPage", "app.channel.get_members.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return nil, model.NewAppError("GetChannelMembersPage", "app.channel.get_members.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
@@ -1796,8 +1796,8 @@ func (a *App) GetChannelMembersPage(channelId string, page, perPage int) (*model
|
|||||||
return channelMembers, nil
|
return channelMembers, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetChannelMembersTimezones(channelId string) ([]string, *model.AppError) {
|
func (a *App) GetChannelMembersTimezones(channelID string) ([]string, *model.AppError) {
|
||||||
membersTimezones, err := a.Srv().Store.Channel().GetChannelMembersTimezones(channelId)
|
membersTimezones, err := a.Srv().Store.Channel().GetChannelMembersTimezones(channelID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, model.NewAppError("GetChannelMembersTimezones", "app.channel.get_members.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return nil, model.NewAppError("GetChannelMembersTimezones", "app.channel.get_members.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
@@ -1813,8 +1813,8 @@ func (a *App) GetChannelMembersTimezones(channelId string) ([]string, *model.App
|
|||||||
return model.RemoveDuplicateStrings(timezones), nil
|
return model.RemoveDuplicateStrings(timezones), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetChannelMembersByIds(channelId string, userIDs []string) (*model.ChannelMembers, *model.AppError) {
|
func (a *App) GetChannelMembersByIds(channelID string, userIDs []string) (*model.ChannelMembers, *model.AppError) {
|
||||||
members, err := a.Srv().Store.Channel().GetMembersByIds(channelId, userIDs)
|
members, err := a.Srv().Store.Channel().GetMembersByIds(channelID, userIDs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, model.NewAppError("GetChannelMembersByIds", "app.channel.get_members_by_ids.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return nil, model.NewAppError("GetChannelMembersByIds", "app.channel.get_members_by_ids.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
@@ -1847,8 +1847,8 @@ func (a *App) GetChannelMembersForUserWithPagination(teamID, userID string, page
|
|||||||
return members, nil
|
return members, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetChannelMemberCount(channelId string) (int64, *model.AppError) {
|
func (a *App) GetChannelMemberCount(channelID string) (int64, *model.AppError) {
|
||||||
count, err := a.Srv().Store.Channel().GetMemberCount(channelId, true)
|
count, err := a.Srv().Store.Channel().GetMemberCount(channelID, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, model.NewAppError("GetChannelMemberCount", "app.channel.get_member_count.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return 0, model.NewAppError("GetChannelMemberCount", "app.channel.get_member_count.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
@@ -1856,8 +1856,8 @@ func (a *App) GetChannelMemberCount(channelId string) (int64, *model.AppError) {
|
|||||||
return count, nil
|
return count, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetChannelGuestCount(channelId string) (int64, *model.AppError) {
|
func (a *App) GetChannelGuestCount(channelID string) (int64, *model.AppError) {
|
||||||
count, err := a.Srv().Store.Channel().GetGuestCount(channelId, true)
|
count, err := a.Srv().Store.Channel().GetGuestCount(channelID, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, model.NewAppError("SqlChannelStore.GetGuestCount", "app.channel.get_member_count.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return 0, model.NewAppError("SqlChannelStore.GetGuestCount", "app.channel.get_member_count.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
@@ -1865,8 +1865,8 @@ func (a *App) GetChannelGuestCount(channelId string) (int64, *model.AppError) {
|
|||||||
return count, nil
|
return count, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetChannelPinnedPostCount(channelId string) (int64, *model.AppError) {
|
func (a *App) GetChannelPinnedPostCount(channelID string) (int64, *model.AppError) {
|
||||||
count, err := a.Srv().Store.Channel().GetPinnedPostCount(channelId, true)
|
count, err := a.Srv().Store.Channel().GetPinnedPostCount(channelID, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, model.NewAppError("GetChannelPinnedPostCount", "app.channel.get_pinnedpost_count.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return 0, model.NewAppError("GetChannelPinnedPostCount", "app.channel.get_pinnedpost_count.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
@@ -1883,8 +1883,8 @@ func (a *App) GetChannelCounts(teamID string, userID string) (*model.ChannelCoun
|
|||||||
return counts, nil
|
return counts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetChannelUnread(channelId, userID string) (*model.ChannelUnread, *model.AppError) {
|
func (a *App) GetChannelUnread(channelID, userID string) (*model.ChannelUnread, *model.AppError) {
|
||||||
channelUnread, err := a.Srv().Store.Channel().GetChannelUnread(channelId, userID)
|
channelUnread, err := a.Srv().Store.Channel().GetChannelUnread(channelID, userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
var nfErr *store.ErrNotFound
|
var nfErr *store.ErrNotFound
|
||||||
switch {
|
switch {
|
||||||
@@ -2005,10 +2005,10 @@ func (a *App) postJoinTeamMessage(user *model.User, channel *model.Channel) *mod
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) LeaveChannel(channelId string, userID string) *model.AppError {
|
func (a *App) LeaveChannel(channelID string, userID string) *model.AppError {
|
||||||
sc := make(chan store.StoreResult, 1)
|
sc := make(chan store.StoreResult, 1)
|
||||||
go func() {
|
go func() {
|
||||||
channel, err := a.Srv().Store.Channel().Get(channelId, true)
|
channel, err := a.Srv().Store.Channel().Get(channelID, true)
|
||||||
sc <- store.StoreResult{Data: channel, NErr: err}
|
sc <- store.StoreResult{Data: channel, NErr: err}
|
||||||
close(sc)
|
close(sc)
|
||||||
}()
|
}()
|
||||||
@@ -2022,7 +2022,7 @@ func (a *App) LeaveChannel(channelId string, userID string) *model.AppError {
|
|||||||
|
|
||||||
mcc := make(chan store.StoreResult, 1)
|
mcc := make(chan store.StoreResult, 1)
|
||||||
go func() {
|
go func() {
|
||||||
count, err := a.Srv().Store.Channel().GetMemberCount(channelId, false)
|
count, err := a.Srv().Store.Channel().GetMemberCount(channelID, false)
|
||||||
mcc <- store.StoreResult{Data: count, NErr: err}
|
mcc <- store.StoreResult{Data: count, NErr: err}
|
||||||
close(mcc)
|
close(mcc)
|
||||||
}()
|
}()
|
||||||
@@ -2306,17 +2306,17 @@ func (a *App) GetNumberOfChannelsOnTeam(teamID string) (int, *model.AppError) {
|
|||||||
return len(*list), nil
|
return len(*list), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) SetActiveChannel(userID string, channelId string) *model.AppError {
|
func (a *App) SetActiveChannel(userID string, channelID string) *model.AppError {
|
||||||
status, err := a.GetStatus(userID)
|
status, err := a.GetStatus(userID)
|
||||||
|
|
||||||
oldStatus := model.STATUS_OFFLINE
|
oldStatus := model.STATUS_OFFLINE
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
status = &model.Status{UserId: userID, Status: model.STATUS_ONLINE, Manual: false, LastActivityAt: model.GetMillis(), ActiveChannel: channelId}
|
status = &model.Status{UserId: userID, Status: model.STATUS_ONLINE, Manual: false, LastActivityAt: model.GetMillis(), ActiveChannel: channelID}
|
||||||
} else {
|
} else {
|
||||||
oldStatus = status.Status
|
oldStatus = status.Status
|
||||||
status.ActiveChannel = channelId
|
status.ActiveChannel = channelID
|
||||||
if !status.Manual && channelId != "" {
|
if !status.Manual && channelID != "" {
|
||||||
status.Status = model.STATUS_ONLINE
|
status.Status = model.STATUS_ONLINE
|
||||||
}
|
}
|
||||||
status.LastActivityAt = model.GetMillis()
|
status.LastActivityAt = model.GetMillis()
|
||||||
@@ -2331,8 +2331,8 @@ func (a *App) SetActiveChannel(userID string, channelId string) *model.AppError
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) UpdateChannelLastViewedAt(channelIds []string, userID string) *model.AppError {
|
func (a *App) UpdateChannelLastViewedAt(channelIDs []string, userID string) *model.AppError {
|
||||||
if _, err := a.Srv().Store.Channel().UpdateLastViewedAt(channelIds, userID, *a.Config().ServiceSettings.ThreadAutoFollow); err != nil {
|
if _, err := a.Srv().Store.Channel().UpdateLastViewedAt(channelIDs, userID, *a.Config().ServiceSettings.ThreadAutoFollow); err != nil {
|
||||||
var invErr *store.ErrInvalidInput
|
var invErr *store.ErrInvalidInput
|
||||||
switch {
|
switch {
|
||||||
case errors.As(err, &invErr):
|
case errors.As(err, &invErr):
|
||||||
@@ -2343,9 +2343,9 @@ func (a *App) UpdateChannelLastViewedAt(channelIds []string, userID string) *mod
|
|||||||
}
|
}
|
||||||
|
|
||||||
if *a.Config().ServiceSettings.EnableChannelViewedMessages {
|
if *a.Config().ServiceSettings.EnableChannelViewedMessages {
|
||||||
for _, channelId := range channelIds {
|
for _, channelID := range channelIDs {
|
||||||
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_CHANNEL_VIEWED, "", "", userID, nil)
|
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_CHANNEL_VIEWED, "", "", userID, nil)
|
||||||
message.Add("channel_id", channelId)
|
message.Add("channel_id", channelID)
|
||||||
a.Publish(message)
|
a.Publish(message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2518,18 +2518,18 @@ func (a *App) SearchChannelsUserNotIn(teamID string, userID string, term string)
|
|||||||
return channelList, nil
|
return channelList, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) MarkChannelsAsViewed(channelIds []string, userID string, currentSessionId string) (map[string]int64, *model.AppError) {
|
func (a *App) MarkChannelsAsViewed(channelIDs []string, userID string, currentSessionId string) (map[string]int64, *model.AppError) {
|
||||||
// I start looking for channels with notifications before I mark it as read, to clear the push notifications if needed
|
// I start looking for channels with notifications before I mark it as read, to clear the push notifications if needed
|
||||||
channelsToClearPushNotifications := []string{}
|
channelsToClearPushNotifications := []string{}
|
||||||
if *a.Config().EmailSettings.SendPushNotifications {
|
if *a.Config().EmailSettings.SendPushNotifications {
|
||||||
for _, channelId := range channelIds {
|
for _, channelID := range channelIDs {
|
||||||
channel, errCh := a.Srv().Store.Channel().Get(channelId, true)
|
channel, errCh := a.Srv().Store.Channel().Get(channelID, true)
|
||||||
if errCh != nil {
|
if errCh != nil {
|
||||||
mlog.Warn("Failed to get channel", mlog.Err(errCh))
|
mlog.Warn("Failed to get channel", mlog.Err(errCh))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
member, err := a.Srv().Store.Channel().GetMember(channelId, userID)
|
member, err := a.Srv().Store.Channel().GetMember(channelID, userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
mlog.Warn("Failed to get membership", mlog.Err(err))
|
mlog.Warn("Failed to get membership", mlog.Err(err))
|
||||||
continue
|
continue
|
||||||
@@ -2545,21 +2545,21 @@ func (a *App) MarkChannelsAsViewed(channelIds []string, userID string, currentSe
|
|||||||
notify = user.NotifyProps[model.PUSH_NOTIFY_PROP]
|
notify = user.NotifyProps[model.PUSH_NOTIFY_PROP]
|
||||||
}
|
}
|
||||||
if notify == model.USER_NOTIFY_ALL {
|
if notify == model.USER_NOTIFY_ALL {
|
||||||
if count, err := a.Srv().Store.User().GetAnyUnreadPostCountForChannel(userID, channelId); err == nil {
|
if count, err := a.Srv().Store.User().GetAnyUnreadPostCountForChannel(userID, channelID); err == nil {
|
||||||
if count > 0 {
|
if count > 0 {
|
||||||
channelsToClearPushNotifications = append(channelsToClearPushNotifications, channelId)
|
channelsToClearPushNotifications = append(channelsToClearPushNotifications, channelID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if notify == model.USER_NOTIFY_MENTION || channel.Type == model.CHANNEL_DIRECT {
|
} else if notify == model.USER_NOTIFY_MENTION || channel.Type == model.CHANNEL_DIRECT {
|
||||||
if count, err := a.Srv().Store.User().GetUnreadCountForChannel(userID, channelId); err == nil {
|
if count, err := a.Srv().Store.User().GetUnreadCountForChannel(userID, channelID); err == nil {
|
||||||
if count > 0 {
|
if count > 0 {
|
||||||
channelsToClearPushNotifications = append(channelsToClearPushNotifications, channelId)
|
channelsToClearPushNotifications = append(channelsToClearPushNotifications, channelID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
times, err := a.Srv().Store.Channel().UpdateLastViewedAt(channelIds, userID, *a.Config().ServiceSettings.ThreadAutoFollow)
|
times, err := a.Srv().Store.Channel().UpdateLastViewedAt(channelIDs, userID, *a.Config().ServiceSettings.ThreadAutoFollow)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
var invErr *store.ErrInvalidInput
|
var invErr *store.ErrInvalidInput
|
||||||
switch {
|
switch {
|
||||||
@@ -2571,14 +2571,14 @@ func (a *App) MarkChannelsAsViewed(channelIds []string, userID string, currentSe
|
|||||||
}
|
}
|
||||||
|
|
||||||
if *a.Config().ServiceSettings.EnableChannelViewedMessages {
|
if *a.Config().ServiceSettings.EnableChannelViewedMessages {
|
||||||
for _, channelId := range channelIds {
|
for _, channelID := range channelIDs {
|
||||||
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_CHANNEL_VIEWED, "", "", userID, nil)
|
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_CHANNEL_VIEWED, "", "", userID, nil)
|
||||||
message.Add("channel_id", channelId)
|
message.Add("channel_id", channelID)
|
||||||
a.Publish(message)
|
a.Publish(message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, channelId := range channelsToClearPushNotifications {
|
for _, channelID := range channelsToClearPushNotifications {
|
||||||
a.clearPushNotification(currentSessionId, userID, channelId)
|
a.clearPushNotification(currentSessionId, userID, channelID)
|
||||||
}
|
}
|
||||||
return times, nil
|
return times, nil
|
||||||
}
|
}
|
||||||
@@ -2588,21 +2588,21 @@ func (a *App) ViewChannel(view *model.ChannelView, userID string, currentSession
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
channelIds := []string{}
|
channelIDs := []string{}
|
||||||
|
|
||||||
if view.ChannelId != "" {
|
if view.ChannelId != "" {
|
||||||
channelIds = append(channelIds, view.ChannelId)
|
channelIDs = append(channelIDs, view.ChannelId)
|
||||||
}
|
}
|
||||||
|
|
||||||
if view.PrevChannelId != "" {
|
if view.PrevChannelId != "" {
|
||||||
channelIds = append(channelIds, view.PrevChannelId)
|
channelIDs = append(channelIDs, view.PrevChannelId)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(channelIds) == 0 {
|
if len(channelIDs) == 0 {
|
||||||
return map[string]int64{}, nil
|
return map[string]int64{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return a.MarkChannelsAsViewed(channelIds, userID, currentSessionId)
|
return a.MarkChannelsAsViewed(channelIDs, userID, currentSessionId)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) PermanentDeleteChannel(channel *model.Channel) *model.AppError {
|
func (a *App) PermanentDeleteChannel(channel *model.Channel) *model.AppError {
|
||||||
@@ -2807,8 +2807,8 @@ func (a *App) RemoveUsersFromChannelNotMemberOfTeam(remover *model.User, channel
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetPinnedPosts(channelId string) (*model.PostList, *model.AppError) {
|
func (a *App) GetPinnedPosts(channelID string) (*model.PostList, *model.AppError) {
|
||||||
posts, err := a.Srv().Store.Channel().GetPinnedPosts(channelId)
|
posts, err := a.Srv().Store.Channel().GetPinnedPosts(channelID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, model.NewAppError("GetPinnedPosts", "app.channel.pinned_posts.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return nil, model.NewAppError("GetPinnedPosts", "app.channel.pinned_posts.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
@@ -2816,8 +2816,8 @@ func (a *App) GetPinnedPosts(channelId string) (*model.PostList, *model.AppError
|
|||||||
return posts, nil
|
return posts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) ToggleMuteChannel(channelId, userID string) (*model.ChannelMember, *model.AppError) {
|
func (a *App) ToggleMuteChannel(channelID, userID string) (*model.ChannelMember, *model.AppError) {
|
||||||
member, nErr := a.Srv().Store.Channel().GetMember(channelId, userID)
|
member, nErr := a.Srv().Store.Channel().GetMember(channelID, userID)
|
||||||
if nErr != nil {
|
if nErr != nil {
|
||||||
var appErr *model.AppError
|
var appErr *model.AppError
|
||||||
var nfErr *store.ErrNotFound
|
var nfErr *store.ErrNotFound
|
||||||
@@ -2843,8 +2843,8 @@ func (a *App) ToggleMuteChannel(channelId, userID string) (*model.ChannelMember,
|
|||||||
return member, nil
|
return member, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) setChannelsMuted(channelIds []string, userID string, muted bool) ([]*model.ChannelMember, *model.AppError) {
|
func (a *App) setChannelsMuted(channelIDs []string, userID string, muted bool) ([]*model.ChannelMember, *model.AppError) {
|
||||||
members, nErr := a.Srv().Store.Channel().GetMembersByChannelIds(channelIds, userID)
|
members, nErr := a.Srv().Store.Channel().GetMembersByChannelIds(channelIDs, userID)
|
||||||
if nErr != nil {
|
if nErr != nil {
|
||||||
var appErr *model.AppError
|
var appErr *model.AppError
|
||||||
switch {
|
switch {
|
||||||
|
|||||||
@@ -191,14 +191,14 @@ func (a *App) muteChannelsForUpdatedCategories(userID string, updatedCategories
|
|||||||
updatedCategoriesById := makeCategoryMap(updatedCategories)
|
updatedCategoriesById := makeCategoryMap(updatedCategories)
|
||||||
originalCategoriesById := makeCategoryMap(originalCategories)
|
originalCategoriesById := makeCategoryMap(originalCategories)
|
||||||
|
|
||||||
for channelId, diff := range channelsDiff {
|
for channelID, diff := range channelsDiff {
|
||||||
fromCategory := originalCategoriesById[diff.fromCategoryId]
|
fromCategory := originalCategoriesById[diff.fromCategoryId]
|
||||||
toCategory := updatedCategoriesById[diff.toCategoryId]
|
toCategory := updatedCategoriesById[diff.toCategoryId]
|
||||||
|
|
||||||
if toCategory.Muted && !fromCategory.Muted {
|
if toCategory.Muted && !fromCategory.Muted {
|
||||||
channelsToMute = append(channelsToMute, channelId)
|
channelsToMute = append(channelsToMute, channelID)
|
||||||
} else if !toCategory.Muted && fromCategory.Muted {
|
} else if !toCategory.Muted && fromCategory.Muted {
|
||||||
channelsToUnmute = append(channelsToUnmute, channelId)
|
channelsToUnmute = append(channelsToUnmute, channelID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -236,8 +236,8 @@ func diffChannelsBetweenCategories(updatedCategories []*model.SidebarCategoryWit
|
|||||||
mapChannelIdsToCategories := func(categories []*model.SidebarCategoryWithChannels) map[string]string {
|
mapChannelIdsToCategories := func(categories []*model.SidebarCategoryWithChannels) map[string]string {
|
||||||
result := make(map[string]string)
|
result := make(map[string]string)
|
||||||
for _, category := range categories {
|
for _, category := range categories {
|
||||||
for _, channelId := range category.Channels {
|
for _, channelID := range category.Channels {
|
||||||
result[channelId] = category.Id
|
result[channelID] = category.Id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -250,11 +250,11 @@ func diffChannelsBetweenCategories(updatedCategories []*model.SidebarCategoryWit
|
|||||||
// Check for any channels that have changed categories. Note that we don't worry about any channels that have moved
|
// Check for any channels that have changed categories. Note that we don't worry about any channels that have moved
|
||||||
// outside of these categories since that heavily complicates things and doesn't currently happen in our apps.
|
// outside of these categories since that heavily complicates things and doesn't currently happen in our apps.
|
||||||
channelsDiff := make(map[string]*categoryChannelDiff)
|
channelsDiff := make(map[string]*categoryChannelDiff)
|
||||||
for channelId, originalCategoryId := range originalChannelIdsMap {
|
for channelID, originalCategoryId := range originalChannelIdsMap {
|
||||||
updatedCategoryId := updatedChannelIdsMap[channelId]
|
updatedCategoryId := updatedChannelIdsMap[channelID]
|
||||||
|
|
||||||
if originalCategoryId != updatedCategoryId && updatedCategoryId != "" {
|
if originalCategoryId != updatedCategoryId && updatedCategoryId != "" {
|
||||||
channelsDiff[channelId] = &categoryChannelDiff{originalCategoryId, updatedCategoryId}
|
channelsDiff[channelID] = &categoryChannelDiff{originalCategoryId, updatedCategoryId}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -434,16 +434,16 @@ func (es *EmailService) sendGuestInviteEmails(team *model.Team, channels []*mode
|
|||||||
map[string]interface{}{"TeamDisplayName": team.DisplayName})
|
map[string]interface{}{"TeamDisplayName": team.DisplayName})
|
||||||
bodyPage.Props["TeamURL"] = siteURL + "/" + team.Name
|
bodyPage.Props["TeamURL"] = siteURL + "/" + team.Name
|
||||||
|
|
||||||
channelIds := []string{}
|
channelIDs := []string{}
|
||||||
for _, channel := range channels {
|
for _, channel := range channels {
|
||||||
channelIds = append(channelIds, channel.Id)
|
channelIDs = append(channelIDs, channel.Id)
|
||||||
}
|
}
|
||||||
|
|
||||||
token := model.NewToken(
|
token := model.NewToken(
|
||||||
TokenTypeGuestInvitation,
|
TokenTypeGuestInvitation,
|
||||||
model.MapToJson(map[string]string{
|
model.MapToJson(map[string]string{
|
||||||
"teamId": team.Id,
|
"teamId": team.Id,
|
||||||
"channels": strings.Join(channelIds, " "),
|
"channels": strings.Join(channelIDs, " "),
|
||||||
"email": invite,
|
"email": invite,
|
||||||
"guest": "true",
|
"guest": "true",
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -44,20 +44,20 @@ func TestNotifySessionsExpired(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
data := []struct {
|
data := []struct {
|
||||||
deviceId string
|
deviceID string
|
||||||
expiresAt int64
|
expiresAt int64
|
||||||
notified bool
|
notified bool
|
||||||
}{
|
}{
|
||||||
{deviceId: "android:11111", expiresAt: model.GetMillis() + 100000, notified: false},
|
{deviceID: "android:11111", expiresAt: model.GetMillis() + 100000, notified: false},
|
||||||
{deviceId: "android:22222", expiresAt: model.GetMillis() - 1000, notified: false},
|
{deviceID: "android:22222", expiresAt: model.GetMillis() - 1000, notified: false},
|
||||||
{deviceId: "android:33333", expiresAt: model.GetMillis() - 2000, notified: false},
|
{deviceID: "android:33333", expiresAt: model.GetMillis() - 2000, notified: false},
|
||||||
{deviceId: "android:44444", expiresAt: model.GetMillis() - 3000, notified: true},
|
{deviceID: "android:44444", expiresAt: model.GetMillis() - 3000, notified: true},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, d := range data {
|
for _, d := range data {
|
||||||
_, err := th.App.CreateSession(&model.Session{
|
_, err := th.App.CreateSession(&model.Session{
|
||||||
UserId: th.BasicUser.Id,
|
UserId: th.BasicUser.Id,
|
||||||
DeviceId: d.deviceId,
|
DeviceId: d.deviceID,
|
||||||
ExpiresAt: d.expiresAt,
|
ExpiresAt: d.expiresAt,
|
||||||
ExpiredNotify: d.notified,
|
ExpiredNotify: d.notified,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -440,11 +440,11 @@ func (a *App) exportAllPosts(writer io.Writer, withAttachments bool) ([]Attachme
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) buildPostReplies(postId string, withAttachments bool) ([]ReplyImportData, []AttachmentImportData, *model.AppError) {
|
func (a *App) buildPostReplies(postID string, withAttachments bool) ([]ReplyImportData, []AttachmentImportData, *model.AppError) {
|
||||||
var replies []ReplyImportData
|
var replies []ReplyImportData
|
||||||
var attachments []AttachmentImportData
|
var attachments []AttachmentImportData
|
||||||
|
|
||||||
replyPosts, nErr := a.Srv().Store.Post().GetRepliesForExport(postId)
|
replyPosts, nErr := a.Srv().Store.Post().GetRepliesForExport(postID)
|
||||||
if nErr != nil {
|
if nErr != nil {
|
||||||
return nil, nil, model.NewAppError("buildPostReplies", "app.post.get_posts.app_error", nil, nErr.Error(), http.StatusInternalServerError)
|
return nil, nil, model.NewAppError("buildPostReplies", "app.post.get_posts.app_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
@@ -475,10 +475,10 @@ func (a *App) buildPostReplies(postId string, withAttachments bool) ([]ReplyImpo
|
|||||||
return replies, attachments, nil
|
return replies, attachments, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) BuildPostReactions(postId string) (*[]ReactionImportData, *model.AppError) {
|
func (a *App) BuildPostReactions(postID string) (*[]ReactionImportData, *model.AppError) {
|
||||||
var reactionsOfPost []ReactionImportData
|
var reactionsOfPost []ReactionImportData
|
||||||
|
|
||||||
reactions, nErr := a.Srv().Store.Reaction().GetForPost(postId, true)
|
reactions, nErr := a.Srv().Store.Reaction().GetForPost(postID, true)
|
||||||
if nErr != nil {
|
if nErr != nil {
|
||||||
return nil, model.NewAppError("BuildPostReactions", "app.reaction.get_for_post.app_error", nil, nErr.Error(), http.StatusInternalServerError)
|
return nil, model.NewAppError("BuildPostReactions", "app.reaction.get_for_post.app_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
@@ -500,8 +500,8 @@ func (a *App) BuildPostReactions(postId string) (*[]ReactionImportData, *model.A
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) buildPostAttachments(postId string) ([]AttachmentImportData, *model.AppError) {
|
func (a *App) buildPostAttachments(postID string) ([]AttachmentImportData, *model.AppError) {
|
||||||
infos, nErr := a.Srv().Store.FileInfo().GetForPost(postId, false, false, false)
|
infos, nErr := a.Srv().Store.FileInfo().GetForPost(postID, false, false, false)
|
||||||
if nErr != nil {
|
if nErr != nil {
|
||||||
return nil, model.NewAppError("buildPostAttachments", "app.file_info.get_for_post.app_error", nil, nErr.Error(), http.StatusInternalServerError)
|
return nil, model.NewAppError("buildPostAttachments", "app.file_info.get_for_post.app_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|||||||
62
app/file.go
62
app/file.go
@@ -251,9 +251,9 @@ func (a *App) RemoveDirectory(path string) *model.AppError {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) getInfoForFilename(post *model.Post, teamID, channelId, userID, oldId, filename string) *model.FileInfo {
|
func (a *App) getInfoForFilename(post *model.Post, teamID, channelID, userID, oldId, filename string) *model.FileInfo {
|
||||||
name, _ := url.QueryUnescape(filename)
|
name, _ := url.QueryUnescape(filename)
|
||||||
pathPrefix := fmt.Sprintf("teams/%s/channels/%s/users/%s/%s/", teamID, channelId, userID, oldId)
|
pathPrefix := fmt.Sprintf("teams/%s/channels/%s/users/%s/%s/", teamID, channelID, userID, oldId)
|
||||||
path := pathPrefix + name
|
path := pathPrefix + name
|
||||||
|
|
||||||
// Open the file and populate the fields of the FileInfo
|
// Open the file and populate the fields of the FileInfo
|
||||||
@@ -325,8 +325,8 @@ func (a *App) findTeamIdForFilename(post *model.Post, id, filename string) strin
|
|||||||
var fileMigrationLock sync.Mutex
|
var fileMigrationLock sync.Mutex
|
||||||
var oldFilenameMatchExp *regexp.Regexp = regexp.MustCompile(`^\/([a-z\d]{26})\/([a-z\d]{26})\/([a-z\d]{26})\/([^\/]+)$`)
|
var oldFilenameMatchExp *regexp.Regexp = regexp.MustCompile(`^\/([a-z\d]{26})\/([a-z\d]{26})\/([a-z\d]{26})\/([^\/]+)$`)
|
||||||
|
|
||||||
// Parse the path from the Filename of the form /{channelId}/{userID}/{uid}/{nameWithExtension}
|
// Parse the path from the Filename of the form /{channelID}/{userID}/{uid}/{nameWithExtension}
|
||||||
func parseOldFilenames(filenames []string, channelId, userID string) [][]string {
|
func parseOldFilenames(filenames []string, channelID, userID string) [][]string {
|
||||||
parsed := [][]string{}
|
parsed := [][]string{}
|
||||||
for _, filename := range filenames {
|
for _, filename := range filenames {
|
||||||
matches := oldFilenameMatchExp.FindStringSubmatch(filename)
|
matches := oldFilenameMatchExp.FindStringSubmatch(filename)
|
||||||
@@ -334,8 +334,8 @@ func parseOldFilenames(filenames []string, channelId, userID string) [][]string
|
|||||||
mlog.Error("Failed to parse old Filename", mlog.String("filename", filename))
|
mlog.Error("Failed to parse old Filename", mlog.String("filename", filename))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if matches[1] != channelId {
|
if matches[1] != channelID {
|
||||||
mlog.Error("ChannelId in Filename does not match", mlog.String("channel_id", channelId), mlog.String("matched", matches[1]))
|
mlog.Error("ChannelId in Filename does not match", mlog.String("channel_id", channelID), mlog.String("matched", matches[1]))
|
||||||
} else if matches[2] != userID {
|
} else if matches[2] != userID {
|
||||||
mlog.Error("UserId in Filename does not match", mlog.String("user_id", userID), mlog.String("matched", matches[2]))
|
mlog.Error("UserId in Filename does not match", mlog.String("user_id", userID), mlog.String("matched", matches[2]))
|
||||||
} else {
|
} else {
|
||||||
@@ -427,7 +427,7 @@ func (a *App) MigrateFilenamesToFileInfos(post *model.Post) []*model.FileInfo {
|
|||||||
mlog.Debug("Migrating post to use FileInfos", mlog.String("post_id", post.Id))
|
mlog.Debug("Migrating post to use FileInfos", mlog.String("post_id", post.Id))
|
||||||
|
|
||||||
savedInfos := make([]*model.FileInfo, 0, len(infos))
|
savedInfos := make([]*model.FileInfo, 0, len(infos))
|
||||||
fileIds := make([]string, 0, len(filenames))
|
fileIDs := make([]string, 0, len(filenames))
|
||||||
for _, info := range infos {
|
for _, info := range infos {
|
||||||
if _, nErr = a.Srv().Store.FileInfo().Save(info); nErr != nil {
|
if _, nErr = a.Srv().Store.FileInfo().Save(info); nErr != nil {
|
||||||
mlog.Error(
|
mlog.Error(
|
||||||
@@ -441,14 +441,14 @@ func (a *App) MigrateFilenamesToFileInfos(post *model.Post) []*model.FileInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
savedInfos = append(savedInfos, info)
|
savedInfos = append(savedInfos, info)
|
||||||
fileIds = append(fileIds, info.Id)
|
fileIDs = append(fileIDs, info.Id)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy and save the updated post
|
// Copy and save the updated post
|
||||||
newPost := post.Clone()
|
newPost := post.Clone()
|
||||||
|
|
||||||
newPost.Filenames = []string{}
|
newPost.Filenames = []string{}
|
||||||
newPost.FileIds = fileIds
|
newPost.FileIds = fileIDs
|
||||||
|
|
||||||
// Update Posts to clear Filenames and set FileIds
|
// Update Posts to clear Filenames and set FileIds
|
||||||
if _, nErr = a.Srv().Store.Post().Update(newPost, post); nErr != nil {
|
if _, nErr = a.Srv().Store.Post().Update(newPost, post); nErr != nil {
|
||||||
@@ -469,15 +469,15 @@ func (a *App) GeneratePublicLink(siteURL string, info *model.FileInfo) string {
|
|||||||
return fmt.Sprintf("%s/files/%v/public?h=%s", siteURL, info.Id, hash)
|
return fmt.Sprintf("%s/files/%v/public?h=%s", siteURL, info.Id, hash)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GeneratePublicLinkHash(fileId, salt string) string {
|
func GeneratePublicLinkHash(fileID, salt string) string {
|
||||||
hash := sha256.New()
|
hash := sha256.New()
|
||||||
hash.Write([]byte(salt))
|
hash.Write([]byte(salt))
|
||||||
hash.Write([]byte(fileId))
|
hash.Write([]byte(fileID))
|
||||||
|
|
||||||
return base64.RawURLEncoding.EncodeToString(hash.Sum(nil))
|
return base64.RawURLEncoding.EncodeToString(hash.Sum(nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) UploadMultipartFiles(teamID string, channelId string, userID string, fileHeaders []*multipart.FileHeader, clientIds []string, now time.Time) (*model.FileUploadResponse, *model.AppError) {
|
func (a *App) UploadMultipartFiles(teamID string, channelID string, userID string, fileHeaders []*multipart.FileHeader, clientIds []string, now time.Time) (*model.FileUploadResponse, *model.AppError) {
|
||||||
files := make([]io.ReadCloser, len(fileHeaders))
|
files := make([]io.ReadCloser, len(fileHeaders))
|
||||||
filenames := make([]string, len(fileHeaders))
|
filenames := make([]string, len(fileHeaders))
|
||||||
|
|
||||||
@@ -495,13 +495,13 @@ func (a *App) UploadMultipartFiles(teamID string, channelId string, userID strin
|
|||||||
filenames[i] = fileHeader.Filename
|
filenames[i] = fileHeader.Filename
|
||||||
}
|
}
|
||||||
|
|
||||||
return a.UploadFiles(teamID, channelId, userID, files, filenames, clientIds, now)
|
return a.UploadFiles(teamID, channelID, userID, files, filenames, clientIds, now)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Uploads some files to the given team and channel as the given user. files and filenames should have
|
// Uploads some files to the given team and channel as the given user. files and filenames should have
|
||||||
// the same length. clientIds should either not be provided or have the same length as files and filenames.
|
// the same length. clientIds should either not be provided or have the same length as files and filenames.
|
||||||
// The provided files should be closed by the caller so that they are not leaked.
|
// The provided files should be closed by the caller so that they are not leaked.
|
||||||
func (a *App) UploadFiles(teamID string, channelId string, userID string, files []io.ReadCloser, filenames []string, clientIds []string, now time.Time) (*model.FileUploadResponse, *model.AppError) {
|
func (a *App) UploadFiles(teamID string, channelID string, userID string, files []io.ReadCloser, filenames []string, clientIds []string, now time.Time) (*model.FileUploadResponse, *model.AppError) {
|
||||||
if *a.Config().FileSettings.DriverName == "" {
|
if *a.Config().FileSettings.DriverName == "" {
|
||||||
return nil, model.NewAppError("UploadFiles", "api.file.upload_file.storage.app_error", nil, "", http.StatusNotImplemented)
|
return nil, model.NewAppError("UploadFiles", "api.file.upload_file.storage.app_error", nil, "", http.StatusNotImplemented)
|
||||||
}
|
}
|
||||||
@@ -524,7 +524,7 @@ func (a *App) UploadFiles(teamID string, channelId string, userID string, files
|
|||||||
io.Copy(buf, file)
|
io.Copy(buf, file)
|
||||||
data := buf.Bytes()
|
data := buf.Bytes()
|
||||||
|
|
||||||
info, data, err := a.DoUploadFileExpectModification(now, teamID, channelId, userID, filenames[i], data)
|
info, data, err := a.DoUploadFileExpectModification(now, teamID, channelID, userID, filenames[i], data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -548,14 +548,14 @@ func (a *App) UploadFiles(teamID string, channelId string, userID string, files
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UploadFile uploads a single file in form of a completely constructed byte array for a channel.
|
// UploadFile uploads a single file in form of a completely constructed byte array for a channel.
|
||||||
func (a *App) UploadFile(data []byte, channelId string, filename string) (*model.FileInfo, *model.AppError) {
|
func (a *App) UploadFile(data []byte, channelID string, filename string) (*model.FileInfo, *model.AppError) {
|
||||||
_, err := a.GetChannel(channelId)
|
_, err := a.GetChannel(channelID)
|
||||||
if err != nil && channelId != "" {
|
if err != nil && channelID != "" {
|
||||||
return nil, model.NewAppError("UploadFile", "api.file.upload_file.incorrect_channelId.app_error",
|
return nil, model.NewAppError("UploadFile", "api.file.upload_file.incorrect_channelId.app_error",
|
||||||
map[string]interface{}{"channelId": channelId}, "", http.StatusBadRequest)
|
map[string]interface{}{"channelId": channelID}, "", http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
info, _, appError := a.DoUploadFileExpectModification(time.Now(), "noteam", channelId, "nouser", filename, data)
|
info, _, appError := a.DoUploadFileExpectModification(time.Now(), "noteam", channelID, "nouser", filename, data)
|
||||||
if appError != nil {
|
if appError != nil {
|
||||||
return nil, appError
|
return nil, appError
|
||||||
}
|
}
|
||||||
@@ -694,11 +694,11 @@ func (t *UploadFileTask) init(a *App) {
|
|||||||
// returns a filled-out FileInfo and an optional error. A plugin may reject the
|
// returns a filled-out FileInfo and an optional error. A plugin may reject the
|
||||||
// upload, returning a rejection error. In this case FileInfo would have
|
// upload, returning a rejection error. In this case FileInfo would have
|
||||||
// contained the last "good" FileInfo before the execution of that plugin.
|
// contained the last "good" FileInfo before the execution of that plugin.
|
||||||
func (a *App) UploadFileX(channelId, name string, input io.Reader,
|
func (a *App) UploadFileX(channelID, name string, input io.Reader,
|
||||||
opts ...func(*UploadFileTask)) (*model.FileInfo, *model.AppError) {
|
opts ...func(*UploadFileTask)) (*model.FileInfo, *model.AppError) {
|
||||||
|
|
||||||
t := &UploadFileTask{
|
t := &UploadFileTask{
|
||||||
ChannelId: filepath.Base(channelId),
|
ChannelId: filepath.Base(channelID),
|
||||||
Name: filepath.Base(name),
|
Name: filepath.Base(name),
|
||||||
Input: input,
|
Input: input,
|
||||||
maxFileSize: *a.Config().FileSettings.MaxFileSize,
|
maxFileSize: *a.Config().FileSettings.MaxFileSize,
|
||||||
@@ -942,7 +942,7 @@ func (t UploadFileTask) newAppError(id string, details interface{}, httpStatus i
|
|||||||
func (a *App) DoUploadFileExpectModification(now time.Time, rawTeamId string, rawChannelId string, rawUserId string, rawFilename string, data []byte) (*model.FileInfo, []byte, *model.AppError) {
|
func (a *App) DoUploadFileExpectModification(now time.Time, rawTeamId string, rawChannelId string, rawUserId string, rawFilename string, data []byte) (*model.FileInfo, []byte, *model.AppError) {
|
||||||
filename := filepath.Base(rawFilename)
|
filename := filepath.Base(rawFilename)
|
||||||
teamID := filepath.Base(rawTeamId)
|
teamID := filepath.Base(rawTeamId)
|
||||||
channelId := filepath.Base(rawChannelId)
|
channelID := filepath.Base(rawChannelId)
|
||||||
userID := filepath.Base(rawUserId)
|
userID := filepath.Base(rawUserId)
|
||||||
|
|
||||||
info, err := model.GetInfoForBytes(filename, bytes.NewReader(data), len(data))
|
info, err := model.GetInfoForBytes(filename, bytes.NewReader(data), len(data))
|
||||||
@@ -963,7 +963,7 @@ func (a *App) DoUploadFileExpectModification(now time.Time, rawTeamId string, ra
|
|||||||
info.CreatorId = userID
|
info.CreatorId = userID
|
||||||
info.CreateAt = now.UnixNano() / int64(time.Millisecond)
|
info.CreateAt = now.UnixNano() / int64(time.Millisecond)
|
||||||
|
|
||||||
pathPrefix := now.Format("20060102") + "/teams/" + teamID + "/channels/" + channelId + "/users/" + userID + "/" + info.Id + "/"
|
pathPrefix := now.Format("20060102") + "/teams/" + teamID + "/channels/" + channelID + "/users/" + userID + "/" + info.Id + "/"
|
||||||
info.Path = pathPrefix + filename
|
info.Path = pathPrefix + filename
|
||||||
|
|
||||||
if info.IsImage() {
|
if info.IsImage() {
|
||||||
@@ -1174,8 +1174,8 @@ func (a *App) generateMiniPreviewForInfos(fileInfos []*model.FileInfo) {
|
|||||||
wg.Wait()
|
wg.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetFileInfo(fileId string) (*model.FileInfo, *model.AppError) {
|
func (a *App) GetFileInfo(fileID string) (*model.FileInfo, *model.AppError) {
|
||||||
fileInfo, err := a.Srv().Store.FileInfo().Get(fileId)
|
fileInfo, err := a.Srv().Store.FileInfo().Get(fileID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
var nfErr *store.ErrNotFound
|
var nfErr *store.ErrNotFound
|
||||||
switch {
|
switch {
|
||||||
@@ -1210,8 +1210,8 @@ func (a *App) GetFileInfos(page, perPage int, opt *model.GetFileInfosOptions) ([
|
|||||||
return fileInfos, nil
|
return fileInfos, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetFile(fileId string) ([]byte, *model.AppError) {
|
func (a *App) GetFile(fileID string) ([]byte, *model.AppError) {
|
||||||
info, err := a.GetFileInfo(fileId)
|
info, err := a.GetFileInfo(fileID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -1224,13 +1224,13 @@ func (a *App) GetFile(fileId string) ([]byte, *model.AppError) {
|
|||||||
return data, nil
|
return data, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) CopyFileInfos(userID string, fileIds []string) ([]string, *model.AppError) {
|
func (a *App) CopyFileInfos(userID string, fileIDs []string) ([]string, *model.AppError) {
|
||||||
var newFileIds []string
|
var newFileIds []string
|
||||||
|
|
||||||
now := model.GetMillis()
|
now := model.GetMillis()
|
||||||
|
|
||||||
for _, fileId := range fileIds {
|
for _, fileID := range fileIDs {
|
||||||
fileInfo, err := a.Srv().Store.FileInfo().Get(fileId)
|
fileInfo, err := a.Srv().Store.FileInfo().Get(fileID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
var nfErr *store.ErrNotFound
|
var nfErr *store.ErrNotFound
|
||||||
switch {
|
switch {
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ func BenchmarkUploadFile(b *testing.B) {
|
|||||||
// disable logging in the benchmark, as best we can
|
// disable logging in the benchmark, as best we can
|
||||||
th.App.Log().SetConsoleLevel(mlog.LevelError)
|
th.App.Log().SetConsoleLevel(mlog.LevelError)
|
||||||
teamID := model.NewId()
|
teamID := model.NewId()
|
||||||
channelId := model.NewId()
|
channelID := model.NewId()
|
||||||
userID := model.NewId()
|
userID := model.NewId()
|
||||||
|
|
||||||
mb := func(i int) int {
|
mb := func(i int) int {
|
||||||
@@ -86,7 +86,7 @@ func BenchmarkUploadFile(b *testing.B) {
|
|||||||
{
|
{
|
||||||
title: "raw-ish DoUploadFile",
|
title: "raw-ish DoUploadFile",
|
||||||
f: func(b *testing.B, n int, data []byte, ext string) {
|
f: func(b *testing.B, n int, data []byte, ext string) {
|
||||||
info1, err := th.App.DoUploadFile(time.Now(), teamID, channelId,
|
info1, err := th.App.DoUploadFile(time.Now(), teamID, channelID,
|
||||||
userID, fmt.Sprintf("BenchmarkDoUploadFile-%d%s", n, ext), data)
|
userID, fmt.Sprintf("BenchmarkDoUploadFile-%d%s", n, ext), data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Fatal(err)
|
b.Fatal(err)
|
||||||
@@ -99,7 +99,7 @@ func BenchmarkUploadFile(b *testing.B) {
|
|||||||
{
|
{
|
||||||
title: "raw UploadFileX Content-Length",
|
title: "raw UploadFileX Content-Length",
|
||||||
f: func(b *testing.B, n int, data []byte, ext string) {
|
f: func(b *testing.B, n int, data []byte, ext string) {
|
||||||
info, aerr := th.App.UploadFileX(channelId,
|
info, aerr := th.App.UploadFileX(channelID,
|
||||||
fmt.Sprintf("BenchmarkUploadFileTask-%d%s", n, ext),
|
fmt.Sprintf("BenchmarkUploadFileTask-%d%s", n, ext),
|
||||||
bytes.NewReader(data),
|
bytes.NewReader(data),
|
||||||
UploadFileSetTeamId(teamID),
|
UploadFileSetTeamId(teamID),
|
||||||
@@ -117,7 +117,7 @@ func BenchmarkUploadFile(b *testing.B) {
|
|||||||
{
|
{
|
||||||
title: "raw UploadFileX chunked",
|
title: "raw UploadFileX chunked",
|
||||||
f: func(b *testing.B, n int, data []byte, ext string) {
|
f: func(b *testing.B, n int, data []byte, ext string) {
|
||||||
info, aerr := th.App.UploadFileX(channelId,
|
info, aerr := th.App.UploadFileX(channelID,
|
||||||
fmt.Sprintf("BenchmarkUploadFileTask-%d%s", n, ext),
|
fmt.Sprintf("BenchmarkUploadFileTask-%d%s", n, ext),
|
||||||
bytes.NewReader(data),
|
bytes.NewReader(data),
|
||||||
UploadFileSetTeamId(teamID),
|
UploadFileSetTeamId(teamID),
|
||||||
@@ -135,7 +135,7 @@ func BenchmarkUploadFile(b *testing.B) {
|
|||||||
{
|
{
|
||||||
title: "image UploadFiles",
|
title: "image UploadFiles",
|
||||||
f: func(b *testing.B, n int, data []byte, ext string) {
|
f: func(b *testing.B, n int, data []byte, ext string) {
|
||||||
resp, err := th.App.UploadFiles(teamID, channelId, userID,
|
resp, err := th.App.UploadFiles(teamID, channelID, userID,
|
||||||
[]io.ReadCloser{ioutil.NopCloser(bytes.NewReader(data))},
|
[]io.ReadCloser{ioutil.NopCloser(bytes.NewReader(data))},
|
||||||
[]string{fmt.Sprintf("BenchmarkDoUploadFiles-%d%s", n, ext)},
|
[]string{fmt.Sprintf("BenchmarkDoUploadFiles-%d%s", n, ext)},
|
||||||
[]string{},
|
[]string{},
|
||||||
@@ -150,7 +150,7 @@ func BenchmarkUploadFile(b *testing.B) {
|
|||||||
{
|
{
|
||||||
title: "image UploadFileX Content-Length",
|
title: "image UploadFileX Content-Length",
|
||||||
f: func(b *testing.B, n int, data []byte, ext string) {
|
f: func(b *testing.B, n int, data []byte, ext string) {
|
||||||
info, aerr := th.App.UploadFileX(channelId,
|
info, aerr := th.App.UploadFileX(channelID,
|
||||||
fmt.Sprintf("BenchmarkUploadFileTask-%d%s", n, ext),
|
fmt.Sprintf("BenchmarkUploadFileTask-%d%s", n, ext),
|
||||||
bytes.NewReader(data),
|
bytes.NewReader(data),
|
||||||
UploadFileSetTeamId(teamID),
|
UploadFileSetTeamId(teamID),
|
||||||
@@ -167,7 +167,7 @@ func BenchmarkUploadFile(b *testing.B) {
|
|||||||
{
|
{
|
||||||
title: "image UploadFileX chunked",
|
title: "image UploadFileX chunked",
|
||||||
f: func(b *testing.B, n int, data []byte, ext string) {
|
f: func(b *testing.B, n int, data []byte, ext string) {
|
||||||
info, aerr := th.App.UploadFileX(channelId,
|
info, aerr := th.App.UploadFileX(channelID,
|
||||||
fmt.Sprintf("BenchmarkUploadFileTask-%d%s", n, ext),
|
fmt.Sprintf("BenchmarkUploadFileTask-%d%s", n, ext),
|
||||||
bytes.NewReader(data),
|
bytes.NewReader(data),
|
||||||
UploadFileSetTeamId(teamID),
|
UploadFileSetTeamId(teamID),
|
||||||
|
|||||||
@@ -44,49 +44,49 @@ func TestDoUploadFile(t *testing.T) {
|
|||||||
defer th.TearDown()
|
defer th.TearDown()
|
||||||
|
|
||||||
teamID := model.NewId()
|
teamID := model.NewId()
|
||||||
channelId := model.NewId()
|
channelID := model.NewId()
|
||||||
userID := model.NewId()
|
userID := model.NewId()
|
||||||
filename := "test"
|
filename := "test"
|
||||||
data := []byte("abcd")
|
data := []byte("abcd")
|
||||||
|
|
||||||
info1, err := th.App.DoUploadFile(time.Date(2007, 2, 4, 1, 2, 3, 4, time.Local), teamID, channelId, userID, filename, data)
|
info1, err := th.App.DoUploadFile(time.Date(2007, 2, 4, 1, 2, 3, 4, time.Local), teamID, channelID, userID, filename, data)
|
||||||
require.Nil(t, err, "DoUploadFile should succeed with valid data")
|
require.Nil(t, err, "DoUploadFile should succeed with valid data")
|
||||||
defer func() {
|
defer func() {
|
||||||
th.App.Srv().Store.FileInfo().PermanentDelete(info1.Id)
|
th.App.Srv().Store.FileInfo().PermanentDelete(info1.Id)
|
||||||
th.App.RemoveFile(info1.Path)
|
th.App.RemoveFile(info1.Path)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
value := fmt.Sprintf("20070204/teams/%v/channels/%v/users/%v/%v/%v", teamID, channelId, userID, info1.Id, filename)
|
value := fmt.Sprintf("20070204/teams/%v/channels/%v/users/%v/%v/%v", teamID, channelID, userID, info1.Id, filename)
|
||||||
assert.Equal(t, value, info1.Path, "stored file at incorrect path")
|
assert.Equal(t, value, info1.Path, "stored file at incorrect path")
|
||||||
|
|
||||||
info2, err := th.App.DoUploadFile(time.Date(2007, 2, 4, 1, 2, 3, 4, time.Local), teamID, channelId, userID, filename, data)
|
info2, err := th.App.DoUploadFile(time.Date(2007, 2, 4, 1, 2, 3, 4, time.Local), teamID, channelID, userID, filename, data)
|
||||||
require.Nil(t, err, "DoUploadFile should succeed with valid data")
|
require.Nil(t, err, "DoUploadFile should succeed with valid data")
|
||||||
defer func() {
|
defer func() {
|
||||||
th.App.Srv().Store.FileInfo().PermanentDelete(info2.Id)
|
th.App.Srv().Store.FileInfo().PermanentDelete(info2.Id)
|
||||||
th.App.RemoveFile(info2.Path)
|
th.App.RemoveFile(info2.Path)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
value = fmt.Sprintf("20070204/teams/%v/channels/%v/users/%v/%v/%v", teamID, channelId, userID, info2.Id, filename)
|
value = fmt.Sprintf("20070204/teams/%v/channels/%v/users/%v/%v/%v", teamID, channelID, userID, info2.Id, filename)
|
||||||
assert.Equal(t, value, info2.Path, "stored file at incorrect path")
|
assert.Equal(t, value, info2.Path, "stored file at incorrect path")
|
||||||
|
|
||||||
info3, err := th.App.DoUploadFile(time.Date(2008, 3, 5, 1, 2, 3, 4, time.Local), teamID, channelId, userID, filename, data)
|
info3, err := th.App.DoUploadFile(time.Date(2008, 3, 5, 1, 2, 3, 4, time.Local), teamID, channelID, userID, filename, data)
|
||||||
require.Nil(t, err, "DoUploadFile should succeed with valid data")
|
require.Nil(t, err, "DoUploadFile should succeed with valid data")
|
||||||
defer func() {
|
defer func() {
|
||||||
th.App.Srv().Store.FileInfo().PermanentDelete(info3.Id)
|
th.App.Srv().Store.FileInfo().PermanentDelete(info3.Id)
|
||||||
th.App.RemoveFile(info3.Path)
|
th.App.RemoveFile(info3.Path)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
value = fmt.Sprintf("20080305/teams/%v/channels/%v/users/%v/%v/%v", teamID, channelId, userID, info3.Id, filename)
|
value = fmt.Sprintf("20080305/teams/%v/channels/%v/users/%v/%v/%v", teamID, channelID, userID, info3.Id, filename)
|
||||||
assert.Equal(t, value, info3.Path, "stored file at incorrect path")
|
assert.Equal(t, value, info3.Path, "stored file at incorrect path")
|
||||||
|
|
||||||
info4, err := th.App.DoUploadFile(time.Date(2009, 3, 5, 1, 2, 3, 4, time.Local), "../../"+teamID, "../../"+channelId, "../../"+userID, "../../"+filename, data)
|
info4, err := th.App.DoUploadFile(time.Date(2009, 3, 5, 1, 2, 3, 4, time.Local), "../../"+teamID, "../../"+channelID, "../../"+userID, "../../"+filename, data)
|
||||||
require.Nil(t, err, "DoUploadFile should succeed with valid data")
|
require.Nil(t, err, "DoUploadFile should succeed with valid data")
|
||||||
defer func() {
|
defer func() {
|
||||||
th.App.Srv().Store.FileInfo().PermanentDelete(info4.Id)
|
th.App.Srv().Store.FileInfo().PermanentDelete(info4.Id)
|
||||||
th.App.RemoveFile(info4.Path)
|
th.App.RemoveFile(info4.Path)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
value = fmt.Sprintf("20090305/teams/%v/channels/%v/users/%v/%v/%v", teamID, channelId, userID, info4.Id, filename)
|
value = fmt.Sprintf("20090305/teams/%v/channels/%v/users/%v/%v/%v", teamID, channelID, userID, info4.Id, filename)
|
||||||
assert.Equal(t, value, info4.Path, "stored file at incorrect path")
|
assert.Equal(t, value, info4.Path, "stored file at incorrect path")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,7 +94,7 @@ func TestUploadFile(t *testing.T) {
|
|||||||
th := Setup(t).InitBasic()
|
th := Setup(t).InitBasic()
|
||||||
defer th.TearDown()
|
defer th.TearDown()
|
||||||
|
|
||||||
channelId := th.BasicChannel.Id
|
channelID := th.BasicChannel.Id
|
||||||
filename := "test"
|
filename := "test"
|
||||||
data := []byte("abcd")
|
data := []byte("abcd")
|
||||||
|
|
||||||
@@ -105,7 +105,7 @@ func TestUploadFile(t *testing.T) {
|
|||||||
info1, err = th.App.UploadFile(data, "", filename)
|
info1, err = th.App.UploadFile(data, "", filename)
|
||||||
require.Nil(t, err, "empty channel IDs should be valid")
|
require.Nil(t, err, "empty channel IDs should be valid")
|
||||||
|
|
||||||
info1, err = th.App.UploadFile(data, channelId, filename)
|
info1, err = th.App.UploadFile(data, channelID, filename)
|
||||||
require.Nil(t, err, "UploadFile should succeed with valid data")
|
require.Nil(t, err, "UploadFile should succeed with valid data")
|
||||||
defer func() {
|
defer func() {
|
||||||
th.App.Srv().Store.FileInfo().PermanentDelete(info1.Id)
|
th.App.Srv().Store.FileInfo().PermanentDelete(info1.Id)
|
||||||
@@ -113,7 +113,7 @@ func TestUploadFile(t *testing.T) {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
value := fmt.Sprintf("%v/teams/noteam/channels/%v/users/nouser/%v/%v",
|
value := fmt.Sprintf("%v/teams/noteam/channels/%v/users/nouser/%v/%v",
|
||||||
time.Now().Format("20060102"), channelId, info1.Id, filename)
|
time.Now().Format("20060102"), channelID, info1.Id, filename)
|
||||||
assert.Equal(t, value, info1.Path, "Stored file at incorrect path")
|
assert.Equal(t, value, info1.Path, "Stored file at incorrect path")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,69 +121,69 @@ func TestParseOldFilenames(t *testing.T) {
|
|||||||
th := Setup(t).InitBasic()
|
th := Setup(t).InitBasic()
|
||||||
defer th.TearDown()
|
defer th.TearDown()
|
||||||
|
|
||||||
fileId := model.NewId()
|
fileID := model.NewId()
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
description string
|
description string
|
||||||
filenames []string
|
filenames []string
|
||||||
channelId string
|
channelID string
|
||||||
userID string
|
userID string
|
||||||
expected [][]string
|
expected [][]string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
description: "Empty input should result in empty output",
|
description: "Empty input should result in empty output",
|
||||||
filenames: []string{},
|
filenames: []string{},
|
||||||
channelId: th.BasicChannel.Id,
|
channelID: th.BasicChannel.Id,
|
||||||
userID: th.BasicUser.Id,
|
userID: th.BasicUser.Id,
|
||||||
expected: [][]string{},
|
expected: [][]string{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "Filename with invalid format should not parse",
|
description: "Filename with invalid format should not parse",
|
||||||
filenames: []string{"/path/to/some/file.png"},
|
filenames: []string{"/path/to/some/file.png"},
|
||||||
channelId: th.BasicChannel.Id,
|
channelID: th.BasicChannel.Id,
|
||||||
userID: th.BasicUser.Id,
|
userID: th.BasicUser.Id,
|
||||||
expected: [][]string{},
|
expected: [][]string{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "ChannelId in Filename should not match",
|
description: "ChannelId in Filename should not match",
|
||||||
filenames: []string{
|
filenames: []string{
|
||||||
fmt.Sprintf("/%v/%v/%v/file.png", model.NewId(), th.BasicUser.Id, fileId),
|
fmt.Sprintf("/%v/%v/%v/file.png", model.NewId(), th.BasicUser.Id, fileID),
|
||||||
},
|
},
|
||||||
channelId: th.BasicChannel.Id,
|
channelID: th.BasicChannel.Id,
|
||||||
userID: th.BasicUser.Id,
|
userID: th.BasicUser.Id,
|
||||||
expected: [][]string{},
|
expected: [][]string{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "UserId in Filename should not match",
|
description: "UserId in Filename should not match",
|
||||||
filenames: []string{
|
filenames: []string{
|
||||||
fmt.Sprintf("/%v/%v/%v/file.png", th.BasicChannel.Id, model.NewId(), fileId),
|
fmt.Sprintf("/%v/%v/%v/file.png", th.BasicChannel.Id, model.NewId(), fileID),
|
||||||
},
|
},
|
||||||
channelId: th.BasicChannel.Id,
|
channelID: th.BasicChannel.Id,
|
||||||
userID: th.BasicUser.Id,
|
userID: th.BasicUser.Id,
|
||||||
expected: [][]string{},
|
expected: [][]string{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "../ in filename should not parse",
|
description: "../ in filename should not parse",
|
||||||
filenames: []string{
|
filenames: []string{
|
||||||
fmt.Sprintf("/%v/%v/%v/../../../file.png", th.BasicChannel.Id, th.BasicUser.Id, fileId),
|
fmt.Sprintf("/%v/%v/%v/../../../file.png", th.BasicChannel.Id, th.BasicUser.Id, fileID),
|
||||||
},
|
},
|
||||||
channelId: th.BasicChannel.Id,
|
channelID: th.BasicChannel.Id,
|
||||||
userID: th.BasicUser.Id,
|
userID: th.BasicUser.Id,
|
||||||
expected: [][]string{},
|
expected: [][]string{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "Should only parse valid filenames",
|
description: "Should only parse valid filenames",
|
||||||
filenames: []string{
|
filenames: []string{
|
||||||
fmt.Sprintf("/%v/%v/%v/../otherfile.png", th.BasicChannel.Id, th.BasicUser.Id, fileId),
|
fmt.Sprintf("/%v/%v/%v/../otherfile.png", th.BasicChannel.Id, th.BasicUser.Id, fileID),
|
||||||
fmt.Sprintf("/%v/%v/%v/file.png", th.BasicChannel.Id, th.BasicUser.Id, fileId),
|
fmt.Sprintf("/%v/%v/%v/file.png", th.BasicChannel.Id, th.BasicUser.Id, fileID),
|
||||||
},
|
},
|
||||||
channelId: th.BasicChannel.Id,
|
channelID: th.BasicChannel.Id,
|
||||||
userID: th.BasicUser.Id,
|
userID: th.BasicUser.Id,
|
||||||
expected: [][]string{
|
expected: [][]string{
|
||||||
{
|
{
|
||||||
th.BasicChannel.Id,
|
th.BasicChannel.Id,
|
||||||
th.BasicUser.Id,
|
th.BasicUser.Id,
|
||||||
fileId,
|
fileID,
|
||||||
"file.png",
|
"file.png",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -191,15 +191,15 @@ func TestParseOldFilenames(t *testing.T) {
|
|||||||
{
|
{
|
||||||
description: "Valid Filename should parse",
|
description: "Valid Filename should parse",
|
||||||
filenames: []string{
|
filenames: []string{
|
||||||
fmt.Sprintf("/%v/%v/%v/file.png", th.BasicChannel.Id, th.BasicUser.Id, fileId),
|
fmt.Sprintf("/%v/%v/%v/file.png", th.BasicChannel.Id, th.BasicUser.Id, fileID),
|
||||||
},
|
},
|
||||||
channelId: th.BasicChannel.Id,
|
channelID: th.BasicChannel.Id,
|
||||||
userID: th.BasicUser.Id,
|
userID: th.BasicUser.Id,
|
||||||
expected: [][]string{
|
expected: [][]string{
|
||||||
{
|
{
|
||||||
th.BasicChannel.Id,
|
th.BasicChannel.Id,
|
||||||
th.BasicUser.Id,
|
th.BasicUser.Id,
|
||||||
fileId,
|
fileID,
|
||||||
"file.png",
|
"file.png",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -208,7 +208,7 @@ func TestParseOldFilenames(t *testing.T) {
|
|||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Run(test.description, func(tt *testing.T) {
|
t.Run(test.description, func(tt *testing.T) {
|
||||||
result := parseOldFilenames(test.filenames, test.channelId, test.userID)
|
result := parseOldFilenames(test.filenames, test.channelID, test.userID)
|
||||||
require.Equal(tt, result, test.expected)
|
require.Equal(tt, result, test.expected)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -256,17 +256,17 @@ func TestMigrateFilenamesToFileInfos(t *testing.T) {
|
|||||||
require.NoError(t, fileErr)
|
require.NoError(t, fileErr)
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|
||||||
fileId := model.NewId()
|
fileID := model.NewId()
|
||||||
fpath := fmt.Sprintf("/teams/%v/channels/%v/users/%v/%v/test.png", th.BasicTeam.Id, th.BasicChannel.Id, th.BasicUser.Id, fileId)
|
fpath := fmt.Sprintf("/teams/%v/channels/%v/users/%v/%v/test.png", th.BasicTeam.Id, th.BasicChannel.Id, th.BasicUser.Id, fileID)
|
||||||
_, err := th.App.WriteFile(file, fpath)
|
_, err := th.App.WriteFile(file, fpath)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
rpost, err := th.App.CreatePost(&model.Post{UserId: th.BasicUser.Id, ChannelId: th.BasicChannel.Id, Filenames: []string{fmt.Sprintf("/%v/%v/%v/test.png", th.BasicChannel.Id, th.BasicUser.Id, fileId)}}, th.BasicChannel, false, true)
|
rpost, err := th.App.CreatePost(&model.Post{UserId: th.BasicUser.Id, ChannelId: th.BasicChannel.Id, Filenames: []string{fmt.Sprintf("/%v/%v/%v/test.png", th.BasicChannel.Id, th.BasicUser.Id, fileID)}}, th.BasicChannel, false, true)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
infos = th.App.MigrateFilenamesToFileInfos(rpost)
|
infos = th.App.MigrateFilenamesToFileInfos(rpost)
|
||||||
assert.Equal(t, 1, len(infos))
|
assert.Equal(t, 1, len(infos))
|
||||||
|
|
||||||
rpost, err = th.App.CreatePost(&model.Post{UserId: th.BasicUser.Id, ChannelId: th.BasicChannel.Id, Filenames: []string{fmt.Sprintf("/%v/%v/%v/../../test.png", th.BasicChannel.Id, th.BasicUser.Id, fileId)}}, th.BasicChannel, false, true)
|
rpost, err = th.App.CreatePost(&model.Post{UserId: th.BasicUser.Id, ChannelId: th.BasicChannel.Id, Filenames: []string{fmt.Sprintf("/%v/%v/%v/../../test.png", th.BasicChannel.Id, th.BasicUser.Id, fileID)}}, th.BasicChannel, false, true)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
infos = th.App.MigrateFilenamesToFileInfos(rpost)
|
infos = th.App.MigrateFilenamesToFileInfos(rpost)
|
||||||
@@ -296,12 +296,12 @@ func TestCopyFileInfos(t *testing.T) {
|
|||||||
defer th.TearDown()
|
defer th.TearDown()
|
||||||
|
|
||||||
teamID := model.NewId()
|
teamID := model.NewId()
|
||||||
channelId := model.NewId()
|
channelID := model.NewId()
|
||||||
userID := model.NewId()
|
userID := model.NewId()
|
||||||
filename := "test"
|
filename := "test"
|
||||||
data := []byte("abcd")
|
data := []byte("abcd")
|
||||||
|
|
||||||
info1, err := th.App.DoUploadFile(time.Date(2007, 2, 4, 1, 2, 3, 4, time.Local), teamID, channelId, userID, filename, data)
|
info1, err := th.App.DoUploadFile(time.Date(2007, 2, 4, 1, 2, 3, 4, time.Local), teamID, channelID, userID, filename, data)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
defer func() {
|
defer func() {
|
||||||
th.App.Srv().Store.FileInfo().PermanentDelete(info1.Id)
|
th.App.Srv().Store.FileInfo().PermanentDelete(info1.Id)
|
||||||
|
|||||||
@@ -435,13 +435,13 @@ func (a *App) ChannelMembersToRemove(teamID *string) ([]*model.ChannelMember, *m
|
|||||||
return channelMembers, nil
|
return channelMembers, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetGroupsByChannel(channelId string, opts model.GroupSearchOpts) ([]*model.GroupWithSchemeAdmin, int, *model.AppError) {
|
func (a *App) GetGroupsByChannel(channelID string, opts model.GroupSearchOpts) ([]*model.GroupWithSchemeAdmin, int, *model.AppError) {
|
||||||
groups, err := a.Srv().Store.Group().GetGroupsByChannel(channelId, opts)
|
groups, err := a.Srv().Store.Group().GetGroupsByChannel(channelID, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, model.NewAppError("GetGroupsByChannel", "app.select_error", nil, err.Error(), http.StatusInternalServerError)
|
return nil, 0, model.NewAppError("GetGroupsByChannel", "app.select_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
count, err := a.Srv().Store.Group().CountGroupsByChannel(channelId, opts)
|
count, err := a.Srv().Store.Group().CountGroupsByChannel(channelID, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, model.NewAppError("GetGroupsByChannel", "app.select_error", nil, err.Error(), http.StatusInternalServerError)
|
return nil, 0, model.NewAppError("GetGroupsByChannel", "app.select_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1064,17 +1064,17 @@ func (a *App) importReplies(data []ReplyImportData, post *model.Post, teamID str
|
|||||||
reply.Message = *replyData.Message
|
reply.Message = *replyData.Message
|
||||||
reply.CreateAt = *replyData.CreateAt
|
reply.CreateAt = *replyData.CreateAt
|
||||||
|
|
||||||
fileIds, err := a.uploadAttachments(replyData.Attachments, reply, teamID)
|
fileIDs, err := a.uploadAttachments(replyData.Attachments, reply, teamID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, fileID := range reply.FileIds {
|
for _, fileID := range reply.FileIds {
|
||||||
if _, ok := fileIds[fileID]; !ok {
|
if _, ok := fileIDs[fileID]; !ok {
|
||||||
a.Srv().Store.FileInfo().PermanentDelete(fileID)
|
a.Srv().Store.FileInfo().PermanentDelete(fileID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
reply.FileIds = make([]string, 0)
|
reply.FileIds = make([]string, 0)
|
||||||
for fileID := range fileIds {
|
for fileID := range fileIDs {
|
||||||
reply.FileIds = append(reply.FileIds, fileID)
|
reply.FileIds = append(reply.FileIds, fileID)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1328,17 +1328,17 @@ func (a *App) importMultiplePostLines(lines []LineImportWorkerData, dryRun bool)
|
|||||||
post.Props = *line.Post.Props
|
post.Props = *line.Post.Props
|
||||||
}
|
}
|
||||||
|
|
||||||
fileIds, appErr := a.uploadAttachments(line.Post.Attachments, post, team.Id)
|
fileIDs, appErr := a.uploadAttachments(line.Post.Attachments, post, team.Id)
|
||||||
if appErr != nil {
|
if appErr != nil {
|
||||||
return line.LineNumber, appErr
|
return line.LineNumber, appErr
|
||||||
}
|
}
|
||||||
for _, fileID := range post.FileIds {
|
for _, fileID := range post.FileIds {
|
||||||
if _, ok := fileIds[fileID]; !ok {
|
if _, ok := fileIDs[fileID]; !ok {
|
||||||
a.Srv().Store.FileInfo().PermanentDelete(fileID)
|
a.Srv().Store.FileInfo().PermanentDelete(fileID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
post.FileIds = make([]string, 0)
|
post.FileIds = make([]string, 0)
|
||||||
for fileID := range fileIds {
|
for fileID := range fileIDs {
|
||||||
post.FileIds = append(post.FileIds, fileID)
|
post.FileIds = append(post.FileIds, fileID)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1434,21 +1434,21 @@ func (a *App) uploadAttachments(attachments *[]AttachmentImportData, post *model
|
|||||||
if attachments == nil {
|
if attachments == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
fileIds := make(map[string]bool)
|
fileIDs := make(map[string]bool)
|
||||||
for _, attachment := range *attachments {
|
for _, attachment := range *attachments {
|
||||||
attachment := attachment
|
attachment := attachment
|
||||||
fileInfo, err := a.importAttachment(&attachment, post, teamID)
|
fileInfo, err := a.importAttachment(&attachment, post, teamID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
fileIds[fileInfo.Id] = true
|
fileIDs[fileInfo.Id] = true
|
||||||
}
|
}
|
||||||
return fileIds, nil
|
return fileIDs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) updateFileInfoWithPostId(post *model.Post) {
|
func (a *App) updateFileInfoWithPostId(post *model.Post) {
|
||||||
for _, fileId := range post.FileIds {
|
for _, fileID := range post.FileIds {
|
||||||
if err := a.Srv().Store.FileInfo().AttachToPost(fileId, post.Id, post.UserId); err != nil {
|
if err := a.Srv().Store.FileInfo().AttachToPost(fileID, post.Id, post.UserId); err != nil {
|
||||||
mlog.Error("Error attaching files to post.", mlog.String("post_id", post.Id), mlog.Any("post_file_ids", post.FileIds), mlog.Err(err))
|
mlog.Error("Error attaching files to post.", mlog.String("post_id", post.Id), mlog.Any("post_file_ids", post.FileIds), mlog.Err(err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1624,17 +1624,17 @@ func (a *App) importMultipleDirectPostLines(lines []LineImportWorkerData, dryRun
|
|||||||
post.Props = *line.DirectPost.Props
|
post.Props = *line.DirectPost.Props
|
||||||
}
|
}
|
||||||
|
|
||||||
fileIds, err := a.uploadAttachments(line.DirectPost.Attachments, post, "noteam")
|
fileIDs, err := a.uploadAttachments(line.DirectPost.Attachments, post, "noteam")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return line.LineNumber, err
|
return line.LineNumber, err
|
||||||
}
|
}
|
||||||
for _, fileID := range post.FileIds {
|
for _, fileID := range post.FileIds {
|
||||||
if _, ok := fileIds[fileID]; !ok {
|
if _, ok := fileIDs[fileID]; !ok {
|
||||||
a.Srv().Store.FileInfo().PermanentDelete(fileID)
|
a.Srv().Store.FileInfo().PermanentDelete(fileID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
post.FileIds = make([]string, 0)
|
post.FileIds = make([]string, 0)
|
||||||
for fileID := range fileIds {
|
for fileID := range fileIDs {
|
||||||
post.FileIds = append(post.FileIds, fileID)
|
post.FileIds = append(post.FileIds, fileID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -256,10 +256,10 @@ func GetAttachments(userID string, th *TestHelper, t *testing.T) []*model.FileIn
|
|||||||
}
|
}
|
||||||
|
|
||||||
func AssertFileIdsInPost(files []*model.FileInfo, th *TestHelper, t *testing.T) {
|
func AssertFileIdsInPost(files []*model.FileInfo, th *TestHelper, t *testing.T) {
|
||||||
postId := files[0].PostId
|
postID := files[0].PostId
|
||||||
require.NotNil(t, postId)
|
require.NotNil(t, postID)
|
||||||
|
|
||||||
posts, err := th.App.Srv().Store.Post().GetPostsByIds([]string{postId})
|
posts, err := th.App.Srv().Store.Post().GetPostsByIds([]string{postID})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
require.Len(t, posts, 1)
|
require.Len(t, posts, 1)
|
||||||
|
|||||||
@@ -38,11 +38,11 @@ import (
|
|||||||
"github.com/mattermost/mattermost-server/v5/utils"
|
"github.com/mattermost/mattermost-server/v5/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (a *App) DoPostAction(postId, actionId, userID, selectedOption string) (string, *model.AppError) {
|
func (a *App) DoPostAction(postID, actionId, userID, selectedOption string) (string, *model.AppError) {
|
||||||
return a.DoPostActionWithCookie(postId, actionId, userID, selectedOption, nil)
|
return a.DoPostActionWithCookie(postID, actionId, userID, selectedOption, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) DoPostActionWithCookie(postId, actionId, userID, selectedOption string, cookie *model.PostActionCookie) (string, *model.AppError) {
|
func (a *App) DoPostActionWithCookie(postID, actionId, userID, selectedOption string, cookie *model.PostActionCookie) (string, *model.AppError) {
|
||||||
|
|
||||||
// PostAction may result in the original post being updated. For the
|
// PostAction may result in the original post being updated. For the
|
||||||
// updated post, we need to unconditionally preserve the original
|
// updated post, we need to unconditionally preserve the original
|
||||||
@@ -64,21 +64,21 @@ func (a *App) DoPostActionWithCookie(postId, actionId, userID, selectedOption st
|
|||||||
rootPostId := ""
|
rootPostId := ""
|
||||||
upstreamRequest := &model.PostActionIntegrationRequest{
|
upstreamRequest := &model.PostActionIntegrationRequest{
|
||||||
UserId: userID,
|
UserId: userID,
|
||||||
PostId: postId,
|
PostId: postID,
|
||||||
}
|
}
|
||||||
|
|
||||||
// See if the post exists in the DB, if so ignore the cookie.
|
// See if the post exists in the DB, if so ignore the cookie.
|
||||||
// Start all queries here for parallel execution
|
// Start all queries here for parallel execution
|
||||||
pchan := make(chan store.StoreResult, 1)
|
pchan := make(chan store.StoreResult, 1)
|
||||||
go func() {
|
go func() {
|
||||||
post, err := a.Srv().Store.Post().GetSingle(postId)
|
post, err := a.Srv().Store.Post().GetSingle(postID)
|
||||||
pchan <- store.StoreResult{Data: post, NErr: err}
|
pchan <- store.StoreResult{Data: post, NErr: err}
|
||||||
close(pchan)
|
close(pchan)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
cchan := make(chan store.StoreResult, 1)
|
cchan := make(chan store.StoreResult, 1)
|
||||||
go func() {
|
go func() {
|
||||||
channel, err := a.Srv().Store.Channel().GetForPost(postId)
|
channel, err := a.Srv().Store.Channel().GetForPost(postID)
|
||||||
cchan <- store.StoreResult{Data: channel, NErr: err}
|
cchan <- store.StoreResult{Data: channel, NErr: err}
|
||||||
close(cchan)
|
close(cchan)
|
||||||
}()
|
}()
|
||||||
@@ -105,7 +105,7 @@ func (a *App) DoPostActionWithCookie(postId, actionId, userID, selectedOption st
|
|||||||
return "", model.NewAppError("DoPostActionWithCookie", "api.post.do_action.action_integration.app_error", nil, "no Integration in action cookie", http.StatusBadRequest)
|
return "", model.NewAppError("DoPostActionWithCookie", "api.post.do_action.action_integration.app_error", nil, "no Integration in action cookie", http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
if postId != cookie.PostId {
|
if postID != cookie.PostId {
|
||||||
return "", model.NewAppError("DoPostActionWithCookie", "api.post.do_action.action_integration.app_error", nil, "postId doesn't match", http.StatusBadRequest)
|
return "", model.NewAppError("DoPostActionWithCookie", "api.post.do_action.action_integration.app_error", nil, "postId doesn't match", http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -252,7 +252,7 @@ func (a *App) DoPostActionWithCookie(postId, actionId, userID, selectedOption st
|
|||||||
}
|
}
|
||||||
|
|
||||||
if response.Update != nil {
|
if response.Update != nil {
|
||||||
response.Update.Id = postId
|
response.Update.Id = postID
|
||||||
|
|
||||||
// Restore the post attributes and Props that need to be preserved
|
// Restore the post attributes and Props that need to be preserved
|
||||||
if response.Update.GetProps() == nil {
|
if response.Update.GetProps() == nil {
|
||||||
@@ -374,9 +374,9 @@ func (a *App) doPluginRequest(method, rawURL string, values url.Values, body []b
|
|||||||
if result[0] != "plugins" {
|
if result[0] != "plugins" {
|
||||||
return nil, model.NewAppError("doPluginRequest", "api.post.do_action.action_integration.app_error", nil, "err=plugins not in path", http.StatusBadRequest)
|
return nil, model.NewAppError("doPluginRequest", "api.post.do_action.action_integration.app_error", nil, "err=plugins not in path", http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
pluginId := result[1]
|
pluginID := result[1]
|
||||||
|
|
||||||
path := strings.TrimPrefix(inURL.Path, "plugins/"+pluginId)
|
path := strings.TrimPrefix(inURL.Path, "plugins/"+pluginID)
|
||||||
|
|
||||||
base, err := url.Parse(path)
|
base, err := url.Parse(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -407,7 +407,7 @@ func (a *App) doPluginRequest(method, rawURL string, values url.Values, body []b
|
|||||||
r.Header.Set("Mattermost-User-Id", a.Session().UserId)
|
r.Header.Set("Mattermost-User-Id", a.Session().UserId)
|
||||||
r.Header.Set(model.HEADER_AUTH, "Bearer "+a.Session().Token)
|
r.Header.Set(model.HEADER_AUTH, "Bearer "+a.Session().Token)
|
||||||
params := make(map[string]string)
|
params := make(map[string]string)
|
||||||
params["plugin_id"] = pluginId
|
params["plugin_id"] = pluginID
|
||||||
r = mux.SetURLVars(r, params)
|
r = mux.SetURLVars(r, params)
|
||||||
|
|
||||||
a.ServePluginRequest(w, r)
|
a.ServePluginRequest(w, r)
|
||||||
|
|||||||
@@ -154,7 +154,7 @@ func (a *App) GetUserForLogin(id, loginId string) (*model.User, *model.AppError)
|
|||||||
return nil, model.NewAppError("GetUserForLogin", "store.sql_user.get_for_login.app_error", nil, "", http.StatusBadRequest)
|
return nil, model.NewAppError("GetUserForLogin", "store.sql_user.get_for_login.app_error", nil, "", http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) DoLogin(w http.ResponseWriter, r *http.Request, user *model.User, deviceId string, isMobile, isOAuthUser, isSaml bool) *model.AppError {
|
func (a *App) DoLogin(w http.ResponseWriter, r *http.Request, user *model.User, deviceID string, isMobile, isOAuthUser, isSaml bool) *model.AppError {
|
||||||
if pluginsEnvironment := a.GetPluginsEnvironment(); pluginsEnvironment != nil {
|
if pluginsEnvironment := a.GetPluginsEnvironment(); pluginsEnvironment != nil {
|
||||||
var rejectionReason string
|
var rejectionReason string
|
||||||
pluginContext := a.PluginContext()
|
pluginContext := a.PluginContext()
|
||||||
@@ -168,18 +168,18 @@ func (a *App) DoLogin(w http.ResponseWriter, r *http.Request, user *model.User,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
session := &model.Session{UserId: user.Id, Roles: user.GetRawRoles(), DeviceId: deviceId, IsOAuth: false, Props: map[string]string{
|
session := &model.Session{UserId: user.Id, Roles: user.GetRawRoles(), DeviceId: deviceID, IsOAuth: false, Props: map[string]string{
|
||||||
model.USER_AUTH_SERVICE_IS_MOBILE: strconv.FormatBool(isMobile),
|
model.USER_AUTH_SERVICE_IS_MOBILE: strconv.FormatBool(isMobile),
|
||||||
model.USER_AUTH_SERVICE_IS_SAML: strconv.FormatBool(isSaml),
|
model.USER_AUTH_SERVICE_IS_SAML: strconv.FormatBool(isSaml),
|
||||||
model.USER_AUTH_SERVICE_IS_OAUTH: strconv.FormatBool(isOAuthUser),
|
model.USER_AUTH_SERVICE_IS_OAUTH: strconv.FormatBool(isOAuthUser),
|
||||||
}}
|
}}
|
||||||
session.GenerateCSRF()
|
session.GenerateCSRF()
|
||||||
|
|
||||||
if deviceId != "" {
|
if deviceID != "" {
|
||||||
a.SetSessionExpireInDays(session, *a.Config().ServiceSettings.SessionLengthMobileInDays)
|
a.SetSessionExpireInDays(session, *a.Config().ServiceSettings.SessionLengthMobileInDays)
|
||||||
|
|
||||||
// A special case where we logout of all other sessions with the same Id
|
// A special case where we logout of all other sessions with the same Id
|
||||||
if err := a.RevokeSessionsForDeviceId(user.Id, deviceId, ""); err != nil {
|
if err := a.RevokeSessionsForDeviceId(user.Id, deviceID, ""); err != nil {
|
||||||
err.StatusCode = http.StatusInternalServerError
|
err.StatusCode = http.StatusInternalServerError
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ type PushNotification struct {
|
|||||||
notificationType notificationType
|
notificationType notificationType
|
||||||
currentSessionId string
|
currentSessionId string
|
||||||
userID string
|
userID string
|
||||||
channelId string
|
channelID string
|
||||||
post *model.Post
|
post *model.Post
|
||||||
user *model.User
|
user *model.User
|
||||||
channel *model.Channel
|
channel *model.Channel
|
||||||
@@ -201,11 +201,11 @@ func (a *App) getPushNotificationMessage(contentsConfig, postMessage string, exp
|
|||||||
return senderName + userLocale("api.post.send_notifications_and_forget.push_general_message")
|
return senderName + userLocale("api.post.send_notifications_and_forget.push_general_message")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) clearPushNotificationSync(currentSessionId, userID, channelId string) *model.AppError {
|
func (a *App) clearPushNotificationSync(currentSessionId, userID, channelID string) *model.AppError {
|
||||||
msg := &model.PushNotification{
|
msg := &model.PushNotification{
|
||||||
Type: model.PUSH_TYPE_CLEAR,
|
Type: model.PUSH_TYPE_CLEAR,
|
||||||
Version: model.PUSH_MESSAGE_V2,
|
Version: model.PUSH_MESSAGE_V2,
|
||||||
ChannelId: channelId,
|
ChannelId: channelID,
|
||||||
ContentAvailable: 1,
|
ContentAvailable: 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,13 +219,13 @@ func (a *App) clearPushNotificationSync(currentSessionId, userID, channelId stri
|
|||||||
return a.sendPushNotificationToAllSessions(msg, userID, currentSessionId)
|
return a.sendPushNotificationToAllSessions(msg, userID, currentSessionId)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) clearPushNotification(currentSessionId, userID, channelId string) {
|
func (a *App) clearPushNotification(currentSessionId, userID, channelID string) {
|
||||||
select {
|
select {
|
||||||
case a.Srv().PushNotificationsHub.notificationsChan <- PushNotification{
|
case a.Srv().PushNotificationsHub.notificationsChan <- PushNotification{
|
||||||
notificationType: notificationTypeClear,
|
notificationType: notificationTypeClear,
|
||||||
currentSessionId: currentSessionId,
|
currentSessionId: currentSessionId,
|
||||||
userID: userID,
|
userID: userID,
|
||||||
channelId: channelId,
|
channelID: channelID,
|
||||||
}:
|
}:
|
||||||
case <-a.Srv().PushNotificationsHub.stopChan:
|
case <-a.Srv().PushNotificationsHub.stopChan:
|
||||||
return
|
return
|
||||||
@@ -307,7 +307,7 @@ func (hub *PushNotificationsHub) start() {
|
|||||||
var err *model.AppError
|
var err *model.AppError
|
||||||
switch notification.notificationType {
|
switch notification.notificationType {
|
||||||
case notificationTypeClear:
|
case notificationTypeClear:
|
||||||
err = hub.app.clearPushNotificationSync(notification.currentSessionId, notification.userID, notification.channelId)
|
err = hub.app.clearPushNotificationSync(notification.currentSessionId, notification.userID, notification.channelID)
|
||||||
case notificationTypeMessage:
|
case notificationTypeMessage:
|
||||||
err = hub.app.sendPushNotificationSync(
|
err = hub.app.sendPushNotificationSync(
|
||||||
notification.post,
|
notification.post,
|
||||||
@@ -485,14 +485,14 @@ func DoesNotifyPropsAllowPushNotification(user *model.User, channelNotifyProps m
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func DoesStatusAllowPushNotification(userNotifyProps model.StringMap, status *model.Status, channelId string) bool {
|
func DoesStatusAllowPushNotification(userNotifyProps model.StringMap, status *model.Status, channelID string) bool {
|
||||||
// If User status is DND or OOO return false right away
|
// If User status is DND or OOO return false right away
|
||||||
if status.Status == model.STATUS_DND || status.Status == model.STATUS_OUT_OF_OFFICE {
|
if status.Status == model.STATUS_DND || status.Status == model.STATUS_OUT_OF_OFFICE {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
pushStatus, ok := userNotifyProps[model.PUSH_STATUS_NOTIFY_PROP]
|
pushStatus, ok := userNotifyProps[model.PUSH_STATUS_NOTIFY_PROP]
|
||||||
if (pushStatus == model.STATUS_ONLINE || !ok) && (status.ActiveChannel != channelId || model.GetMillis()-status.LastActivityAt > model.STATUS_CHANNEL_TIMEOUT) {
|
if (pushStatus == model.STATUS_ONLINE || !ok) && (status.ActiveChannel != channelID || model.GetMillis()-status.LastActivityAt > model.STATUS_CHANNEL_TIMEOUT) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -354,7 +354,7 @@ func TestDoesNotifyPropsAllowPushNotification(t *testing.T) {
|
|||||||
|
|
||||||
func TestDoesStatusAllowPushNotification(t *testing.T) {
|
func TestDoesStatusAllowPushNotification(t *testing.T) {
|
||||||
userID := model.NewId()
|
userID := model.NewId()
|
||||||
channelId := model.NewId()
|
channelID := model.NewId()
|
||||||
|
|
||||||
offline := &model.Status{UserId: userID, Status: model.STATUS_OFFLINE, Manual: false, LastActivityAt: 0, ActiveChannel: ""}
|
offline := &model.Status{UserId: userID, Status: model.STATUS_OFFLINE, Manual: false, LastActivityAt: 0, ActiveChannel: ""}
|
||||||
away := &model.Status{UserId: userID, Status: model.STATUS_AWAY, Manual: false, LastActivityAt: 0, ActiveChannel: ""}
|
away := &model.Status{UserId: userID, Status: model.STATUS_AWAY, Manual: false, LastActivityAt: 0, ActiveChannel: ""}
|
||||||
@@ -365,175 +365,175 @@ func TestDoesStatusAllowPushNotification(t *testing.T) {
|
|||||||
name string
|
name string
|
||||||
userNotifySetting string
|
userNotifySetting string
|
||||||
status *model.Status
|
status *model.Status
|
||||||
channelId string
|
channelID string
|
||||||
expected bool
|
expected bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "WHEN props is ONLINE and user is offline with channel",
|
name: "WHEN props is ONLINE and user is offline with channel",
|
||||||
userNotifySetting: model.STATUS_ONLINE,
|
userNotifySetting: model.STATUS_ONLINE,
|
||||||
status: offline,
|
status: offline,
|
||||||
channelId: channelId,
|
channelID: channelID,
|
||||||
expected: true,
|
expected: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "WHEN props is ONLINE and user is offline without channel",
|
name: "WHEN props is ONLINE and user is offline without channel",
|
||||||
userNotifySetting: model.STATUS_ONLINE,
|
userNotifySetting: model.STATUS_ONLINE,
|
||||||
status: offline,
|
status: offline,
|
||||||
channelId: "",
|
channelID: "",
|
||||||
expected: true,
|
expected: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "WHEN props is ONLINE and user is away with channel",
|
name: "WHEN props is ONLINE and user is away with channel",
|
||||||
userNotifySetting: model.STATUS_ONLINE,
|
userNotifySetting: model.STATUS_ONLINE,
|
||||||
status: away,
|
status: away,
|
||||||
channelId: channelId,
|
channelID: channelID,
|
||||||
expected: true,
|
expected: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "WHEN props is ONLINE and user is away without channel",
|
name: "WHEN props is ONLINE and user is away without channel",
|
||||||
userNotifySetting: model.STATUS_ONLINE,
|
userNotifySetting: model.STATUS_ONLINE,
|
||||||
status: away,
|
status: away,
|
||||||
channelId: "",
|
channelID: "",
|
||||||
expected: true,
|
expected: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "WHEN props is ONLINE and user is online with channel",
|
name: "WHEN props is ONLINE and user is online with channel",
|
||||||
userNotifySetting: model.STATUS_ONLINE,
|
userNotifySetting: model.STATUS_ONLINE,
|
||||||
status: online,
|
status: online,
|
||||||
channelId: channelId,
|
channelID: channelID,
|
||||||
expected: true,
|
expected: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "WHEN props is ONLINE and user is online without channel",
|
name: "WHEN props is ONLINE and user is online without channel",
|
||||||
userNotifySetting: model.STATUS_ONLINE,
|
userNotifySetting: model.STATUS_ONLINE,
|
||||||
status: online,
|
status: online,
|
||||||
channelId: "",
|
channelID: "",
|
||||||
expected: false,
|
expected: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "WHEN props is ONLINE and user is dnd with channel",
|
name: "WHEN props is ONLINE and user is dnd with channel",
|
||||||
userNotifySetting: model.STATUS_ONLINE,
|
userNotifySetting: model.STATUS_ONLINE,
|
||||||
status: dnd,
|
status: dnd,
|
||||||
channelId: channelId,
|
channelID: channelID,
|
||||||
expected: false,
|
expected: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "WHEN props is ONLINE and user is dnd without channel",
|
name: "WHEN props is ONLINE and user is dnd without channel",
|
||||||
userNotifySetting: model.STATUS_ONLINE,
|
userNotifySetting: model.STATUS_ONLINE,
|
||||||
status: dnd,
|
status: dnd,
|
||||||
channelId: "",
|
channelID: "",
|
||||||
expected: false,
|
expected: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "WHEN props is AWAY and user is offline with channel",
|
name: "WHEN props is AWAY and user is offline with channel",
|
||||||
userNotifySetting: model.STATUS_AWAY,
|
userNotifySetting: model.STATUS_AWAY,
|
||||||
status: offline,
|
status: offline,
|
||||||
channelId: channelId,
|
channelID: channelID,
|
||||||
expected: true,
|
expected: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "WHEN props is AWAY and user is offline without channel",
|
name: "WHEN props is AWAY and user is offline without channel",
|
||||||
userNotifySetting: model.STATUS_AWAY,
|
userNotifySetting: model.STATUS_AWAY,
|
||||||
status: offline,
|
status: offline,
|
||||||
channelId: "",
|
channelID: "",
|
||||||
expected: true,
|
expected: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "WHEN props is AWAY and user is away with channel",
|
name: "WHEN props is AWAY and user is away with channel",
|
||||||
userNotifySetting: model.STATUS_AWAY,
|
userNotifySetting: model.STATUS_AWAY,
|
||||||
status: away,
|
status: away,
|
||||||
channelId: channelId,
|
channelID: channelID,
|
||||||
expected: true,
|
expected: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "WHEN props is AWAY and user is away without channel",
|
name: "WHEN props is AWAY and user is away without channel",
|
||||||
userNotifySetting: model.STATUS_AWAY,
|
userNotifySetting: model.STATUS_AWAY,
|
||||||
status: away,
|
status: away,
|
||||||
channelId: "",
|
channelID: "",
|
||||||
expected: true,
|
expected: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "WHEN props is AWAY and user is online with channel",
|
name: "WHEN props is AWAY and user is online with channel",
|
||||||
userNotifySetting: model.STATUS_AWAY,
|
userNotifySetting: model.STATUS_AWAY,
|
||||||
status: online,
|
status: online,
|
||||||
channelId: channelId,
|
channelID: channelID,
|
||||||
expected: false,
|
expected: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "WHEN props is AWAY and user is online without channel",
|
name: "WHEN props is AWAY and user is online without channel",
|
||||||
userNotifySetting: model.STATUS_AWAY,
|
userNotifySetting: model.STATUS_AWAY,
|
||||||
status: online,
|
status: online,
|
||||||
channelId: "",
|
channelID: "",
|
||||||
expected: false,
|
expected: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "WHEN props is AWAY and user is dnd with channel",
|
name: "WHEN props is AWAY and user is dnd with channel",
|
||||||
userNotifySetting: model.STATUS_AWAY,
|
userNotifySetting: model.STATUS_AWAY,
|
||||||
status: dnd,
|
status: dnd,
|
||||||
channelId: channelId,
|
channelID: channelID,
|
||||||
expected: false,
|
expected: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "WHEN props is AWAY and user is dnd without channel",
|
name: "WHEN props is AWAY and user is dnd without channel",
|
||||||
userNotifySetting: model.STATUS_AWAY,
|
userNotifySetting: model.STATUS_AWAY,
|
||||||
status: dnd,
|
status: dnd,
|
||||||
channelId: "",
|
channelID: "",
|
||||||
expected: false,
|
expected: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "WHEN props is OFFLINE and user is offline with channel",
|
name: "WHEN props is OFFLINE and user is offline with channel",
|
||||||
userNotifySetting: model.STATUS_OFFLINE,
|
userNotifySetting: model.STATUS_OFFLINE,
|
||||||
status: offline,
|
status: offline,
|
||||||
channelId: channelId,
|
channelID: channelID,
|
||||||
expected: true,
|
expected: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "WHEN props is OFFLINE and user is offline without channel",
|
name: "WHEN props is OFFLINE and user is offline without channel",
|
||||||
userNotifySetting: model.STATUS_OFFLINE,
|
userNotifySetting: model.STATUS_OFFLINE,
|
||||||
status: offline,
|
status: offline,
|
||||||
channelId: "",
|
channelID: "",
|
||||||
expected: true,
|
expected: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "WHEN props is OFFLINE and user is away with channel",
|
name: "WHEN props is OFFLINE and user is away with channel",
|
||||||
userNotifySetting: model.STATUS_OFFLINE,
|
userNotifySetting: model.STATUS_OFFLINE,
|
||||||
status: away,
|
status: away,
|
||||||
channelId: channelId,
|
channelID: channelID,
|
||||||
expected: false,
|
expected: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "WHEN props is OFFLINE and user is away without channel",
|
name: "WHEN props is OFFLINE and user is away without channel",
|
||||||
userNotifySetting: model.STATUS_OFFLINE,
|
userNotifySetting: model.STATUS_OFFLINE,
|
||||||
status: away,
|
status: away,
|
||||||
channelId: "",
|
channelID: "",
|
||||||
expected: false,
|
expected: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "WHEN props is OFFLINE and user is online with channel",
|
name: "WHEN props is OFFLINE and user is online with channel",
|
||||||
userNotifySetting: model.STATUS_OFFLINE,
|
userNotifySetting: model.STATUS_OFFLINE,
|
||||||
status: online,
|
status: online,
|
||||||
channelId: channelId,
|
channelID: channelID,
|
||||||
expected: false,
|
expected: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "WHEN props is OFFLINE and user is online without channel",
|
name: "WHEN props is OFFLINE and user is online without channel",
|
||||||
userNotifySetting: model.STATUS_OFFLINE,
|
userNotifySetting: model.STATUS_OFFLINE,
|
||||||
status: online,
|
status: online,
|
||||||
channelId: "",
|
channelID: "",
|
||||||
expected: false,
|
expected: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "WHEN props is OFFLINE and user is dnd with channel",
|
name: "WHEN props is OFFLINE and user is dnd with channel",
|
||||||
userNotifySetting: model.STATUS_OFFLINE,
|
userNotifySetting: model.STATUS_OFFLINE,
|
||||||
status: dnd,
|
status: dnd,
|
||||||
channelId: channelId,
|
channelID: channelID,
|
||||||
expected: false,
|
expected: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "WHEN props is OFFLINE and user is dnd without channel",
|
name: "WHEN props is OFFLINE and user is dnd without channel",
|
||||||
userNotifySetting: model.STATUS_OFFLINE,
|
userNotifySetting: model.STATUS_OFFLINE,
|
||||||
status: dnd,
|
status: dnd,
|
||||||
channelId: "",
|
channelID: "",
|
||||||
expected: false,
|
expected: false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -542,7 +542,7 @@ func TestDoesStatusAllowPushNotification(t *testing.T) {
|
|||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
userNotifyProps := make(map[string]string)
|
userNotifyProps := make(map[string]string)
|
||||||
userNotifyProps["push_status"] = tc.userNotifySetting
|
userNotifyProps["push_status"] = tc.userNotifySetting
|
||||||
assert.Equal(t, tc.expected, DoesStatusAllowPushNotification(userNotifyProps, tc.status, tc.channelId))
|
assert.Equal(t, tc.expected, DoesStatusAllowPushNotification(userNotifyProps, tc.status, tc.channelID))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
14
app/oauth.go
14
app/oauth.go
@@ -54,12 +54,12 @@ func (a *App) CreateOAuthApp(app *model.OAuthApp) (*model.OAuthApp, *model.AppEr
|
|||||||
return oauthApp, nil
|
return oauthApp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetOAuthApp(appId string) (*model.OAuthApp, *model.AppError) {
|
func (a *App) GetOAuthApp(appID string) (*model.OAuthApp, *model.AppError) {
|
||||||
if !*a.Config().ServiceSettings.EnableOAuthServiceProvider {
|
if !*a.Config().ServiceSettings.EnableOAuthServiceProvider {
|
||||||
return nil, model.NewAppError("GetOAuthApp", "api.oauth.allow_oauth.turn_off.app_error", nil, "", http.StatusNotImplemented)
|
return nil, model.NewAppError("GetOAuthApp", "api.oauth.allow_oauth.turn_off.app_error", nil, "", http.StatusNotImplemented)
|
||||||
}
|
}
|
||||||
|
|
||||||
oauthApp, err := a.Srv().Store.OAuth().GetApp(appId)
|
oauthApp, err := a.Srv().Store.OAuth().GetApp(appID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
var nfErr *store.ErrNotFound
|
var nfErr *store.ErrNotFound
|
||||||
switch {
|
switch {
|
||||||
@@ -100,12 +100,12 @@ func (a *App) UpdateOauthApp(oldApp, updatedApp *model.OAuthApp) (*model.OAuthAp
|
|||||||
return oauthApp, nil
|
return oauthApp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) DeleteOAuthApp(appId string) *model.AppError {
|
func (a *App) DeleteOAuthApp(appID string) *model.AppError {
|
||||||
if !*a.Config().ServiceSettings.EnableOAuthServiceProvider {
|
if !*a.Config().ServiceSettings.EnableOAuthServiceProvider {
|
||||||
return model.NewAppError("DeleteOAuthApp", "api.oauth.allow_oauth.turn_off.app_error", nil, "", http.StatusNotImplemented)
|
return model.NewAppError("DeleteOAuthApp", "api.oauth.allow_oauth.turn_off.app_error", nil, "", http.StatusNotImplemented)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := a.Srv().Store.OAuth().DeleteApp(appId); err != nil {
|
if err := a.Srv().Store.OAuth().DeleteApp(appID); err != nil {
|
||||||
return model.NewAppError("DeleteOAuthApp", "app.oauth.delete_app.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return model.NewAppError("DeleteOAuthApp", "app.oauth.delete_app.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -464,13 +464,13 @@ func (a *App) GetAuthorizedAppsForUser(userID string, page, perPage int) ([]*mod
|
|||||||
return apps, nil
|
return apps, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) DeauthorizeOAuthAppForUser(userID, appId string) *model.AppError {
|
func (a *App) DeauthorizeOAuthAppForUser(userID, appID string) *model.AppError {
|
||||||
if !*a.Config().ServiceSettings.EnableOAuthServiceProvider {
|
if !*a.Config().ServiceSettings.EnableOAuthServiceProvider {
|
||||||
return model.NewAppError("DeauthorizeOAuthAppForUser", "api.oauth.allow_oauth.turn_off.app_error", nil, "", http.StatusNotImplemented)
|
return model.NewAppError("DeauthorizeOAuthAppForUser", "api.oauth.allow_oauth.turn_off.app_error", nil, "", http.StatusNotImplemented)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Revoke app sessions
|
// Revoke app sessions
|
||||||
accessData, err := a.Srv().Store.OAuth().GetAccessDataByUserForApp(userID, appId)
|
accessData, err := a.Srv().Store.OAuth().GetAccessDataByUserForApp(userID, appID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return model.NewAppError("DeauthorizeOAuthAppForUser", "app.oauth.get_access_data_by_user_for_app.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return model.NewAppError("DeauthorizeOAuthAppForUser", "app.oauth.get_access_data_by_user_for_app.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
@@ -486,7 +486,7 @@ func (a *App) DeauthorizeOAuthAppForUser(userID, appId string) *model.AppError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Deauthorize the app
|
// Deauthorize the app
|
||||||
if err := a.Srv().Store.Preference().Delete(userID, model.PREFERENCE_CATEGORY_AUTHORIZED_OAUTH_APP, appId); err != nil {
|
if err := a.Srv().Store.Preference().Delete(userID, model.PREFERENCE_CATEGORY_AUTHORIZED_OAUTH_APP, appID); err != nil {
|
||||||
return model.NewAppError("DeauthorizeOAuthAppForUser", "app.preference.delete.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return model.NewAppError("DeauthorizeOAuthAppForUser", "app.preference.delete.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
@@ -31,7 +31,7 @@ import (
|
|||||||
const prepackagedPluginsDir = "prepackaged_plugins"
|
const prepackagedPluginsDir = "prepackaged_plugins"
|
||||||
|
|
||||||
type pluginSignaturePath struct {
|
type pluginSignaturePath struct {
|
||||||
pluginId string
|
pluginID string
|
||||||
path string
|
path string
|
||||||
signaturePath string
|
signaturePath string
|
||||||
}
|
}
|
||||||
@@ -91,9 +91,9 @@ func (a *App) SyncPluginsActiveState() {
|
|||||||
disabledPlugins := []*model.BundleInfo{}
|
disabledPlugins := []*model.BundleInfo{}
|
||||||
enabledPlugins := []*model.BundleInfo{}
|
enabledPlugins := []*model.BundleInfo{}
|
||||||
for _, plugin := range availablePlugins {
|
for _, plugin := range availablePlugins {
|
||||||
pluginId := plugin.Manifest.Id
|
pluginID := plugin.Manifest.Id
|
||||||
pluginEnabled := false
|
pluginEnabled := false
|
||||||
if state, ok := config.PluginStates[pluginId]; ok {
|
if state, ok := config.PluginStates[pluginID]; ok {
|
||||||
pluginEnabled = state.Enable
|
pluginEnabled = state.Enable
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,8 +128,8 @@ func (a *App) SyncPluginsActiveState() {
|
|||||||
go func(plugin *model.BundleInfo) {
|
go func(plugin *model.BundleInfo) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
|
|
||||||
pluginId := plugin.Manifest.Id
|
pluginID := plugin.Manifest.Id
|
||||||
updatedManifest, activated, err := pluginsEnvironment.Activate(pluginId)
|
updatedManifest, activated, err := pluginsEnvironment.Activate(pluginID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
plugin.WrapLogger(a.Log()).Error("Unable to activate plugin", mlog.Err(err))
|
plugin.WrapLogger(a.Log()).Error("Unable to activate plugin", mlog.Err(err))
|
||||||
return
|
return
|
||||||
@@ -494,7 +494,7 @@ func (a *App) GetMarketplacePlugins(filter *model.MarketplacePluginFilter) ([]*m
|
|||||||
}
|
}
|
||||||
|
|
||||||
// getPrepackagedPlugin returns a pre-packaged plugin.
|
// getPrepackagedPlugin returns a pre-packaged plugin.
|
||||||
func (a *App) getPrepackagedPlugin(pluginId, version string) (*plugin.PrepackagedPlugin, *model.AppError) {
|
func (a *App) getPrepackagedPlugin(pluginID, version string) (*plugin.PrepackagedPlugin, *model.AppError) {
|
||||||
pluginsEnvironment := a.GetPluginsEnvironment()
|
pluginsEnvironment := a.GetPluginsEnvironment()
|
||||||
if pluginsEnvironment == nil {
|
if pluginsEnvironment == nil {
|
||||||
return nil, model.NewAppError("getPrepackagedPlugin", "app.plugin.config.app_error", nil, "plugin environment is nil", http.StatusInternalServerError)
|
return nil, model.NewAppError("getPrepackagedPlugin", "app.plugin.config.app_error", nil, "plugin environment is nil", http.StatusInternalServerError)
|
||||||
@@ -502,7 +502,7 @@ func (a *App) getPrepackagedPlugin(pluginId, version string) (*plugin.Prepackage
|
|||||||
|
|
||||||
prepackagedPlugins := pluginsEnvironment.PrepackagedPlugins()
|
prepackagedPlugins := pluginsEnvironment.PrepackagedPlugins()
|
||||||
for _, p := range prepackagedPlugins {
|
for _, p := range prepackagedPlugins {
|
||||||
if p.Manifest.Id == pluginId && p.Manifest.Version == version {
|
if p.Manifest.Id == pluginID && p.Manifest.Version == version {
|
||||||
return p, nil
|
return p, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -511,7 +511,7 @@ func (a *App) getPrepackagedPlugin(pluginId, version string) (*plugin.Prepackage
|
|||||||
}
|
}
|
||||||
|
|
||||||
// getRemoteMarketplacePlugin returns plugin from marketplace-server.
|
// getRemoteMarketplacePlugin returns plugin from marketplace-server.
|
||||||
func (a *App) getRemoteMarketplacePlugin(pluginId, version string) (*model.BaseMarketplacePlugin, *model.AppError) {
|
func (a *App) getRemoteMarketplacePlugin(pluginID, version string) (*model.BaseMarketplacePlugin, *model.AppError) {
|
||||||
marketplaceClient, err := marketplace.NewClient(
|
marketplaceClient, err := marketplace.NewClient(
|
||||||
*a.Config().PluginSettings.MarketplaceUrl,
|
*a.Config().PluginSettings.MarketplaceUrl,
|
||||||
a.HTTPService(),
|
a.HTTPService(),
|
||||||
@@ -521,7 +521,7 @@ func (a *App) getRemoteMarketplacePlugin(pluginId, version string) (*model.BaseM
|
|||||||
}
|
}
|
||||||
|
|
||||||
filter := a.getBaseMarketplaceFilter()
|
filter := a.getBaseMarketplaceFilter()
|
||||||
filter.PluginId = pluginId
|
filter.PluginId = pluginID
|
||||||
filter.ReturnAllVersions = true
|
filter.ReturnAllVersions = true
|
||||||
|
|
||||||
plugin, err := marketplaceClient.GetPlugin(filter, version)
|
plugin, err := marketplaceClient.GetPlugin(filter, version)
|
||||||
@@ -791,7 +791,7 @@ func (a *App) getPluginsFromFilePaths(fileStorePaths []string) map[string]*plugi
|
|||||||
if strings.HasSuffix(path, ".tar.gz") {
|
if strings.HasSuffix(path, ".tar.gz") {
|
||||||
id := strings.TrimSuffix(filepath.Base(path), ".tar.gz")
|
id := strings.TrimSuffix(filepath.Base(path), ".tar.gz")
|
||||||
helper := &pluginSignaturePath{
|
helper := &pluginSignaturePath{
|
||||||
pluginId: id,
|
pluginID: id,
|
||||||
path: path,
|
path: path,
|
||||||
signaturePath: "",
|
signaturePath: "",
|
||||||
}
|
}
|
||||||
@@ -907,16 +907,16 @@ func (a *App) installFeatureFlagPlugins() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for pluginId, version := range ffControledPlugins {
|
for pluginID, version := range ffControledPlugins {
|
||||||
// Skip installing if the plugin has been previously disabled.
|
// Skip installing if the plugin has been previously disabled.
|
||||||
pluginState := a.Config().PluginSettings.PluginStates[pluginId]
|
pluginState := a.Config().PluginSettings.PluginStates[pluginID]
|
||||||
if pluginState != nil && !pluginState.Enable {
|
if pluginState != nil && !pluginState.Enable {
|
||||||
a.Log().Debug("Not auto installing/upgrade because plugin was disabled", mlog.String("plugin_id", pluginId), mlog.String("version", version))
|
a.Log().Debug("Not auto installing/upgrade because plugin was disabled", mlog.String("plugin_id", pluginID), mlog.String("version", version))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if we already installed this version as InstallMarketplacePlugin can't handle re-installs well.
|
// Check if we already installed this version as InstallMarketplacePlugin can't handle re-installs well.
|
||||||
pluginStatus, err := a.Srv().GetPluginStatus(pluginId)
|
pluginStatus, err := a.Srv().GetPluginStatus(pluginID)
|
||||||
pluginExists := err == nil
|
pluginExists := err == nil
|
||||||
if pluginExists && pluginStatus.Version == version {
|
if pluginExists && pluginStatus.Version == version {
|
||||||
continue
|
continue
|
||||||
@@ -929,32 +929,32 @@ func (a *App) installFeatureFlagPlugins() {
|
|||||||
if !inCloud && pluginExists {
|
if !inCloud && pluginExists {
|
||||||
parsedVersion, err := semver.Parse(version)
|
parsedVersion, err := semver.Parse(version)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.Log().Debug("Bad version from feature flag", mlog.String("plugin_id", pluginId), mlog.Err(err), mlog.String("version", version))
|
a.Log().Debug("Bad version from feature flag", mlog.String("plugin_id", pluginID), mlog.Err(err), mlog.String("version", version))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
parsedExistingVersion, err := semver.Parse(pluginStatus.Version)
|
parsedExistingVersion, err := semver.Parse(pluginStatus.Version)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.Log().Debug("Bad version from plugin manifest", mlog.String("plugin_id", pluginId), mlog.Err(err), mlog.String("version", pluginStatus.Version))
|
a.Log().Debug("Bad version from plugin manifest", mlog.String("plugin_id", pluginID), mlog.Err(err), mlog.String("version", pluginStatus.Version))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if parsedVersion.LTE(parsedExistingVersion) {
|
if parsedVersion.LTE(parsedExistingVersion) {
|
||||||
a.Log().Debug("Skip installation because given version was a downgrade and on-prem installations should not downgrade.", mlog.String("plugin_id", pluginId), mlog.Err(err), mlog.String("version", pluginStatus.Version))
|
a.Log().Debug("Skip installation because given version was a downgrade and on-prem installations should not downgrade.", mlog.String("plugin_id", pluginID), mlog.Err(err), mlog.String("version", pluginStatus.Version))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := a.InstallMarketplacePlugin(&model.InstallMarketplacePluginRequest{
|
_, err := a.InstallMarketplacePlugin(&model.InstallMarketplacePluginRequest{
|
||||||
Id: pluginId,
|
Id: pluginID,
|
||||||
Version: version,
|
Version: version,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.Log().Debug("Unable to install plugin from FF manifest", mlog.String("plugin_id", pluginId), mlog.Err(err), mlog.String("version", version))
|
a.Log().Debug("Unable to install plugin from FF manifest", mlog.String("plugin_id", pluginID), mlog.Err(err), mlog.String("version", version))
|
||||||
} else {
|
} else {
|
||||||
if err := a.EnablePlugin(pluginId); err != nil {
|
if err := a.EnablePlugin(pluginID); err != nil {
|
||||||
a.Log().Debug("Unable to enable plugin installed from feature flag.", mlog.String("plugin_id", pluginId), mlog.Err(err), mlog.String("version", version))
|
a.Log().Debug("Unable to enable plugin installed from feature flag.", mlog.String("plugin_id", pluginID), mlog.Err(err), mlog.String("version", version))
|
||||||
} else {
|
} else {
|
||||||
a.Log().Debug("Installed and enabled plugin.", mlog.String("plugin_id", pluginId), mlog.String("version", version))
|
a.Log().Debug("Installed and enabled plugin.", mlog.String("plugin_id", pluginID), mlog.String("version", version))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,8 +85,8 @@ func (api *PluginAPI) ExecuteSlashCommand(commandArgs *model.CommandArgs) (*mode
|
|||||||
return response, nil
|
return response, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PluginAPI) GetSession(sessionId string) (*model.Session, *model.AppError) {
|
func (api *PluginAPI) GetSession(sessionID string) (*model.Session, *model.AppError) {
|
||||||
session, err := api.app.GetSessionById(sessionId)
|
session, err := api.app.GetSessionById(sessionID)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -311,17 +311,17 @@ func (api *PluginAPI) UpdateUserStatus(userID, status string) (*model.Status, *m
|
|||||||
return api.app.GetStatus(userID)
|
return api.app.GetStatus(userID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PluginAPI) GetUsersInChannel(channelId, sortBy string, page, perPage int) ([]*model.User, *model.AppError) {
|
func (api *PluginAPI) GetUsersInChannel(channelID, sortBy string, page, perPage int) ([]*model.User, *model.AppError) {
|
||||||
switch sortBy {
|
switch sortBy {
|
||||||
case model.CHANNEL_SORT_BY_USERNAME:
|
case model.CHANNEL_SORT_BY_USERNAME:
|
||||||
return api.app.GetUsersInChannel(&model.UserGetOptions{
|
return api.app.GetUsersInChannel(&model.UserGetOptions{
|
||||||
InChannelId: channelId,
|
InChannelId: channelID,
|
||||||
Page: page,
|
Page: page,
|
||||||
PerPage: perPage,
|
PerPage: perPage,
|
||||||
})
|
})
|
||||||
case model.CHANNEL_SORT_BY_STATUS:
|
case model.CHANNEL_SORT_BY_STATUS:
|
||||||
return api.app.GetUsersInChannelByStatus(&model.UserGetOptions{
|
return api.app.GetUsersInChannelByStatus(&model.UserGetOptions{
|
||||||
InChannelId: channelId,
|
InChannelId: channelID,
|
||||||
Page: page,
|
Page: page,
|
||||||
PerPage: perPage,
|
PerPage: perPage,
|
||||||
})
|
})
|
||||||
@@ -357,8 +357,8 @@ func (api *PluginAPI) CreateChannel(channel *model.Channel) (*model.Channel, *mo
|
|||||||
return api.app.CreateChannel(channel, false)
|
return api.app.CreateChannel(channel, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PluginAPI) DeleteChannel(channelId string) *model.AppError {
|
func (api *PluginAPI) DeleteChannel(channelID string) *model.AppError {
|
||||||
channel, err := api.app.GetChannel(channelId)
|
channel, err := api.app.GetChannel(channelID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -373,8 +373,8 @@ func (api *PluginAPI) GetPublicChannelsForTeam(teamID string, page, perPage int)
|
|||||||
return *channels, err
|
return *channels, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PluginAPI) GetChannel(channelId string) (*model.Channel, *model.AppError) {
|
func (api *PluginAPI) GetChannel(channelID string) (*model.Channel, *model.AppError) {
|
||||||
return api.app.GetChannel(channelId)
|
return api.app.GetChannel(channelID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PluginAPI) GetChannelByName(teamID, name string, includeDeleted bool) (*model.Channel, *model.AppError) {
|
func (api *PluginAPI) GetChannelByName(teamID, name string, includeDeleted bool) (*model.Channel, *model.AppError) {
|
||||||
@@ -393,16 +393,16 @@ func (api *PluginAPI) GetChannelsForTeamForUser(teamID, userID string, includeDe
|
|||||||
return *channels, err
|
return *channels, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PluginAPI) GetChannelStats(channelId string) (*model.ChannelStats, *model.AppError) {
|
func (api *PluginAPI) GetChannelStats(channelID string) (*model.ChannelStats, *model.AppError) {
|
||||||
memberCount, err := api.app.GetChannelMemberCount(channelId)
|
memberCount, err := api.app.GetChannelMemberCount(channelID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
guestCount, err := api.app.GetChannelMemberCount(channelId)
|
guestCount, err := api.app.GetChannelMemberCount(channelID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &model.ChannelStats{ChannelId: channelId, MemberCount: memberCount, GuestCount: guestCount}, nil
|
return &model.ChannelStats{ChannelId: channelID, MemberCount: memberCount, GuestCount: guestCount}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PluginAPI) GetDirectChannel(userID1, userID2 string) (*model.Channel, *model.AppError) {
|
func (api *PluginAPI) GetDirectChannel(userID1, userID2 string) (*model.Channel, *model.AppError) {
|
||||||
@@ -476,12 +476,12 @@ func (api *PluginAPI) SearchPostsInTeamForUser(teamID string, userID string, sea
|
|||||||
return api.app.SearchPostsInTeamForUser(terms, userID, teamID, isOrSearch, includeDeletedChannels, timeZoneOffset, page, perPage)
|
return api.app.SearchPostsInTeamForUser(terms, userID, teamID, isOrSearch, includeDeletedChannels, timeZoneOffset, page, perPage)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PluginAPI) AddChannelMember(channelId, userID string) (*model.ChannelMember, *model.AppError) {
|
func (api *PluginAPI) AddChannelMember(channelID, userID string) (*model.ChannelMember, *model.AppError) {
|
||||||
// For now, don't allow overriding these via the plugin API.
|
// For now, don't allow overriding these via the plugin API.
|
||||||
userRequestorId := ""
|
userRequestorId := ""
|
||||||
postRootId := ""
|
postRootId := ""
|
||||||
|
|
||||||
channel, err := api.GetChannel(channelId)
|
channel, err := api.GetChannel(channelID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -489,10 +489,10 @@ func (api *PluginAPI) AddChannelMember(channelId, userID string) (*model.Channel
|
|||||||
return api.app.AddChannelMember(userID, channel, userRequestorId, postRootId)
|
return api.app.AddChannelMember(userID, channel, userRequestorId, postRootId)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PluginAPI) AddUserToChannel(channelId, userID, asUserId string) (*model.ChannelMember, *model.AppError) {
|
func (api *PluginAPI) AddUserToChannel(channelID, userID, asUserId string) (*model.ChannelMember, *model.AppError) {
|
||||||
postRootId := ""
|
postRootId := ""
|
||||||
|
|
||||||
channel, err := api.GetChannel(channelId)
|
channel, err := api.GetChannel(channelID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -500,32 +500,32 @@ func (api *PluginAPI) AddUserToChannel(channelId, userID, asUserId string) (*mod
|
|||||||
return api.app.AddChannelMember(userID, channel, asUserId, postRootId)
|
return api.app.AddChannelMember(userID, channel, asUserId, postRootId)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PluginAPI) GetChannelMember(channelId, userID string) (*model.ChannelMember, *model.AppError) {
|
func (api *PluginAPI) GetChannelMember(channelID, userID string) (*model.ChannelMember, *model.AppError) {
|
||||||
return api.app.GetChannelMember(channelId, userID)
|
return api.app.GetChannelMember(channelID, userID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PluginAPI) GetChannelMembers(channelId string, page, perPage int) (*model.ChannelMembers, *model.AppError) {
|
func (api *PluginAPI) GetChannelMembers(channelID string, page, perPage int) (*model.ChannelMembers, *model.AppError) {
|
||||||
return api.app.GetChannelMembersPage(channelId, page, perPage)
|
return api.app.GetChannelMembersPage(channelID, page, perPage)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PluginAPI) GetChannelMembersByIds(channelId string, userIDs []string) (*model.ChannelMembers, *model.AppError) {
|
func (api *PluginAPI) GetChannelMembersByIds(channelID string, userIDs []string) (*model.ChannelMembers, *model.AppError) {
|
||||||
return api.app.GetChannelMembersByIds(channelId, userIDs)
|
return api.app.GetChannelMembersByIds(channelID, userIDs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PluginAPI) GetChannelMembersForUser(teamID, userID string, page, perPage int) ([]*model.ChannelMember, *model.AppError) {
|
func (api *PluginAPI) GetChannelMembersForUser(teamID, userID string, page, perPage int) ([]*model.ChannelMember, *model.AppError) {
|
||||||
return api.app.GetChannelMembersForUserWithPagination(teamID, userID, page, perPage)
|
return api.app.GetChannelMembersForUserWithPagination(teamID, userID, page, perPage)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PluginAPI) UpdateChannelMemberRoles(channelId, userID, newRoles string) (*model.ChannelMember, *model.AppError) {
|
func (api *PluginAPI) UpdateChannelMemberRoles(channelID, userID, newRoles string) (*model.ChannelMember, *model.AppError) {
|
||||||
return api.app.UpdateChannelMemberRoles(channelId, userID, newRoles)
|
return api.app.UpdateChannelMemberRoles(channelID, userID, newRoles)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PluginAPI) UpdateChannelMemberNotifications(channelId, userID string, notifications map[string]string) (*model.ChannelMember, *model.AppError) {
|
func (api *PluginAPI) UpdateChannelMemberNotifications(channelID, userID string, notifications map[string]string) (*model.ChannelMember, *model.AppError) {
|
||||||
return api.app.UpdateChannelMemberNotifyProps(notifications, channelId, userID)
|
return api.app.UpdateChannelMemberNotifyProps(notifications, channelID, userID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PluginAPI) DeleteChannelMember(channelId, userID string) *model.AppError {
|
func (api *PluginAPI) DeleteChannelMember(channelID, userID string) *model.AppError {
|
||||||
return api.app.LeaveChannel(channelId, userID)
|
return api.app.LeaveChannel(channelID, userID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PluginAPI) GetGroup(groupId string) (*model.Group, *model.AppError) {
|
func (api *PluginAPI) GetGroup(groupId string) (*model.Group, *model.AppError) {
|
||||||
@@ -552,8 +552,8 @@ func (api *PluginAPI) RemoveReaction(reaction *model.Reaction) *model.AppError {
|
|||||||
return api.app.DeleteReactionForPost(reaction)
|
return api.app.DeleteReactionForPost(reaction)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PluginAPI) GetReactions(postId string) ([]*model.Reaction, *model.AppError) {
|
func (api *PluginAPI) GetReactions(postID string) ([]*model.Reaction, *model.AppError) {
|
||||||
return api.app.GetReactionsForPost(postId)
|
return api.app.GetReactionsForPost(postID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PluginAPI) SendEphemeralPost(userID string, post *model.Post) *model.Post {
|
func (api *PluginAPI) SendEphemeralPost(userID string, post *model.Post) *model.Post {
|
||||||
@@ -564,37 +564,37 @@ func (api *PluginAPI) UpdateEphemeralPost(userID string, post *model.Post) *mode
|
|||||||
return api.app.UpdateEphemeralPost(userID, post)
|
return api.app.UpdateEphemeralPost(userID, post)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PluginAPI) DeleteEphemeralPost(userID, postId string) {
|
func (api *PluginAPI) DeleteEphemeralPost(userID, postID string) {
|
||||||
api.app.DeleteEphemeralPost(userID, postId)
|
api.app.DeleteEphemeralPost(userID, postID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PluginAPI) DeletePost(postId string) *model.AppError {
|
func (api *PluginAPI) DeletePost(postID string) *model.AppError {
|
||||||
_, err := api.app.DeletePost(postId, api.id)
|
_, err := api.app.DeletePost(postID, api.id)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PluginAPI) GetPostThread(postId string) (*model.PostList, *model.AppError) {
|
func (api *PluginAPI) GetPostThread(postID string) (*model.PostList, *model.AppError) {
|
||||||
return api.app.GetPostThread(postId, false, false, false)
|
return api.app.GetPostThread(postID, false, false, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PluginAPI) GetPost(postId string) (*model.Post, *model.AppError) {
|
func (api *PluginAPI) GetPost(postID string) (*model.Post, *model.AppError) {
|
||||||
return api.app.GetSinglePost(postId)
|
return api.app.GetSinglePost(postID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PluginAPI) GetPostsSince(channelId string, time int64) (*model.PostList, *model.AppError) {
|
func (api *PluginAPI) GetPostsSince(channelID string, time int64) (*model.PostList, *model.AppError) {
|
||||||
return api.app.GetPostsSince(model.GetPostsSinceOptions{ChannelId: channelId, Time: time})
|
return api.app.GetPostsSince(model.GetPostsSinceOptions{ChannelId: channelID, Time: time})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PluginAPI) GetPostsAfter(channelId, postId string, page, perPage int) (*model.PostList, *model.AppError) {
|
func (api *PluginAPI) GetPostsAfter(channelID, postID string, page, perPage int) (*model.PostList, *model.AppError) {
|
||||||
return api.app.GetPostsAfterPost(model.GetPostsOptions{ChannelId: channelId, PostId: postId, Page: page, PerPage: perPage})
|
return api.app.GetPostsAfterPost(model.GetPostsOptions{ChannelId: channelID, PostId: postID, Page: page, PerPage: perPage})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PluginAPI) GetPostsBefore(channelId, postId string, page, perPage int) (*model.PostList, *model.AppError) {
|
func (api *PluginAPI) GetPostsBefore(channelID, postID string, page, perPage int) (*model.PostList, *model.AppError) {
|
||||||
return api.app.GetPostsBeforePost(model.GetPostsOptions{ChannelId: channelId, PostId: postId, Page: page, PerPage: perPage})
|
return api.app.GetPostsBeforePost(model.GetPostsOptions{ChannelId: channelID, PostId: postID, Page: page, PerPage: perPage})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PluginAPI) GetPostsForChannel(channelId string, page, perPage int) (*model.PostList, *model.AppError) {
|
func (api *PluginAPI) GetPostsForChannel(channelID string, page, perPage int) (*model.PostList, *model.AppError) {
|
||||||
return api.app.GetPostsPage(model.GetPostsOptions{ChannelId: channelId, Page: page, PerPage: perPage})
|
return api.app.GetPostsPage(model.GetPostsOptions{ChannelId: channelID, Page: page, PerPage: perPage})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PluginAPI) UpdatePost(post *model.Post) (*model.Post, *model.AppError) {
|
func (api *PluginAPI) UpdatePost(post *model.Post) (*model.Post, *model.AppError) {
|
||||||
@@ -632,24 +632,24 @@ func (api *PluginAPI) GetEmoji(emojiId string) (*model.Emoji, *model.AppError) {
|
|||||||
return api.app.GetEmoji(emojiId)
|
return api.app.GetEmoji(emojiId)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PluginAPI) CopyFileInfos(userID string, fileIds []string) ([]string, *model.AppError) {
|
func (api *PluginAPI) CopyFileInfos(userID string, fileIDs []string) ([]string, *model.AppError) {
|
||||||
return api.app.CopyFileInfos(userID, fileIds)
|
return api.app.CopyFileInfos(userID, fileIDs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PluginAPI) GetFileInfo(fileId string) (*model.FileInfo, *model.AppError) {
|
func (api *PluginAPI) GetFileInfo(fileID string) (*model.FileInfo, *model.AppError) {
|
||||||
return api.app.GetFileInfo(fileId)
|
return api.app.GetFileInfo(fileID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PluginAPI) GetFileInfos(page, perPage int, opt *model.GetFileInfosOptions) ([]*model.FileInfo, *model.AppError) {
|
func (api *PluginAPI) GetFileInfos(page, perPage int, opt *model.GetFileInfosOptions) ([]*model.FileInfo, *model.AppError) {
|
||||||
return api.app.GetFileInfos(page, perPage, opt)
|
return api.app.GetFileInfos(page, perPage, opt)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PluginAPI) GetFileLink(fileId string) (string, *model.AppError) {
|
func (api *PluginAPI) GetFileLink(fileID string) (string, *model.AppError) {
|
||||||
if !*api.app.Config().FileSettings.EnablePublicLink {
|
if !*api.app.Config().FileSettings.EnablePublicLink {
|
||||||
return "", model.NewAppError("GetFileLink", "plugin_api.get_file_link.disabled.app_error", nil, "", http.StatusNotImplemented)
|
return "", model.NewAppError("GetFileLink", "plugin_api.get_file_link.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||||
}
|
}
|
||||||
|
|
||||||
info, err := api.app.GetFileInfo(fileId)
|
info, err := api.app.GetFileInfo(fileID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
@@ -665,12 +665,12 @@ func (api *PluginAPI) ReadFile(path string) ([]byte, *model.AppError) {
|
|||||||
return api.app.ReadFile(path)
|
return api.app.ReadFile(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PluginAPI) GetFile(fileId string) ([]byte, *model.AppError) {
|
func (api *PluginAPI) GetFile(fileID string) ([]byte, *model.AppError) {
|
||||||
return api.app.GetFile(fileId)
|
return api.app.GetFile(fileID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PluginAPI) UploadFile(data []byte, channelId string, filename string) (*model.FileInfo, *model.AppError) {
|
func (api *PluginAPI) UploadFile(data []byte, channelID string, filename string) (*model.FileInfo, *model.AppError) {
|
||||||
return api.app.UploadFile(data, channelId, filename)
|
return api.app.UploadFile(data, channelID, filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PluginAPI) GetEmojiImage(emojiId string) ([]byte, string, *model.AppError) {
|
func (api *PluginAPI) GetEmojiImage(emojiId string) ([]byte, string, *model.AppError) {
|
||||||
@@ -836,8 +836,8 @@ func (api *PluginAPI) HasPermissionToTeam(userID, teamID string, permission *mod
|
|||||||
return api.app.HasPermissionToTeam(userID, teamID, permission)
|
return api.app.HasPermissionToTeam(userID, teamID, permission)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PluginAPI) HasPermissionToChannel(userID, channelId string, permission *model.Permission) bool {
|
func (api *PluginAPI) HasPermissionToChannel(userID, channelID string, permission *model.Permission) bool {
|
||||||
return api.app.HasPermissionToChannel(userID, channelId, permission)
|
return api.app.HasPermissionToChannel(userID, channelID, permission)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PluginAPI) LogDebug(msg string, keyValuePairs ...interface{}) {
|
func (api *PluginAPI) LogDebug(msg string, keyValuePairs ...interface{}) {
|
||||||
@@ -915,8 +915,8 @@ func (api *PluginAPI) DeleteBotIconImage(userID string) *model.AppError {
|
|||||||
return api.app.DeleteBotIconImage(userID)
|
return api.app.DeleteBotIconImage(userID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PluginAPI) PublishUserTyping(userID, channelId, parentId string) *model.AppError {
|
func (api *PluginAPI) PublishUserTyping(userID, channelID, parentId string) *model.AppError {
|
||||||
return api.app.PublishUserTyping(userID, channelId, parentId)
|
return api.app.PublishUserTyping(userID, channelID, parentId)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PluginAPI) PluginHTTP(request *http.Request) *http.Response {
|
func (api *PluginAPI) PluginHTTP(request *http.Request) *http.Response {
|
||||||
|
|||||||
@@ -51,9 +51,9 @@ func getDefaultPluginSettingsSchema() string {
|
|||||||
return string(ret)
|
return string(ret)
|
||||||
}
|
}
|
||||||
|
|
||||||
func setDefaultPluginConfig(th *TestHelper, pluginId string) {
|
func setDefaultPluginConfig(th *TestHelper, pluginID string) {
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
cfg.PluginSettings.Plugins[pluginId] = map[string]interface{}{
|
cfg.PluginSettings.Plugins[pluginID] = map[string]interface{}{
|
||||||
"BasicChannelName": th.BasicChannel.Name,
|
"BasicChannelName": th.BasicChannel.Name,
|
||||||
"BasicChannelId": th.BasicChannel.Id,
|
"BasicChannelId": th.BasicChannel.Id,
|
||||||
"BasicTeamName": th.BasicTeam.Name,
|
"BasicTeamName": th.BasicTeam.Name,
|
||||||
@@ -68,7 +68,7 @@ func setDefaultPluginConfig(th *TestHelper, pluginId string) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupMultiPluginApiTest(t *testing.T, pluginCodes []string, pluginManifests []string, pluginIds []string, app *App) string {
|
func setupMultiPluginApiTest(t *testing.T, pluginCodes []string, pluginManifests []string, pluginIDs []string, app *App) string {
|
||||||
pluginDir, err := ioutil.TempDir("", "")
|
pluginDir, err := ioutil.TempDir("", "")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
t.Cleanup(func() {
|
t.Cleanup(func() {
|
||||||
@@ -90,21 +90,21 @@ func setupMultiPluginApiTest(t *testing.T, pluginCodes []string, pluginManifests
|
|||||||
env, err := plugin.NewEnvironment(app.NewPluginAPI, pluginDir, webappPluginDir, app.Log(), nil)
|
env, err := plugin.NewEnvironment(app.NewPluginAPI, pluginDir, webappPluginDir, app.Log(), nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
require.Equal(t, len(pluginCodes), len(pluginIds))
|
require.Equal(t, len(pluginCodes), len(pluginIDs))
|
||||||
require.Equal(t, len(pluginManifests), len(pluginIds))
|
require.Equal(t, len(pluginManifests), len(pluginIDs))
|
||||||
|
|
||||||
for i, pluginId := range pluginIds {
|
for i, pluginID := range pluginIDs {
|
||||||
backend := filepath.Join(pluginDir, pluginId, "backend.exe")
|
backend := filepath.Join(pluginDir, pluginID, "backend.exe")
|
||||||
utils.CompileGo(t, pluginCodes[i], backend)
|
utils.CompileGo(t, pluginCodes[i], backend)
|
||||||
|
|
||||||
ioutil.WriteFile(filepath.Join(pluginDir, pluginId, "plugin.json"), []byte(pluginManifests[i]), 0600)
|
ioutil.WriteFile(filepath.Join(pluginDir, pluginID, "plugin.json"), []byte(pluginManifests[i]), 0600)
|
||||||
manifest, activated, reterr := env.Activate(pluginId)
|
manifest, activated, reterr := env.Activate(pluginID)
|
||||||
require.NoError(t, reterr)
|
require.NoError(t, reterr)
|
||||||
require.NotNil(t, manifest)
|
require.NotNil(t, manifest)
|
||||||
require.True(t, activated)
|
require.True(t, activated)
|
||||||
|
|
||||||
app.UpdateConfig(func(cfg *model.Config) {
|
app.UpdateConfig(func(cfg *model.Config) {
|
||||||
cfg.PluginSettings.PluginStates[pluginId] = &model.PluginState{
|
cfg.PluginSettings.PluginStates[pluginID] = &model.PluginState{
|
||||||
Enable: true,
|
Enable: true,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -115,8 +115,8 @@ func setupMultiPluginApiTest(t *testing.T, pluginCodes []string, pluginManifests
|
|||||||
return pluginDir
|
return pluginDir
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupPluginApiTest(t *testing.T, pluginCode string, pluginManifest string, pluginId string, app *App) string {
|
func setupPluginApiTest(t *testing.T, pluginCode string, pluginManifest string, pluginID string, app *App) string {
|
||||||
return setupMultiPluginApiTest(t, []string{pluginCode}, []string{pluginManifest}, []string{pluginId}, app)
|
return setupMultiPluginApiTest(t, []string{pluginCode}, []string{pluginManifest}, []string{pluginID}, app)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPublicFilesPathConfiguration(t *testing.T) {
|
func TestPublicFilesPathConfiguration(t *testing.T) {
|
||||||
@@ -1263,9 +1263,9 @@ func TestPluginCreatePostWithUploadedFile(t *testing.T) {
|
|||||||
api := th.SetupPluginAPI()
|
api := th.SetupPluginAPI()
|
||||||
|
|
||||||
data := []byte("Hello World")
|
data := []byte("Hello World")
|
||||||
channelId := th.BasicChannel.Id
|
channelID := th.BasicChannel.Id
|
||||||
filename := "testGetFile"
|
filename := "testGetFile"
|
||||||
fileInfo, err := api.UploadFile(data, channelId, filename)
|
fileInfo, err := api.UploadFile(data, channelID, filename)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
defer func() {
|
defer func() {
|
||||||
th.App.Srv().Store.FileInfo().PermanentDelete(fileInfo.Id)
|
th.App.Srv().Store.FileInfo().PermanentDelete(fileInfo.Id)
|
||||||
@@ -1280,7 +1280,7 @@ func TestPluginCreatePostWithUploadedFile(t *testing.T) {
|
|||||||
post, err := api.CreatePost(&model.Post{
|
post, err := api.CreatePost(&model.Post{
|
||||||
Message: "test",
|
Message: "test",
|
||||||
UserId: userID,
|
UserId: userID,
|
||||||
ChannelId: channelId,
|
ChannelId: channelID,
|
||||||
FileIds: model.StringArray{fileInfo.Id},
|
FileIds: model.StringArray{fileInfo.Id},
|
||||||
})
|
})
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
@@ -1496,8 +1496,8 @@ func TestApiMetrics(t *testing.T) {
|
|||||||
|
|
||||||
th.App.SetPluginsEnvironment(env)
|
th.App.SetPluginsEnvironment(env)
|
||||||
|
|
||||||
pluginId := model.NewId()
|
pluginID := model.NewId()
|
||||||
backend := filepath.Join(pluginDir, pluginId, "backend.exe")
|
backend := filepath.Join(pluginDir, pluginID, "backend.exe")
|
||||||
code :=
|
code :=
|
||||||
`
|
`
|
||||||
package main
|
package main
|
||||||
@@ -1521,7 +1521,7 @@ func TestApiMetrics(t *testing.T) {
|
|||||||
}
|
}
|
||||||
`
|
`
|
||||||
utils.CompileGo(t, code, backend)
|
utils.CompileGo(t, code, backend)
|
||||||
ioutil.WriteFile(filepath.Join(pluginDir, pluginId, "plugin.json"), []byte(`{"id": "`+pluginId+`", "backend": {"executable": "backend.exe"}}`), 0600)
|
ioutil.WriteFile(filepath.Join(pluginDir, pluginID, "plugin.json"), []byte(`{"id": "`+pluginID+`", "backend": {"executable": "backend.exe"}}`), 0600)
|
||||||
|
|
||||||
// Don't care about these mocks
|
// Don't care about these mocks
|
||||||
metricsMock.On("ObservePluginHookDuration", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return()
|
metricsMock.On("ObservePluginHookDuration", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return()
|
||||||
@@ -1529,12 +1529,12 @@ func TestApiMetrics(t *testing.T) {
|
|||||||
metricsMock.On("ObservePluginMultiHookDuration", mock.Anything).Return()
|
metricsMock.On("ObservePluginMultiHookDuration", mock.Anything).Return()
|
||||||
|
|
||||||
// Setup mocks
|
// Setup mocks
|
||||||
metricsMock.On("ObservePluginApiDuration", pluginId, "UpdateUser", true, mock.Anything).Return()
|
metricsMock.On("ObservePluginApiDuration", pluginID, "UpdateUser", true, mock.Anything).Return()
|
||||||
|
|
||||||
_, _, activationErr := env.Activate(pluginId)
|
_, _, activationErr := env.Activate(pluginID)
|
||||||
require.NoError(t, activationErr)
|
require.NoError(t, activationErr)
|
||||||
|
|
||||||
require.True(t, th.App.GetPluginsEnvironment().IsActive(pluginId))
|
require.True(t, th.App.GetPluginsEnvironment().IsActive(pluginID))
|
||||||
|
|
||||||
user1 := &model.User{
|
user1 := &model.User{
|
||||||
Email: model.NewId() + "success+test@example.com",
|
Email: model.NewId() + "success+test@example.com",
|
||||||
@@ -1551,8 +1551,8 @@ func TestApiMetrics(t *testing.T) {
|
|||||||
require.Equal(t, "plugin-callback-success", user1.Nickname)
|
require.Equal(t, "plugin-callback-success", user1.Nickname)
|
||||||
|
|
||||||
// Disable plugin
|
// Disable plugin
|
||||||
require.True(t, th.App.GetPluginsEnvironment().Deactivate(pluginId))
|
require.True(t, th.App.GetPluginsEnvironment().Deactivate(pluginID))
|
||||||
require.False(t, th.App.GetPluginsEnvironment().IsActive(pluginId))
|
require.False(t, th.App.GetPluginsEnvironment().IsActive(pluginID))
|
||||||
|
|
||||||
metricsMock.AssertExpectations(t)
|
metricsMock.AssertExpectations(t)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ type PluginCommand struct {
|
|||||||
PluginId string
|
PluginId string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) RegisterPluginCommand(pluginId string, command *model.Command) error {
|
func (a *App) RegisterPluginCommand(pluginID string, command *model.Command) error {
|
||||||
if command.Trigger == "" {
|
if command.Trigger == "" {
|
||||||
return errors.New("invalid command")
|
return errors.New("invalid command")
|
||||||
}
|
}
|
||||||
@@ -32,9 +32,9 @@ func (a *App) RegisterPluginCommand(pluginId string, command *model.Command) err
|
|||||||
if command.AutocompleteData == nil {
|
if command.AutocompleteData == nil {
|
||||||
command.AutocompleteData = model.NewAutocompleteData(command.Trigger, command.AutoCompleteHint, command.AutoCompleteDesc)
|
command.AutocompleteData = model.NewAutocompleteData(command.Trigger, command.AutoCompleteHint, command.AutoCompleteDesc)
|
||||||
} else {
|
} else {
|
||||||
baseURL, err := url.Parse("/plugins/" + pluginId)
|
baseURL, err := url.Parse("/plugins/" + pluginID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "Can't parse url %s", "/plugins/"+pluginId)
|
return errors.Wrapf(err, "Can't parse url %s", "/plugins/"+pluginID)
|
||||||
}
|
}
|
||||||
err = command.AutocompleteData.UpdateRelativeURLsForPluginCommands(baseURL)
|
err = command.AutocompleteData.UpdateRelativeURLsForPluginCommands(baseURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -58,7 +58,7 @@ func (a *App) RegisterPluginCommand(pluginId string, command *model.Command) err
|
|||||||
|
|
||||||
for _, pc := range a.Srv().pluginCommands {
|
for _, pc := range a.Srv().pluginCommands {
|
||||||
if pc.Command.Trigger == command.Trigger && pc.Command.TeamId == command.TeamId {
|
if pc.Command.Trigger == command.Trigger && pc.Command.TeamId == command.TeamId {
|
||||||
if pc.PluginId == pluginId {
|
if pc.PluginId == pluginID {
|
||||||
pc.Command = command
|
pc.Command = command
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -67,12 +67,12 @@ func (a *App) RegisterPluginCommand(pluginId string, command *model.Command) err
|
|||||||
|
|
||||||
a.Srv().pluginCommands = append(a.Srv().pluginCommands, &PluginCommand{
|
a.Srv().pluginCommands = append(a.Srv().pluginCommands, &PluginCommand{
|
||||||
Command: command,
|
Command: command,
|
||||||
PluginId: pluginId,
|
PluginId: pluginID,
|
||||||
})
|
})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) UnregisterPluginCommand(pluginId, teamID, trigger string) {
|
func (a *App) UnregisterPluginCommand(pluginID, teamID, trigger string) {
|
||||||
trigger = strings.ToLower(trigger)
|
trigger = strings.ToLower(trigger)
|
||||||
|
|
||||||
a.Srv().pluginCommandsLock.Lock()
|
a.Srv().pluginCommandsLock.Lock()
|
||||||
@@ -87,13 +87,13 @@ func (a *App) UnregisterPluginCommand(pluginId, teamID, trigger string) {
|
|||||||
a.Srv().pluginCommands = remaining
|
a.Srv().pluginCommands = remaining
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) UnregisterPluginCommands(pluginId string) {
|
func (a *App) UnregisterPluginCommands(pluginID string) {
|
||||||
a.Srv().pluginCommandsLock.Lock()
|
a.Srv().pluginCommandsLock.Lock()
|
||||||
defer a.Srv().pluginCommandsLock.Unlock()
|
defer a.Srv().pluginCommandsLock.Unlock()
|
||||||
|
|
||||||
var remaining []*PluginCommand
|
var remaining []*PluginCommand
|
||||||
for _, pc := range a.Srv().pluginCommands {
|
for _, pc := range a.Srv().pluginCommands {
|
||||||
if pc.PluginId != pluginId {
|
if pc.PluginId != pluginID {
|
||||||
remaining = append(remaining, pc)
|
remaining = append(remaining, pc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -152,8 +152,8 @@ func (a *App) tryExecutePluginCommand(args *model.CommandArgs) (*model.Command,
|
|||||||
args.AddUserMention(username, userID)
|
args.AddUserMention(username, userID)
|
||||||
}
|
}
|
||||||
|
|
||||||
for channelName, channelId := range a.MentionsToPublicChannels(args.Command, args.TeamId) {
|
for channelName, channelID := range a.MentionsToPublicChannels(args.Command, args.TeamId) {
|
||||||
args.AddChannelMention(channelName, channelId)
|
args.AddChannelMention(channelName, channelID)
|
||||||
}
|
}
|
||||||
|
|
||||||
response, appErr := pluginHooks.ExecuteCommand(a.PluginContext(), args)
|
response, appErr := pluginHooks.ExecuteCommand(a.PluginContext(), args)
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ func TestPluginCommand(t *testing.T) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
tearDown, pluginIds, activationErrors := SetAppEnvironmentWithPlugins(t, []string{`
|
tearDown, pluginIDs, activationErrors := SetAppEnvironmentWithPlugins(t, []string{`
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@@ -96,7 +96,7 @@ func TestPluginCommand(t *testing.T) {
|
|||||||
require.Equal(t, model.COMMAND_RESPONSE_TYPE_EPHEMERAL, resp.ResponseType)
|
require.Equal(t, model.COMMAND_RESPONSE_TYPE_EPHEMERAL, resp.ResponseType)
|
||||||
require.Equal(t, "text", resp.Text)
|
require.Equal(t, "text", resp.Text)
|
||||||
|
|
||||||
err2 := th.App.DisablePlugin(pluginIds[0])
|
err2 := th.App.DisablePlugin(pluginIDs[0])
|
||||||
require.Nil(t, err2)
|
require.Nil(t, err2)
|
||||||
|
|
||||||
commands, err3 := th.App.ListAutocompleteCommands(args.TeamId, utils.T)
|
commands, err3 := th.App.ListAutocompleteCommands(args.TeamId, utils.T)
|
||||||
@@ -106,7 +106,7 @@ func TestPluginCommand(t *testing.T) {
|
|||||||
require.NotEqual(t, "plugin", commands.Trigger)
|
require.NotEqual(t, "plugin", commands.Trigger)
|
||||||
}
|
}
|
||||||
|
|
||||||
th.App.RemovePlugin(pluginIds[0])
|
th.App.RemovePlugin(pluginIDs[0])
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("re-entrant command registration on config change", func(t *testing.T) {
|
t.Run("re-entrant command registration on config change", func(t *testing.T) {
|
||||||
@@ -116,7 +116,7 @@ func TestPluginCommand(t *testing.T) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
tearDown, pluginIds, activationErrors := SetAppEnvironmentWithPlugins(t, []string{`
|
tearDown, pluginIDs, activationErrors := SetAppEnvironmentWithPlugins(t, []string{`
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@@ -207,7 +207,7 @@ func TestPluginCommand(t *testing.T) {
|
|||||||
killed = true
|
killed = true
|
||||||
}
|
}
|
||||||
|
|
||||||
th.App.RemovePlugin(pluginIds[0])
|
th.App.RemovePlugin(pluginIDs[0])
|
||||||
require.False(t, killed, "execute command appears to have deadlocked")
|
require.False(t, killed, "execute command appears to have deadlocked")
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -223,7 +223,7 @@ func TestPluginCommand(t *testing.T) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
tearDown, pluginIds, activationErrors := SetAppEnvironmentWithPlugins(t, []string{`
|
tearDown, pluginIDs, activationErrors := SetAppEnvironmentWithPlugins(t, []string{`
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@@ -285,10 +285,10 @@ func TestPluginCommand(t *testing.T) {
|
|||||||
require.Equal(t, model.COMMAND_RESPONSE_TYPE_EPHEMERAL, resp.ResponseType)
|
require.Equal(t, model.COMMAND_RESPONSE_TYPE_EPHEMERAL, resp.ResponseType)
|
||||||
require.Equal(t, "text", resp.Text)
|
require.Equal(t, "text", resp.Text)
|
||||||
|
|
||||||
th.App.RemovePlugin(pluginIds[0])
|
th.App.RemovePlugin(pluginIDs[0])
|
||||||
})
|
})
|
||||||
t.Run("plugin has crashed before execution of command", func(t *testing.T) {
|
t.Run("plugin has crashed before execution of command", func(t *testing.T) {
|
||||||
tearDown, pluginIds, activationErrors := SetAppEnvironmentWithPlugins(t, []string{`
|
tearDown, pluginIDs, activationErrors := SetAppEnvironmentWithPlugins(t, []string{`
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@@ -329,11 +329,11 @@ func TestPluginCommand(t *testing.T) {
|
|||||||
require.Nil(t, resp)
|
require.Nil(t, resp)
|
||||||
require.NotNil(t, err)
|
require.NotNil(t, err)
|
||||||
require.Equal(t, err.Id, "model.plugin_command_error.error.app_error")
|
require.Equal(t, err.Id, "model.plugin_command_error.error.app_error")
|
||||||
th.App.RemovePlugin(pluginIds[0])
|
th.App.RemovePlugin(pluginIDs[0])
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("plugin has crashed due to the execution of the command", func(t *testing.T) {
|
t.Run("plugin has crashed due to the execution of the command", func(t *testing.T) {
|
||||||
tearDown, pluginIds, activationErrors := SetAppEnvironmentWithPlugins(t, []string{`
|
tearDown, pluginIDs, activationErrors := SetAppEnvironmentWithPlugins(t, []string{`
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@@ -374,7 +374,7 @@ func TestPluginCommand(t *testing.T) {
|
|||||||
require.Nil(t, resp)
|
require.Nil(t, resp)
|
||||||
require.NotNil(t, err)
|
require.NotNil(t, err)
|
||||||
require.Equal(t, err.Id, "model.plugin_command_crash.error.app_error")
|
require.Equal(t, err.Id, "model.plugin_command_crash.error.app_error")
|
||||||
th.App.RemovePlugin(pluginIds[0])
|
th.App.RemovePlugin(pluginIDs[0])
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,20 +36,20 @@ func SetAppEnvironmentWithPlugins(t *testing.T, pluginCode []string, app *App, a
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
app.SetPluginsEnvironment(env)
|
app.SetPluginsEnvironment(env)
|
||||||
pluginIds := []string{}
|
pluginIDs := []string{}
|
||||||
activationErrors := []error{}
|
activationErrors := []error{}
|
||||||
for _, code := range pluginCode {
|
for _, code := range pluginCode {
|
||||||
pluginId := model.NewId()
|
pluginID := model.NewId()
|
||||||
backend := filepath.Join(pluginDir, pluginId, "backend.exe")
|
backend := filepath.Join(pluginDir, pluginID, "backend.exe")
|
||||||
utils.CompileGo(t, code, backend)
|
utils.CompileGo(t, code, backend)
|
||||||
|
|
||||||
ioutil.WriteFile(filepath.Join(pluginDir, pluginId, "plugin.json"), []byte(`{"id": "`+pluginId+`", "backend": {"executable": "backend.exe"}}`), 0600)
|
ioutil.WriteFile(filepath.Join(pluginDir, pluginID, "plugin.json"), []byte(`{"id": "`+pluginID+`", "backend": {"executable": "backend.exe"}}`), 0600)
|
||||||
_, _, activationErr := env.Activate(pluginId)
|
_, _, activationErr := env.Activate(pluginID)
|
||||||
pluginIds = append(pluginIds, pluginId)
|
pluginIDs = append(pluginIDs, pluginID)
|
||||||
activationErrors = append(activationErrors, activationErr)
|
activationErrors = append(activationErrors, activationErr)
|
||||||
|
|
||||||
app.UpdateConfig(func(cfg *model.Config) {
|
app.UpdateConfig(func(cfg *model.Config) {
|
||||||
cfg.PluginSettings.PluginStates[pluginId] = &model.PluginState{
|
cfg.PluginSettings.PluginStates[pluginID] = &model.PluginState{
|
||||||
Enable: true,
|
Enable: true,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -58,7 +58,7 @@ func SetAppEnvironmentWithPlugins(t *testing.T, pluginCode []string, app *App, a
|
|||||||
return func() {
|
return func() {
|
||||||
os.RemoveAll(pluginDir)
|
os.RemoveAll(pluginDir)
|
||||||
os.RemoveAll(webappPluginDir)
|
os.RemoveAll(webappPluginDir)
|
||||||
}, pluginIds, activationErrors
|
}, pluginIDs, activationErrors
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHookMessageWillBePosted(t *testing.T) {
|
func TestHookMessageWillBePosted(t *testing.T) {
|
||||||
@@ -573,8 +573,8 @@ func TestHookFileWillBeUploaded(t *testing.T) {
|
|||||||
assert.NotNil(t, response)
|
assert.NotNil(t, response)
|
||||||
assert.Equal(t, 1, len(response.FileInfos))
|
assert.Equal(t, 1, len(response.FileInfos))
|
||||||
|
|
||||||
fileId := response.FileInfos[0].Id
|
fileID := response.FileInfos[0].Id
|
||||||
fileInfo, err := th.App.GetFileInfo(fileId)
|
fileInfo, err := th.App.GetFileInfo(fileID)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.NotNil(t, fileInfo)
|
assert.NotNil(t, fileInfo)
|
||||||
assert.Equal(t, "testhook.txt", fileInfo.Name)
|
assert.Equal(t, "testhook.txt", fileInfo.Name)
|
||||||
@@ -648,9 +648,9 @@ func TestHookFileWillBeUploaded(t *testing.T) {
|
|||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.NotNil(t, response)
|
assert.NotNil(t, response)
|
||||||
assert.Equal(t, 1, len(response.FileInfos))
|
assert.Equal(t, 1, len(response.FileInfos))
|
||||||
fileId := response.FileInfos[0].Id
|
fileID := response.FileInfos[0].Id
|
||||||
|
|
||||||
fileInfo, err := th.App.GetFileInfo(fileId)
|
fileInfo, err := th.App.GetFileInfo(fileID)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.NotNil(t, fileInfo)
|
assert.NotNil(t, fileInfo)
|
||||||
assert.Equal(t, "modifiedinfo", fileInfo.Name)
|
assert.Equal(t, "modifiedinfo", fileInfo.Name)
|
||||||
@@ -966,7 +966,7 @@ func TestActiveHooks(t *testing.T) {
|
|||||||
defer th.TearDown()
|
defer th.TearDown()
|
||||||
|
|
||||||
t.Run("", func(t *testing.T) {
|
t.Run("", func(t *testing.T) {
|
||||||
tearDown, pluginIds, _ := SetAppEnvironmentWithPlugins(t,
|
tearDown, pluginIDs, _ := SetAppEnvironmentWithPlugins(t,
|
||||||
[]string{
|
[]string{
|
||||||
`
|
`
|
||||||
package main
|
package main
|
||||||
@@ -999,10 +999,10 @@ func TestActiveHooks(t *testing.T) {
|
|||||||
`}, th.App, th.App.NewPluginAPI)
|
`}, th.App, th.App.NewPluginAPI)
|
||||||
defer tearDown()
|
defer tearDown()
|
||||||
|
|
||||||
require.Len(t, pluginIds, 1)
|
require.Len(t, pluginIDs, 1)
|
||||||
pluginId := pluginIds[0]
|
pluginID := pluginIDs[0]
|
||||||
|
|
||||||
require.True(t, th.App.GetPluginsEnvironment().IsActive(pluginId))
|
require.True(t, th.App.GetPluginsEnvironment().IsActive(pluginID))
|
||||||
user1 := &model.User{
|
user1 := &model.User{
|
||||||
Email: model.NewId() + "success+test@example.com",
|
Email: model.NewId() + "success+test@example.com",
|
||||||
Nickname: "Darth Vader1",
|
Nickname: "Darth Vader1",
|
||||||
@@ -1018,15 +1018,15 @@ func TestActiveHooks(t *testing.T) {
|
|||||||
require.Equal(t, "plugin-callback-success", user1.Nickname)
|
require.Equal(t, "plugin-callback-success", user1.Nickname)
|
||||||
|
|
||||||
// Disable plugin
|
// Disable plugin
|
||||||
require.True(t, th.App.GetPluginsEnvironment().Deactivate(pluginId))
|
require.True(t, th.App.GetPluginsEnvironment().Deactivate(pluginID))
|
||||||
require.False(t, th.App.GetPluginsEnvironment().IsActive(pluginId))
|
require.False(t, th.App.GetPluginsEnvironment().IsActive(pluginID))
|
||||||
|
|
||||||
hooks, err := th.App.GetPluginsEnvironment().HooksForPlugin(pluginId)
|
hooks, err := th.App.GetPluginsEnvironment().HooksForPlugin(pluginID)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
require.Nil(t, hooks)
|
require.Nil(t, hooks)
|
||||||
|
|
||||||
// Should fail to find pluginId as it was deleted when deactivated
|
// Should fail to find pluginID as it was deleted when deactivated
|
||||||
path, err := th.App.GetPluginsEnvironment().PublicFilesPath(pluginId)
|
path, err := th.App.GetPluginsEnvironment().PublicFilesPath(pluginID)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
require.Empty(t, path)
|
require.Empty(t, path)
|
||||||
})
|
})
|
||||||
@@ -1051,8 +1051,8 @@ func TestHookMetrics(t *testing.T) {
|
|||||||
|
|
||||||
th.App.SetPluginsEnvironment(env)
|
th.App.SetPluginsEnvironment(env)
|
||||||
|
|
||||||
pluginId := model.NewId()
|
pluginID := model.NewId()
|
||||||
backend := filepath.Join(pluginDir, pluginId, "backend.exe")
|
backend := filepath.Join(pluginDir, pluginID, "backend.exe")
|
||||||
code :=
|
code :=
|
||||||
`
|
`
|
||||||
package main
|
package main
|
||||||
@@ -1084,30 +1084,30 @@ func TestHookMetrics(t *testing.T) {
|
|||||||
}
|
}
|
||||||
`
|
`
|
||||||
utils.CompileGo(t, code, backend)
|
utils.CompileGo(t, code, backend)
|
||||||
ioutil.WriteFile(filepath.Join(pluginDir, pluginId, "plugin.json"), []byte(`{"id": "`+pluginId+`", "backend": {"executable": "backend.exe"}}`), 0600)
|
ioutil.WriteFile(filepath.Join(pluginDir, pluginID, "plugin.json"), []byte(`{"id": "`+pluginID+`", "backend": {"executable": "backend.exe"}}`), 0600)
|
||||||
|
|
||||||
// Setup mocks before activating
|
// Setup mocks before activating
|
||||||
metricsMock.On("ObservePluginHookDuration", pluginId, "Implemented", true, mock.Anything).Return()
|
metricsMock.On("ObservePluginHookDuration", pluginID, "Implemented", true, mock.Anything).Return()
|
||||||
metricsMock.On("ObservePluginHookDuration", pluginId, "OnActivate", true, mock.Anything).Return()
|
metricsMock.On("ObservePluginHookDuration", pluginID, "OnActivate", true, mock.Anything).Return()
|
||||||
metricsMock.On("ObservePluginHookDuration", pluginId, "OnDeactivate", true, mock.Anything).Return()
|
metricsMock.On("ObservePluginHookDuration", pluginID, "OnDeactivate", true, mock.Anything).Return()
|
||||||
metricsMock.On("ObservePluginHookDuration", pluginId, "OnConfigurationChange", true, mock.Anything).Return()
|
metricsMock.On("ObservePluginHookDuration", pluginID, "OnConfigurationChange", true, mock.Anything).Return()
|
||||||
metricsMock.On("ObservePluginHookDuration", pluginId, "UserHasBeenCreated", true, mock.Anything).Return()
|
metricsMock.On("ObservePluginHookDuration", pluginID, "UserHasBeenCreated", true, mock.Anything).Return()
|
||||||
|
|
||||||
// Don't care about these calls.
|
// Don't care about these calls.
|
||||||
metricsMock.On("ObservePluginApiDuration", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return()
|
metricsMock.On("ObservePluginApiDuration", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return()
|
||||||
metricsMock.On("ObservePluginMultiHookIterationDuration", mock.Anything, mock.Anything, mock.Anything).Return()
|
metricsMock.On("ObservePluginMultiHookIterationDuration", mock.Anything, mock.Anything, mock.Anything).Return()
|
||||||
metricsMock.On("ObservePluginMultiHookDuration", mock.Anything).Return()
|
metricsMock.On("ObservePluginMultiHookDuration", mock.Anything).Return()
|
||||||
|
|
||||||
_, _, activationErr := env.Activate(pluginId)
|
_, _, activationErr := env.Activate(pluginID)
|
||||||
require.NoError(t, activationErr)
|
require.NoError(t, activationErr)
|
||||||
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
cfg.PluginSettings.PluginStates[pluginId] = &model.PluginState{
|
cfg.PluginSettings.PluginStates[pluginID] = &model.PluginState{
|
||||||
Enable: true,
|
Enable: true,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
require.True(t, th.App.GetPluginsEnvironment().IsActive(pluginId))
|
require.True(t, th.App.GetPluginsEnvironment().IsActive(pluginID))
|
||||||
|
|
||||||
user1 := &model.User{
|
user1 := &model.User{
|
||||||
Email: model.NewId() + "success+test@example.com",
|
Email: model.NewId() + "success+test@example.com",
|
||||||
@@ -1124,8 +1124,8 @@ func TestHookMetrics(t *testing.T) {
|
|||||||
require.Equal(t, "plugin-callback-success", user1.Nickname)
|
require.Equal(t, "plugin-callback-success", user1.Nickname)
|
||||||
|
|
||||||
// Disable plugin
|
// Disable plugin
|
||||||
require.True(t, th.App.GetPluginsEnvironment().Deactivate(pluginId))
|
require.True(t, th.App.GetPluginsEnvironment().Deactivate(pluginID))
|
||||||
require.False(t, th.App.GetPluginsEnvironment().IsActive(pluginId))
|
require.False(t, th.App.GetPluginsEnvironment().IsActive(pluginID))
|
||||||
|
|
||||||
metricsMock.AssertExpectations(t)
|
metricsMock.AssertExpectations(t)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -466,14 +466,14 @@ func (a *App) removePluginLocally(id string) *model.AppError {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) removeSignature(pluginId string) *model.AppError {
|
func (a *App) removeSignature(pluginID string) *model.AppError {
|
||||||
filePath := a.getSignatureStorePath(pluginId)
|
filePath := a.getSignatureStorePath(pluginID)
|
||||||
exists, err := a.FileExists(filePath)
|
exists, err := a.FileExists(filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return model.NewAppError("removeSignature", "app.plugin.remove_bundle.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return model.NewAppError("removeSignature", "app.plugin.remove_bundle.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
if !exists {
|
if !exists {
|
||||||
mlog.Debug("no plugin signature to remove", mlog.String("plugin_id", pluginId))
|
mlog.Debug("no plugin signature to remove", mlog.String("plugin_id", pluginID))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if err = a.RemoveFile(filePath); err != nil {
|
if err = a.RemoveFile(filePath); err != nil {
|
||||||
|
|||||||
@@ -20,35 +20,35 @@ func getKeyHash(key string) string {
|
|||||||
return base64.StdEncoding.EncodeToString(hash.Sum(nil))
|
return base64.StdEncoding.EncodeToString(hash.Sum(nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) SetPluginKey(pluginId string, key string, value []byte) *model.AppError {
|
func (a *App) SetPluginKey(pluginID string, key string, value []byte) *model.AppError {
|
||||||
return a.SetPluginKeyWithExpiry(pluginId, key, value, 0)
|
return a.SetPluginKeyWithExpiry(pluginID, key, value, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) SetPluginKeyWithExpiry(pluginId string, key string, value []byte, expireInSeconds int64) *model.AppError {
|
func (a *App) SetPluginKeyWithExpiry(pluginID string, key string, value []byte, expireInSeconds int64) *model.AppError {
|
||||||
options := model.PluginKVSetOptions{
|
options := model.PluginKVSetOptions{
|
||||||
ExpireInSeconds: expireInSeconds,
|
ExpireInSeconds: expireInSeconds,
|
||||||
}
|
}
|
||||||
_, err := a.SetPluginKeyWithOptions(pluginId, key, value, options)
|
_, err := a.SetPluginKeyWithOptions(pluginID, key, value, options)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) CompareAndSetPluginKey(pluginId string, key string, oldValue, newValue []byte) (bool, *model.AppError) {
|
func (a *App) CompareAndSetPluginKey(pluginID string, key string, oldValue, newValue []byte) (bool, *model.AppError) {
|
||||||
options := model.PluginKVSetOptions{
|
options := model.PluginKVSetOptions{
|
||||||
Atomic: true,
|
Atomic: true,
|
||||||
OldValue: oldValue,
|
OldValue: oldValue,
|
||||||
}
|
}
|
||||||
return a.SetPluginKeyWithOptions(pluginId, key, newValue, options)
|
return a.SetPluginKeyWithOptions(pluginID, key, newValue, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) SetPluginKeyWithOptions(pluginId string, key string, value []byte, options model.PluginKVSetOptions) (bool, *model.AppError) {
|
func (a *App) SetPluginKeyWithOptions(pluginID string, key string, value []byte, options model.PluginKVSetOptions) (bool, *model.AppError) {
|
||||||
if err := options.IsValid(); err != nil {
|
if err := options.IsValid(); err != nil {
|
||||||
mlog.Debug("Failed to set plugin key value with options", mlog.String("plugin_id", pluginId), mlog.String("key", key), mlog.Err(err))
|
mlog.Debug("Failed to set plugin key value with options", mlog.String("plugin_id", pluginID), mlog.String("key", key), mlog.Err(err))
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
updated, err := a.Srv().Store.Plugin().SetWithOptions(pluginId, key, value, options)
|
updated, err := a.Srv().Store.Plugin().SetWithOptions(pluginID, key, value, options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
mlog.Error("Failed to set plugin key value with options", mlog.String("plugin_id", pluginId), mlog.String("key", key), mlog.Err(err))
|
mlog.Error("Failed to set plugin key value with options", mlog.String("plugin_id", pluginID), mlog.String("key", key), mlog.Err(err))
|
||||||
var appErr *model.AppError
|
var appErr *model.AppError
|
||||||
switch {
|
switch {
|
||||||
case errors.As(err, &appErr):
|
case errors.As(err, &appErr):
|
||||||
@@ -59,22 +59,22 @@ func (a *App) SetPluginKeyWithOptions(pluginId string, key string, value []byte,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Clean up a previous entry using the hashed key, if it exists.
|
// Clean up a previous entry using the hashed key, if it exists.
|
||||||
if err := a.Srv().Store.Plugin().Delete(pluginId, getKeyHash(key)); err != nil {
|
if err := a.Srv().Store.Plugin().Delete(pluginID, getKeyHash(key)); err != nil {
|
||||||
mlog.Warn("Failed to clean up previously hashed plugin key value", mlog.String("plugin_id", pluginId), mlog.String("key", key), mlog.Err(err))
|
mlog.Warn("Failed to clean up previously hashed plugin key value", mlog.String("plugin_id", pluginID), mlog.String("key", key), mlog.Err(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
return updated, nil
|
return updated, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) CompareAndDeletePluginKey(pluginId string, key string, oldValue []byte) (bool, *model.AppError) {
|
func (a *App) CompareAndDeletePluginKey(pluginID string, key string, oldValue []byte) (bool, *model.AppError) {
|
||||||
kv := &model.PluginKeyValue{
|
kv := &model.PluginKeyValue{
|
||||||
PluginId: pluginId,
|
PluginId: pluginID,
|
||||||
Key: key,
|
Key: key,
|
||||||
}
|
}
|
||||||
|
|
||||||
deleted, err := a.Srv().Store.Plugin().CompareAndDelete(kv, oldValue)
|
deleted, err := a.Srv().Store.Plugin().CompareAndDelete(kv, oldValue)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
mlog.Error("Failed to compare and delete plugin key value", mlog.String("plugin_id", pluginId), mlog.String("key", key), mlog.Err(err))
|
mlog.Error("Failed to compare and delete plugin key value", mlog.String("plugin_id", pluginID), mlog.String("key", key), mlog.Err(err))
|
||||||
var appErr *model.AppError
|
var appErr *model.AppError
|
||||||
switch {
|
switch {
|
||||||
case errors.As(err, &appErr):
|
case errors.As(err, &appErr):
|
||||||
@@ -85,50 +85,50 @@ func (a *App) CompareAndDeletePluginKey(pluginId string, key string, oldValue []
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Clean up a previous entry using the hashed key, if it exists.
|
// Clean up a previous entry using the hashed key, if it exists.
|
||||||
if err := a.Srv().Store.Plugin().Delete(pluginId, getKeyHash(key)); err != nil {
|
if err := a.Srv().Store.Plugin().Delete(pluginID, getKeyHash(key)); err != nil {
|
||||||
mlog.Warn("Failed to clean up previously hashed plugin key value", mlog.String("plugin_id", pluginId), mlog.String("key", key), mlog.Err(err))
|
mlog.Warn("Failed to clean up previously hashed plugin key value", mlog.String("plugin_id", pluginID), mlog.String("key", key), mlog.Err(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
return deleted, nil
|
return deleted, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetPluginKey(pluginId string, key string) ([]byte, *model.AppError) {
|
func (a *App) GetPluginKey(pluginID string, key string) ([]byte, *model.AppError) {
|
||||||
if kv, err := a.Srv().Store.Plugin().Get(pluginId, key); err == nil {
|
if kv, err := a.Srv().Store.Plugin().Get(pluginID, key); err == nil {
|
||||||
return kv.Value, nil
|
return kv.Value, nil
|
||||||
} else if nfErr := new(store.ErrNotFound); !errors.As(err, &nfErr) {
|
} else if nfErr := new(store.ErrNotFound); !errors.As(err, &nfErr) {
|
||||||
mlog.Error("Failed to query plugin key value", mlog.String("plugin_id", pluginId), mlog.String("key", key), mlog.Err(err))
|
mlog.Error("Failed to query plugin key value", mlog.String("plugin_id", pluginID), mlog.String("key", key), mlog.Err(err))
|
||||||
return nil, model.NewAppError("GetPluginKey", "app.plugin_store.get.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return nil, model.NewAppError("GetPluginKey", "app.plugin_store.get.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lookup using the hashed version of the key for keys written prior to v5.6.
|
// Lookup using the hashed version of the key for keys written prior to v5.6.
|
||||||
if kv, err := a.Srv().Store.Plugin().Get(pluginId, getKeyHash(key)); err == nil {
|
if kv, err := a.Srv().Store.Plugin().Get(pluginID, getKeyHash(key)); err == nil {
|
||||||
return kv.Value, nil
|
return kv.Value, nil
|
||||||
} else if nfErr := new(store.ErrNotFound); !errors.As(err, &nfErr) {
|
} else if nfErr := new(store.ErrNotFound); !errors.As(err, &nfErr) {
|
||||||
mlog.Error("Failed to query plugin key value using hashed key", mlog.String("plugin_id", pluginId), mlog.String("key", key), mlog.Err(err))
|
mlog.Error("Failed to query plugin key value using hashed key", mlog.String("plugin_id", pluginID), mlog.String("key", key), mlog.Err(err))
|
||||||
return nil, model.NewAppError("GetPluginKey", "app.plugin_store.get.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return nil, model.NewAppError("GetPluginKey", "app.plugin_store.get.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) DeletePluginKey(pluginId string, key string) *model.AppError {
|
func (a *App) DeletePluginKey(pluginID string, key string) *model.AppError {
|
||||||
if err := a.Srv().Store.Plugin().Delete(pluginId, getKeyHash(key)); err != nil {
|
if err := a.Srv().Store.Plugin().Delete(pluginID, getKeyHash(key)); err != nil {
|
||||||
mlog.Error("Failed to delete plugin key value", mlog.String("plugin_id", pluginId), mlog.String("key", key), mlog.Err(err))
|
mlog.Error("Failed to delete plugin key value", mlog.String("plugin_id", pluginID), mlog.String("key", key), mlog.Err(err))
|
||||||
return model.NewAppError("DeletePluginKey", "app.plugin_store.delete.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return model.NewAppError("DeletePluginKey", "app.plugin_store.delete.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Also delete the key without hashing
|
// Also delete the key without hashing
|
||||||
if err := a.Srv().Store.Plugin().Delete(pluginId, key); err != nil {
|
if err := a.Srv().Store.Plugin().Delete(pluginID, key); err != nil {
|
||||||
mlog.Error("Failed to delete plugin key value using hashed key", mlog.String("plugin_id", pluginId), mlog.String("key", key), mlog.Err(err))
|
mlog.Error("Failed to delete plugin key value using hashed key", mlog.String("plugin_id", pluginID), mlog.String("key", key), mlog.Err(err))
|
||||||
return model.NewAppError("DeletePluginKey", "app.plugin_store.delete.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return model.NewAppError("DeletePluginKey", "app.plugin_store.delete.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) DeleteAllKeysForPlugin(pluginId string) *model.AppError {
|
func (a *App) DeleteAllKeysForPlugin(pluginID string) *model.AppError {
|
||||||
if err := a.Srv().Store.Plugin().DeleteAllForPlugin(pluginId); err != nil {
|
if err := a.Srv().Store.Plugin().DeleteAllForPlugin(pluginID); err != nil {
|
||||||
mlog.Error("Failed to delete all plugin key values", mlog.String("plugin_id", pluginId), mlog.Err(err))
|
mlog.Error("Failed to delete all plugin key values", mlog.String("plugin_id", pluginID), mlog.Err(err))
|
||||||
return model.NewAppError("DeleteAllKeysForPlugin", "app.plugin_store.delete.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return model.NewAppError("DeleteAllKeysForPlugin", "app.plugin_store.delete.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,8 +148,8 @@ func (a *App) DeleteAllExpiredPluginKeys() *model.AppError {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) ListPluginKeys(pluginId string, page, perPage int) ([]string, *model.AppError) {
|
func (a *App) ListPluginKeys(pluginID string, page, perPage int) ([]string, *model.AppError) {
|
||||||
data, err := a.Srv().Store.Plugin().List(pluginId, page*perPage, perPage)
|
data, err := a.Srv().Store.Plugin().List(pluginID, page*perPage, perPage)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
mlog.Error("Failed to list plugin key values", mlog.Int("page", page), mlog.Int("perPage", perPage), mlog.Err(err))
|
mlog.Error("Failed to list plugin key values", mlog.Int("page", page), mlog.Int("perPage", perPage), mlog.Err(err))
|
||||||
|
|||||||
@@ -37,38 +37,38 @@ func TestPluginKeyValueStore(t *testing.T) {
|
|||||||
th := Setup(t)
|
th := Setup(t)
|
||||||
defer th.TearDown()
|
defer th.TearDown()
|
||||||
|
|
||||||
pluginId := "testpluginid"
|
pluginID := "testpluginid"
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
assert.Nil(t, th.App.DeletePluginKey(pluginId, "key"))
|
assert.Nil(t, th.App.DeletePluginKey(pluginID, "key"))
|
||||||
assert.Nil(t, th.App.DeletePluginKey(pluginId, "key2"))
|
assert.Nil(t, th.App.DeletePluginKey(pluginID, "key2"))
|
||||||
assert.Nil(t, th.App.DeletePluginKey(pluginId, "key3"))
|
assert.Nil(t, th.App.DeletePluginKey(pluginID, "key3"))
|
||||||
assert.Nil(t, th.App.DeletePluginKey(pluginId, "key4"))
|
assert.Nil(t, th.App.DeletePluginKey(pluginID, "key4"))
|
||||||
}()
|
}()
|
||||||
|
|
||||||
assert.Nil(t, th.App.SetPluginKey(pluginId, "key", []byte("test")))
|
assert.Nil(t, th.App.SetPluginKey(pluginID, "key", []byte("test")))
|
||||||
ret, err := th.App.GetPluginKey(pluginId, "key")
|
ret, err := th.App.GetPluginKey(pluginID, "key")
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, []byte("test"), ret)
|
assert.Equal(t, []byte("test"), ret)
|
||||||
|
|
||||||
// Test inserting over existing entries
|
// Test inserting over existing entries
|
||||||
assert.Nil(t, th.App.SetPluginKey(pluginId, "key", []byte("test2")))
|
assert.Nil(t, th.App.SetPluginKey(pluginID, "key", []byte("test2")))
|
||||||
ret, err = th.App.GetPluginKey(pluginId, "key")
|
ret, err = th.App.GetPluginKey(pluginID, "key")
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, []byte("test2"), ret)
|
assert.Equal(t, []byte("test2"), ret)
|
||||||
|
|
||||||
// Test getting non-existent key
|
// Test getting non-existent key
|
||||||
ret, err = th.App.GetPluginKey(pluginId, "notakey")
|
ret, err = th.App.GetPluginKey(pluginID, "notakey")
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Nil(t, ret)
|
assert.Nil(t, ret)
|
||||||
|
|
||||||
// Test deleting non-existent keys.
|
// Test deleting non-existent keys.
|
||||||
assert.Nil(t, th.App.DeletePluginKey(pluginId, "notrealkey"))
|
assert.Nil(t, th.App.DeletePluginKey(pluginID, "notrealkey"))
|
||||||
|
|
||||||
// Verify behaviour for the old approach that involved storing the hashed keys.
|
// Verify behaviour for the old approach that involved storing the hashed keys.
|
||||||
hashedKey2 := getHashedKey("key2")
|
hashedKey2 := getHashedKey("key2")
|
||||||
kv := &model.PluginKeyValue{
|
kv := &model.PluginKeyValue{
|
||||||
PluginId: pluginId,
|
PluginId: pluginID,
|
||||||
Key: hashedKey2,
|
Key: hashedKey2,
|
||||||
Value: []byte("test"),
|
Value: []byte("test"),
|
||||||
ExpireAt: 0,
|
ExpireAt: 0,
|
||||||
@@ -78,57 +78,57 @@ func TestPluginKeyValueStore(t *testing.T) {
|
|||||||
assert.NoError(t, nErr)
|
assert.NoError(t, nErr)
|
||||||
|
|
||||||
// Test fetch by keyname (this key does not exist but hashed key will be used for lookup)
|
// Test fetch by keyname (this key does not exist but hashed key will be used for lookup)
|
||||||
ret, err = th.App.GetPluginKey(pluginId, "key2")
|
ret, err = th.App.GetPluginKey(pluginID, "key2")
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, kv.Value, ret)
|
assert.Equal(t, kv.Value, ret)
|
||||||
|
|
||||||
// Test fetch by hashed keyname
|
// Test fetch by hashed keyname
|
||||||
ret, err = th.App.GetPluginKey(pluginId, hashedKey2)
|
ret, err = th.App.GetPluginKey(pluginID, hashedKey2)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, kv.Value, ret)
|
assert.Equal(t, kv.Value, ret)
|
||||||
|
|
||||||
// Test ListKeys
|
// Test ListKeys
|
||||||
assert.Nil(t, th.App.SetPluginKey(pluginId, "key3", []byte("test3")))
|
assert.Nil(t, th.App.SetPluginKey(pluginID, "key3", []byte("test3")))
|
||||||
assert.Nil(t, th.App.SetPluginKey(pluginId, "key4", []byte("test4")))
|
assert.Nil(t, th.App.SetPluginKey(pluginID, "key4", []byte("test4")))
|
||||||
|
|
||||||
list, err := th.App.ListPluginKeys(pluginId, 0, 1)
|
list, err := th.App.ListPluginKeys(pluginID, 0, 1)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, []string{"key"}, list)
|
assert.Equal(t, []string{"key"}, list)
|
||||||
|
|
||||||
list, err = th.App.ListPluginKeys(pluginId, 1, 1)
|
list, err = th.App.ListPluginKeys(pluginID, 1, 1)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, []string{"key3"}, list)
|
assert.Equal(t, []string{"key3"}, list)
|
||||||
|
|
||||||
list, err = th.App.ListPluginKeys(pluginId, 0, 4)
|
list, err = th.App.ListPluginKeys(pluginID, 0, 4)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, []string{"key", "key3", "key4", hashedKey2}, list)
|
assert.Equal(t, []string{"key", "key3", "key4", hashedKey2}, list)
|
||||||
|
|
||||||
list, err = th.App.ListPluginKeys(pluginId, 0, 2)
|
list, err = th.App.ListPluginKeys(pluginID, 0, 2)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, []string{"key", "key3"}, list)
|
assert.Equal(t, []string{"key", "key3"}, list)
|
||||||
|
|
||||||
list, err = th.App.ListPluginKeys(pluginId, 1, 2)
|
list, err = th.App.ListPluginKeys(pluginID, 1, 2)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, []string{"key4", hashedKey2}, list)
|
assert.Equal(t, []string{"key4", hashedKey2}, list)
|
||||||
|
|
||||||
list, err = th.App.ListPluginKeys(pluginId, 2, 2)
|
list, err = th.App.ListPluginKeys(pluginID, 2, 2)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, []string{}, list)
|
assert.Equal(t, []string{}, list)
|
||||||
|
|
||||||
// List Keys bad input
|
// List Keys bad input
|
||||||
list, err = th.App.ListPluginKeys(pluginId, 0, 0)
|
list, err = th.App.ListPluginKeys(pluginID, 0, 0)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, []string{"key", "key3", "key4", hashedKey2}, list)
|
assert.Equal(t, []string{"key", "key3", "key4", hashedKey2}, list)
|
||||||
|
|
||||||
list, err = th.App.ListPluginKeys(pluginId, 0, -1)
|
list, err = th.App.ListPluginKeys(pluginID, 0, -1)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, []string{"key", "key3", "key4", hashedKey2}, list)
|
assert.Equal(t, []string{"key", "key3", "key4", hashedKey2}, list)
|
||||||
|
|
||||||
list, err = th.App.ListPluginKeys(pluginId, -1, 1)
|
list, err = th.App.ListPluginKeys(pluginID, -1, 1)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, []string{"key"}, list)
|
assert.Equal(t, []string{"key"}, list)
|
||||||
|
|
||||||
list, err = th.App.ListPluginKeys(pluginId, -1, 0)
|
list, err = th.App.ListPluginKeys(pluginID, -1, 0)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, []string{"key", "key3", "key4", hashedKey2}, list)
|
assert.Equal(t, []string{"key", "key3", "key4", hashedKey2}, list)
|
||||||
}
|
}
|
||||||
@@ -137,72 +137,72 @@ func TestPluginKeyValueStoreCompareAndSet(t *testing.T) {
|
|||||||
th := Setup(t)
|
th := Setup(t)
|
||||||
defer th.TearDown()
|
defer th.TearDown()
|
||||||
|
|
||||||
pluginId := "testpluginid"
|
pluginID := "testpluginid"
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
assert.Nil(t, th.App.DeletePluginKey(pluginId, "key"))
|
assert.Nil(t, th.App.DeletePluginKey(pluginID, "key"))
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// Set using Set api for key2
|
// Set using Set api for key2
|
||||||
assert.Nil(t, th.App.SetPluginKey(pluginId, "key2", []byte("test")))
|
assert.Nil(t, th.App.SetPluginKey(pluginID, "key2", []byte("test")))
|
||||||
ret, err := th.App.GetPluginKey(pluginId, "key2")
|
ret, err := th.App.GetPluginKey(pluginID, "key2")
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, []byte("test"), ret)
|
assert.Equal(t, []byte("test"), ret)
|
||||||
|
|
||||||
// Attempt to insert value for key2
|
// Attempt to insert value for key2
|
||||||
updated, err := th.App.CompareAndSetPluginKey(pluginId, "key2", nil, []byte("test2"))
|
updated, err := th.App.CompareAndSetPluginKey(pluginID, "key2", nil, []byte("test2"))
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.False(t, updated)
|
assert.False(t, updated)
|
||||||
ret, err = th.App.GetPluginKey(pluginId, "key2")
|
ret, err = th.App.GetPluginKey(pluginID, "key2")
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, []byte("test"), ret)
|
assert.Equal(t, []byte("test"), ret)
|
||||||
|
|
||||||
// Insert new value for key
|
// Insert new value for key
|
||||||
updated, err = th.App.CompareAndSetPluginKey(pluginId, "key", nil, []byte("test"))
|
updated, err = th.App.CompareAndSetPluginKey(pluginID, "key", nil, []byte("test"))
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.True(t, updated)
|
assert.True(t, updated)
|
||||||
ret, err = th.App.GetPluginKey(pluginId, "key")
|
ret, err = th.App.GetPluginKey(pluginID, "key")
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, []byte("test"), ret)
|
assert.Equal(t, []byte("test"), ret)
|
||||||
|
|
||||||
// Should fail to insert again
|
// Should fail to insert again
|
||||||
updated, err = th.App.CompareAndSetPluginKey(pluginId, "key", nil, []byte("test3"))
|
updated, err = th.App.CompareAndSetPluginKey(pluginID, "key", nil, []byte("test3"))
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.False(t, updated)
|
assert.False(t, updated)
|
||||||
ret, err = th.App.GetPluginKey(pluginId, "key")
|
ret, err = th.App.GetPluginKey(pluginID, "key")
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, []byte("test"), ret)
|
assert.Equal(t, []byte("test"), ret)
|
||||||
|
|
||||||
// Test updating using incorrect old value
|
// Test updating using incorrect old value
|
||||||
updated, err = th.App.CompareAndSetPluginKey(pluginId, "key", []byte("oldvalue"), []byte("test3"))
|
updated, err = th.App.CompareAndSetPluginKey(pluginID, "key", []byte("oldvalue"), []byte("test3"))
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.False(t, updated)
|
assert.False(t, updated)
|
||||||
ret, err = th.App.GetPluginKey(pluginId, "key")
|
ret, err = th.App.GetPluginKey(pluginID, "key")
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, []byte("test"), ret)
|
assert.Equal(t, []byte("test"), ret)
|
||||||
|
|
||||||
// Test updating using correct old value
|
// Test updating using correct old value
|
||||||
updated, err = th.App.CompareAndSetPluginKey(pluginId, "key", []byte("test"), []byte("test2"))
|
updated, err = th.App.CompareAndSetPluginKey(pluginID, "key", []byte("test"), []byte("test2"))
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.True(t, updated)
|
assert.True(t, updated)
|
||||||
ret, err = th.App.GetPluginKey(pluginId, "key")
|
ret, err = th.App.GetPluginKey(pluginID, "key")
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, []byte("test2"), ret)
|
assert.Equal(t, []byte("test2"), ret)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPluginKeyValueStoreSetWithOptionsJSON(t *testing.T) {
|
func TestPluginKeyValueStoreSetWithOptionsJSON(t *testing.T) {
|
||||||
pluginId := "testpluginid"
|
pluginID := "testpluginid"
|
||||||
|
|
||||||
t.Run("storing a value without providing options works", func(t *testing.T) {
|
t.Run("storing a value without providing options works", func(t *testing.T) {
|
||||||
th := Setup(t)
|
th := Setup(t)
|
||||||
defer th.TearDown()
|
defer th.TearDown()
|
||||||
|
|
||||||
result, err := th.App.SetPluginKeyWithOptions(pluginId, "key", []byte("value-1"), model.PluginKVSetOptions{})
|
result, err := th.App.SetPluginKeyWithOptions(pluginID, "key", []byte("value-1"), model.PluginKVSetOptions{})
|
||||||
assert.True(t, result)
|
assert.True(t, result)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
|
|
||||||
// and I can get it back!
|
// and I can get it back!
|
||||||
ret, err := th.App.GetPluginKey(pluginId, "key")
|
ret, err := th.App.GetPluginKey(pluginID, "key")
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, []byte(`value-1`), ret)
|
assert.Equal(t, []byte(`value-1`), ret)
|
||||||
})
|
})
|
||||||
@@ -211,10 +211,10 @@ func TestPluginKeyValueStoreSetWithOptionsJSON(t *testing.T) {
|
|||||||
th := Setup(t)
|
th := Setup(t)
|
||||||
defer th.TearDown()
|
defer th.TearDown()
|
||||||
|
|
||||||
err := th.App.SetPluginKey(pluginId, "key", []byte("value-1"))
|
err := th.App.SetPluginKey(pluginID, "key", []byte("value-1"))
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
result, err := th.App.SetPluginKeyWithOptions(pluginId, "key", []byte("value-3"), model.PluginKVSetOptions{
|
result, err := th.App.SetPluginKeyWithOptions(pluginID, "key", []byte("value-3"), model.PluginKVSetOptions{
|
||||||
Atomic: true,
|
Atomic: true,
|
||||||
OldValue: []byte("value-2"),
|
OldValue: []byte("value-2"),
|
||||||
})
|
})
|
||||||
@@ -222,7 +222,7 @@ func TestPluginKeyValueStoreSetWithOptionsJSON(t *testing.T) {
|
|||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
|
|
||||||
// test that the value didn't change
|
// test that the value didn't change
|
||||||
ret, err := th.App.GetPluginKey(pluginId, "key")
|
ret, err := th.App.GetPluginKey(pluginID, "key")
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, []byte(`value-1`), ret)
|
assert.Equal(t, []byte(`value-1`), ret)
|
||||||
})
|
})
|
||||||
@@ -231,10 +231,10 @@ func TestPluginKeyValueStoreSetWithOptionsJSON(t *testing.T) {
|
|||||||
th := Setup(t)
|
th := Setup(t)
|
||||||
defer th.TearDown()
|
defer th.TearDown()
|
||||||
|
|
||||||
err := th.App.SetPluginKey(pluginId, "key", []byte("value-2"))
|
err := th.App.SetPluginKey(pluginID, "key", []byte("value-2"))
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
result, err := th.App.SetPluginKeyWithOptions(pluginId, "key", []byte("value-3"), model.PluginKVSetOptions{
|
result, err := th.App.SetPluginKeyWithOptions(pluginID, "key", []byte("value-3"), model.PluginKVSetOptions{
|
||||||
Atomic: true,
|
Atomic: true,
|
||||||
OldValue: []byte("value-2"),
|
OldValue: []byte("value-2"),
|
||||||
})
|
})
|
||||||
@@ -242,7 +242,7 @@ func TestPluginKeyValueStoreSetWithOptionsJSON(t *testing.T) {
|
|||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
|
|
||||||
// test that the value did change
|
// test that the value did change
|
||||||
ret, err := th.App.GetPluginKey(pluginId, "key")
|
ret, err := th.App.GetPluginKey(pluginID, "key")
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, []byte(`value-3`), ret)
|
assert.Equal(t, []byte(`value-3`), ret)
|
||||||
})
|
})
|
||||||
@@ -252,19 +252,19 @@ func TestPluginKeyValueStoreSetWithOptionsJSON(t *testing.T) {
|
|||||||
defer th.TearDown()
|
defer th.TearDown()
|
||||||
|
|
||||||
// first set a value.
|
// first set a value.
|
||||||
result, err := th.App.SetPluginKeyWithOptions(pluginId, "nil-test-key-2", []byte("value-1"), model.PluginKVSetOptions{})
|
result, err := th.App.SetPluginKeyWithOptions(pluginID, "nil-test-key-2", []byte("value-1"), model.PluginKVSetOptions{})
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
require.True(t, result)
|
require.True(t, result)
|
||||||
|
|
||||||
// now it should delete the set value.
|
// now it should delete the set value.
|
||||||
result, err = th.App.SetPluginKeyWithOptions(pluginId, "nil-test-key-2", nil, model.PluginKVSetOptions{
|
result, err = th.App.SetPluginKeyWithOptions(pluginID, "nil-test-key-2", nil, model.PluginKVSetOptions{
|
||||||
Atomic: true,
|
Atomic: true,
|
||||||
OldValue: []byte("value-1"),
|
OldValue: []byte("value-1"),
|
||||||
})
|
})
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.True(t, result)
|
assert.True(t, result)
|
||||||
|
|
||||||
ret, err := th.App.GetPluginKey(pluginId, "nil-test-key-2")
|
ret, err := th.App.GetPluginKey(pluginID, "nil-test-key-2")
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Nil(t, ret)
|
assert.Nil(t, ret)
|
||||||
})
|
})
|
||||||
@@ -274,22 +274,22 @@ func TestPluginKeyValueStoreSetWithOptionsJSON(t *testing.T) {
|
|||||||
defer th.TearDown()
|
defer th.TearDown()
|
||||||
|
|
||||||
// first set a value.
|
// first set a value.
|
||||||
result, err := th.App.SetPluginKeyWithOptions(pluginId, "nil-test-key-3", []byte("value-1"), model.PluginKVSetOptions{})
|
result, err := th.App.SetPluginKeyWithOptions(pluginID, "nil-test-key-3", []byte("value-1"), model.PluginKVSetOptions{})
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
require.True(t, result)
|
require.True(t, result)
|
||||||
|
|
||||||
// now it should delete the set value.
|
// now it should delete the set value.
|
||||||
result, err = th.App.SetPluginKeyWithOptions(pluginId, "nil-test-key-3", nil, model.PluginKVSetOptions{})
|
result, err = th.App.SetPluginKeyWithOptions(pluginID, "nil-test-key-3", nil, model.PluginKVSetOptions{})
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.True(t, result)
|
assert.True(t, result)
|
||||||
|
|
||||||
// verify a nil value is returned
|
// verify a nil value is returned
|
||||||
ret, err := th.App.GetPluginKey(pluginId, "nil-test-key-3")
|
ret, err := th.App.GetPluginKey(pluginID, "nil-test-key-3")
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Nil(t, ret)
|
assert.Nil(t, ret)
|
||||||
|
|
||||||
// verify the row is actually gone
|
// verify the row is actually gone
|
||||||
list, err := th.App.ListPluginKeys(pluginId, 0, 1)
|
list, err := th.App.ListPluginKeys(pluginID, 0, 1)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Empty(t, list)
|
assert.Empty(t, list)
|
||||||
})
|
})
|
||||||
@@ -298,14 +298,14 @@ func TestPluginKeyValueStoreSetWithOptionsJSON(t *testing.T) {
|
|||||||
th := Setup(t)
|
th := Setup(t)
|
||||||
defer th.TearDown()
|
defer th.TearDown()
|
||||||
|
|
||||||
result, err := th.App.SetPluginKeyWithOptions(pluginId, "nil-test-key-4", []byte("value-1"), model.PluginKVSetOptions{
|
result, err := th.App.SetPluginKeyWithOptions(pluginID, "nil-test-key-4", []byte("value-1"), model.PluginKVSetOptions{
|
||||||
Atomic: true,
|
Atomic: true,
|
||||||
OldValue: nil,
|
OldValue: nil,
|
||||||
})
|
})
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.True(t, result)
|
assert.True(t, result)
|
||||||
|
|
||||||
ret, err := th.App.GetPluginKey(pluginId, "nil-test-key-4")
|
ret, err := th.App.GetPluginKey(pluginID, "nil-test-key-4")
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, []byte("value-1"), ret)
|
assert.Equal(t, []byte("value-1"), ret)
|
||||||
})
|
})
|
||||||
@@ -314,21 +314,21 @@ func TestPluginKeyValueStoreSetWithOptionsJSON(t *testing.T) {
|
|||||||
th := Setup(t)
|
th := Setup(t)
|
||||||
defer th.TearDown()
|
defer th.TearDown()
|
||||||
|
|
||||||
result, err := th.App.SetPluginKeyWithOptions(pluginId, "key", []byte("value-1"), model.PluginKVSetOptions{
|
result, err := th.App.SetPluginKeyWithOptions(pluginID, "key", []byte("value-1"), model.PluginKVSetOptions{
|
||||||
ExpireInSeconds: 1,
|
ExpireInSeconds: 1,
|
||||||
})
|
})
|
||||||
assert.True(t, result)
|
assert.True(t, result)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
|
|
||||||
// test that the value is set
|
// test that the value is set
|
||||||
ret, err := th.App.GetPluginKey(pluginId, "key")
|
ret, err := th.App.GetPluginKey(pluginID, "key")
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, []byte(`value-1`), ret)
|
assert.Equal(t, []byte(`value-1`), ret)
|
||||||
|
|
||||||
// test that the value is not longer
|
// test that the value is not longer
|
||||||
time.Sleep(1500 * time.Millisecond)
|
time.Sleep(1500 * time.Millisecond)
|
||||||
|
|
||||||
ret, err = th.App.GetPluginKey(pluginId, "key")
|
ret, err = th.App.GetPluginKey(pluginID, "key")
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Nil(t, ret)
|
assert.Nil(t, ret)
|
||||||
})
|
})
|
||||||
|
|||||||
102
app/post.go
102
app/post.go
@@ -126,8 +126,8 @@ func (a *App) deduplicateCreatePost(post *model.Post) (foundPost *model.Post, er
|
|||||||
|
|
||||||
// Query the cache atomically for the given pending post id, saving a record if
|
// Query the cache atomically for the given pending post id, saving a record if
|
||||||
// it hasn't previously been seen.
|
// it hasn't previously been seen.
|
||||||
var postId string
|
var postID string
|
||||||
nErr := a.Srv().seenPendingPostIdsCache.Get(post.PendingPostId, &postId)
|
nErr := a.Srv().seenPendingPostIdsCache.Get(post.PendingPostId, &postID)
|
||||||
if nErr == cache.ErrKeyNotFound {
|
if nErr == cache.ErrKeyNotFound {
|
||||||
a.Srv().seenPendingPostIdsCache.SetWithExpiry(post.PendingPostId, unknownPostId, PendingPostIDsCacheTTL)
|
a.Srv().seenPendingPostIdsCache.SetWithExpiry(post.PendingPostId, unknownPostId, PendingPostIDsCacheTTL)
|
||||||
return nil, nil
|
return nil, nil
|
||||||
@@ -140,13 +140,13 @@ func (a *App) deduplicateCreatePost(post *model.Post) (foundPost *model.Post, er
|
|||||||
// If another thread saved the cache record, but hasn't yet updated it with the actual post
|
// If another thread saved the cache record, but hasn't yet updated it with the actual post
|
||||||
// id (because it's still saving), notify the client with an error. Ideally, we'd wait
|
// id (because it's still saving), notify the client with an error. Ideally, we'd wait
|
||||||
// for the other thread, but coordinating that adds complexity to the happy path.
|
// for the other thread, but coordinating that adds complexity to the happy path.
|
||||||
if postId == unknownPostId {
|
if postID == unknownPostId {
|
||||||
return nil, model.NewAppError("deduplicateCreatePost", "api.post.deduplicate_create_post.pending", nil, "", http.StatusInternalServerError)
|
return nil, model.NewAppError("deduplicateCreatePost", "api.post.deduplicate_create_post.pending", nil, "", http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the other thread finished creating the post, return the created post back to the
|
// If the other thread finished creating the post, return the created post back to the
|
||||||
// client, making the API call feel idempotent.
|
// client, making the API call feel idempotent.
|
||||||
actualPost, err := a.GetSinglePost(postId)
|
actualPost, err := a.GetSinglePost(postID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, model.NewAppError("deduplicateCreatePost", "api.post.deduplicate_create_post.failed_to_get", nil, err.Error(), http.StatusInternalServerError)
|
return nil, model.NewAppError("deduplicateCreatePost", "api.post.deduplicate_create_post.failed_to_get", nil, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
@@ -365,14 +365,14 @@ func (a *App) CreatePost(post *model.Post, channel *model.Channel, triggerWebhoo
|
|||||||
|
|
||||||
func (a *App) attachFilesToPost(post *model.Post) *model.AppError {
|
func (a *App) attachFilesToPost(post *model.Post) *model.AppError {
|
||||||
var attachedIds []string
|
var attachedIds []string
|
||||||
for _, fileId := range post.FileIds {
|
for _, fileID := range post.FileIds {
|
||||||
err := a.Srv().Store.FileInfo().AttachToPost(fileId, post.Id, post.UserId)
|
err := a.Srv().Store.FileInfo().AttachToPost(fileID, post.Id, post.UserId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
mlog.Warn("Failed to attach file to post", mlog.String("file_id", fileId), mlog.String("post_id", post.Id), mlog.Err(err))
|
mlog.Warn("Failed to attach file to post", mlog.String("file_id", fileID), mlog.String("post_id", post.Id), mlog.Err(err))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
attachedIds = append(attachedIds, fileId)
|
attachedIds = append(attachedIds, fileID)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(post.FileIds) != len(attachedIds) {
|
if len(post.FileIds) != len(attachedIds) {
|
||||||
@@ -526,9 +526,9 @@ func (a *App) UpdateEphemeralPost(userID string, post *model.Post) *model.Post {
|
|||||||
return post
|
return post
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) DeleteEphemeralPost(userID, postId string) {
|
func (a *App) DeleteEphemeralPost(userID, postID string) {
|
||||||
post := &model.Post{
|
post := &model.Post{
|
||||||
Id: postId,
|
Id: postID,
|
||||||
UserId: userID,
|
UserId: userID,
|
||||||
Type: model.POST_EPHEMERAL,
|
Type: model.POST_EPHEMERAL,
|
||||||
DeleteAt: model.GetMillis(),
|
DeleteAt: model.GetMillis(),
|
||||||
@@ -659,8 +659,8 @@ func (a *App) UpdatePost(post *model.Post, safeUpdate bool) (*model.Post, *model
|
|||||||
return rpost, nil
|
return rpost, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) PatchPost(postId string, patch *model.PostPatch) (*model.Post, *model.AppError) {
|
func (a *App) PatchPost(postID string, patch *model.PostPatch) (*model.Post, *model.AppError) {
|
||||||
post, err := a.GetSinglePost(postId)
|
post, err := a.GetSinglePost(postID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -704,8 +704,8 @@ func (a *App) GetPostsPage(options model.GetPostsOptions) (*model.PostList, *mod
|
|||||||
return postList, nil
|
return postList, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetPosts(channelId string, offset int, limit int) (*model.PostList, *model.AppError) {
|
func (a *App) GetPosts(channelID string, offset int, limit int) (*model.PostList, *model.AppError) {
|
||||||
postList, err := a.Srv().Store.Post().GetPosts(model.GetPostsOptions{ChannelId: channelId, Page: offset, PerPage: limit}, true)
|
postList, err := a.Srv().Store.Post().GetPosts(model.GetPostsOptions{ChannelId: channelID, Page: offset, PerPage: limit}, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
var invErr *store.ErrInvalidInput
|
var invErr *store.ErrInvalidInput
|
||||||
switch {
|
switch {
|
||||||
@@ -719,8 +719,8 @@ func (a *App) GetPosts(channelId string, offset int, limit int) (*model.PostList
|
|||||||
return postList, nil
|
return postList, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetPostsEtag(channelId string, collapsedThreads bool) string {
|
func (a *App) GetPostsEtag(channelID string, collapsedThreads bool) string {
|
||||||
return a.Srv().Store.Post().GetEtag(channelId, true, collapsedThreads)
|
return a.Srv().Store.Post().GetEtag(channelID, true, collapsedThreads)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetPostsSince(options model.GetPostsSinceOptions) (*model.PostList, *model.AppError) {
|
func (a *App) GetPostsSince(options model.GetPostsSinceOptions) (*model.PostList, *model.AppError) {
|
||||||
@@ -732,8 +732,8 @@ func (a *App) GetPostsSince(options model.GetPostsSinceOptions) (*model.PostList
|
|||||||
return postList, nil
|
return postList, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetSinglePost(postId string) (*model.Post, *model.AppError) {
|
func (a *App) GetSinglePost(postID string) (*model.Post, *model.AppError) {
|
||||||
post, err := a.Srv().Store.Post().GetSingle(postId)
|
post, err := a.Srv().Store.Post().GetSingle(postID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
var nfErr *store.ErrNotFound
|
var nfErr *store.ErrNotFound
|
||||||
switch {
|
switch {
|
||||||
@@ -747,8 +747,8 @@ func (a *App) GetSinglePost(postId string) (*model.Post, *model.AppError) {
|
|||||||
return post, nil
|
return post, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetPostThread(postId string, skipFetchThreads, collapsedThreads, collapsedThreadsExtended bool) (*model.PostList, *model.AppError) {
|
func (a *App) GetPostThread(postID string, skipFetchThreads, collapsedThreads, collapsedThreadsExtended bool) (*model.PostList, *model.AppError) {
|
||||||
posts, err := a.Srv().Store.Post().Get(postId, skipFetchThreads, collapsedThreads, collapsedThreadsExtended)
|
posts, err := a.Srv().Store.Post().Get(postID, skipFetchThreads, collapsedThreads, collapsedThreadsExtended)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
var nfErr *store.ErrNotFound
|
var nfErr *store.ErrNotFound
|
||||||
var invErr *store.ErrInvalidInput
|
var invErr *store.ErrInvalidInput
|
||||||
@@ -783,8 +783,8 @@ func (a *App) GetFlaggedPostsForTeam(userID, teamID string, offset int, limit in
|
|||||||
return postList, nil
|
return postList, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetFlaggedPostsForChannel(userID, channelId string, offset int, limit int) (*model.PostList, *model.AppError) {
|
func (a *App) GetFlaggedPostsForChannel(userID, channelID string, offset int, limit int) (*model.PostList, *model.AppError) {
|
||||||
postList, err := a.Srv().Store.Post().GetFlaggedPostsForChannel(userID, channelId, offset, limit)
|
postList, err := a.Srv().Store.Post().GetFlaggedPostsForChannel(userID, channelID, offset, limit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, model.NewAppError("GetFlaggedPostsForChannel", "app.post.get_flagged_posts.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return nil, model.NewAppError("GetFlaggedPostsForChannel", "app.post.get_flagged_posts.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
@@ -792,8 +792,8 @@ func (a *App) GetFlaggedPostsForChannel(userID, channelId string, offset int, li
|
|||||||
return postList, nil
|
return postList, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetPermalinkPost(postId string, userID string) (*model.PostList, *model.AppError) {
|
func (a *App) GetPermalinkPost(postID string, userID string) (*model.PostList, *model.AppError) {
|
||||||
list, nErr := a.Srv().Store.Post().Get(postId, false, false, false)
|
list, nErr := a.Srv().Store.Post().Get(postID, false, false, false)
|
||||||
if nErr != nil {
|
if nErr != nil {
|
||||||
var nfErr *store.ErrNotFound
|
var nfErr *store.ErrNotFound
|
||||||
var invErr *store.ErrInvalidInput
|
var invErr *store.ErrInvalidInput
|
||||||
@@ -876,8 +876,8 @@ func (a *App) GetPostsAroundPost(before bool, options model.GetPostsOptions) (*m
|
|||||||
return postList, nil
|
return postList, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetPostAfterTime(channelId string, time int64) (*model.Post, *model.AppError) {
|
func (a *App) GetPostAfterTime(channelID string, time int64) (*model.Post, *model.AppError) {
|
||||||
post, err := a.Srv().Store.Post().GetPostAfterTime(channelId, time)
|
post, err := a.Srv().Store.Post().GetPostAfterTime(channelID, time)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, model.NewAppError("GetPostAfterTime", "app.post.get_post_after_time.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return nil, model.NewAppError("GetPostAfterTime", "app.post.get_post_after_time.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
@@ -885,22 +885,22 @@ func (a *App) GetPostAfterTime(channelId string, time int64) (*model.Post, *mode
|
|||||||
return post, nil
|
return post, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetPostIdAfterTime(channelId string, time int64) (string, *model.AppError) {
|
func (a *App) GetPostIdAfterTime(channelID string, time int64) (string, *model.AppError) {
|
||||||
postId, err := a.Srv().Store.Post().GetPostIdAfterTime(channelId, time)
|
postID, err := a.Srv().Store.Post().GetPostIdAfterTime(channelID, time)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", model.NewAppError("GetPostIdAfterTime", "app.post.get_post_id_around.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return "", model.NewAppError("GetPostIdAfterTime", "app.post.get_post_id_around.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
return postId, nil
|
return postID, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetPostIdBeforeTime(channelId string, time int64) (string, *model.AppError) {
|
func (a *App) GetPostIdBeforeTime(channelID string, time int64) (string, *model.AppError) {
|
||||||
postId, err := a.Srv().Store.Post().GetPostIdBeforeTime(channelId, time)
|
postID, err := a.Srv().Store.Post().GetPostIdBeforeTime(channelID, time)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", model.NewAppError("GetPostIdBeforeTime", "app.post.get_post_id_around.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return "", model.NewAppError("GetPostIdBeforeTime", "app.post.get_post_id_around.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
return postId, nil
|
return postID, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetNextPostIdFromPostList(postList *model.PostList) string {
|
func (a *App) GetNextPostIdFromPostList(postList *model.PostList) string {
|
||||||
@@ -976,16 +976,16 @@ func (a *App) AddCursorIdsForPostList(originalList *model.PostList, afterPost, b
|
|||||||
originalList.NextPostId = nextPostId
|
originalList.NextPostId = nextPostId
|
||||||
originalList.PrevPostId = prevPostId
|
originalList.PrevPostId = prevPostId
|
||||||
}
|
}
|
||||||
func (a *App) GetPostsForChannelAroundLastUnread(channelId, userID string, limitBefore, limitAfter int, skipFetchThreads bool, collapsedThreads, collapsedThreadsExtended bool) (*model.PostList, *model.AppError) {
|
func (a *App) GetPostsForChannelAroundLastUnread(channelID, userID string, limitBefore, limitAfter int, skipFetchThreads bool, collapsedThreads, collapsedThreadsExtended bool) (*model.PostList, *model.AppError) {
|
||||||
var member *model.ChannelMember
|
var member *model.ChannelMember
|
||||||
var err *model.AppError
|
var err *model.AppError
|
||||||
if member, err = a.GetChannelMember(channelId, userID); err != nil {
|
if member, err = a.GetChannelMember(channelID, userID); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else if member.LastViewedAt == 0 {
|
} else if member.LastViewedAt == 0 {
|
||||||
return model.NewPostList(), nil
|
return model.NewPostList(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
lastUnreadPostId, err := a.GetPostIdAfterTime(channelId, member.LastViewedAt)
|
lastUnreadPostId, err := a.GetPostIdAfterTime(channelID, member.LastViewedAt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else if lastUnreadPostId == "" {
|
} else if lastUnreadPostId == "" {
|
||||||
@@ -1000,13 +1000,13 @@ func (a *App) GetPostsForChannelAroundLastUnread(channelId, userID string, limit
|
|||||||
// channel organically, those replies will be added below.
|
// channel organically, those replies will be added below.
|
||||||
postList.Order = []string{lastUnreadPostId}
|
postList.Order = []string{lastUnreadPostId}
|
||||||
|
|
||||||
if postListBefore, err := a.GetPostsBeforePost(model.GetPostsOptions{ChannelId: channelId, PostId: lastUnreadPostId, Page: PageDefault, PerPage: limitBefore, SkipFetchThreads: skipFetchThreads, CollapsedThreads: collapsedThreads, CollapsedThreadsExtended: collapsedThreadsExtended}); err != nil {
|
if postListBefore, err := a.GetPostsBeforePost(model.GetPostsOptions{ChannelId: channelID, PostId: lastUnreadPostId, Page: PageDefault, PerPage: limitBefore, SkipFetchThreads: skipFetchThreads, CollapsedThreads: collapsedThreads, CollapsedThreadsExtended: collapsedThreadsExtended}); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else if postListBefore != nil {
|
} else if postListBefore != nil {
|
||||||
postList.Extend(postListBefore)
|
postList.Extend(postListBefore)
|
||||||
}
|
}
|
||||||
|
|
||||||
if postListAfter, err := a.GetPostsAfterPost(model.GetPostsOptions{ChannelId: channelId, PostId: lastUnreadPostId, Page: PageDefault, PerPage: limitAfter - 1, SkipFetchThreads: skipFetchThreads, CollapsedThreads: collapsedThreads, CollapsedThreadsExtended: collapsedThreadsExtended}); err != nil {
|
if postListAfter, err := a.GetPostsAfterPost(model.GetPostsOptions{ChannelId: channelID, PostId: lastUnreadPostId, Page: PageDefault, PerPage: limitAfter - 1, SkipFetchThreads: skipFetchThreads, CollapsedThreads: collapsedThreads, CollapsedThreadsExtended: collapsedThreadsExtended}); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else if postListAfter != nil {
|
} else if postListAfter != nil {
|
||||||
postList.Extend(postListAfter)
|
postList.Extend(postListAfter)
|
||||||
@@ -1016,8 +1016,8 @@ func (a *App) GetPostsForChannelAroundLastUnread(channelId, userID string, limit
|
|||||||
return postList, nil
|
return postList, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) DeletePost(postId, deleteByID string) (*model.Post, *model.AppError) {
|
func (a *App) DeletePost(postID, deleteByID string) (*model.Post, *model.AppError) {
|
||||||
post, nErr := a.Srv().Store.Post().GetSingle(postId)
|
post, nErr := a.Srv().Store.Post().GetSingle(postID)
|
||||||
if nErr != nil {
|
if nErr != nil {
|
||||||
return nil, model.NewAppError("DeletePost", "app.post.get.app_error", nil, nErr.Error(), http.StatusBadRequest)
|
return nil, model.NewAppError("DeletePost", "app.post.get.app_error", nil, nErr.Error(), http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
@@ -1032,7 +1032,7 @@ func (a *App) DeletePost(postId, deleteByID string) (*model.Post, *model.AppErro
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := a.Srv().Store.Post().Delete(postId, model.GetMillis(), deleteByID); err != nil {
|
if err := a.Srv().Store.Post().Delete(postID, model.GetMillis(), deleteByID); err != nil {
|
||||||
var nfErr *store.ErrNotFound
|
var nfErr *store.ErrNotFound
|
||||||
switch {
|
switch {
|
||||||
case errors.As(err, &nfErr):
|
case errors.As(err, &nfErr):
|
||||||
@@ -1067,8 +1067,8 @@ func (a *App) DeletePost(postId, deleteByID string) (*model.Post, *model.AppErro
|
|||||||
return post, nil
|
return post, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) DeleteFlaggedPosts(postId string) {
|
func (a *App) DeleteFlaggedPosts(postID string) {
|
||||||
if err := a.Srv().Store.Preference().DeleteCategoryAndName(model.PREFERENCE_CATEGORY_FLAGGED_POST, postId); err != nil {
|
if err := a.Srv().Store.Preference().DeleteCategoryAndName(model.PREFERENCE_CATEGORY_FLAGGED_POST, postID); err != nil {
|
||||||
mlog.Warn("Unable to delete flagged post preference when deleting post.", mlog.Err(err))
|
mlog.Warn("Unable to delete flagged post preference when deleting post.", mlog.Err(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -1238,16 +1238,16 @@ func (a *App) SearchPostsInTeamForUser(terms string, userID string, teamID strin
|
|||||||
return postSearchResults, nil
|
return postSearchResults, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetFileInfosForPostWithMigration(postId string) ([]*model.FileInfo, *model.AppError) {
|
func (a *App) GetFileInfosForPostWithMigration(postID string) ([]*model.FileInfo, *model.AppError) {
|
||||||
|
|
||||||
pchan := make(chan store.StoreResult, 1)
|
pchan := make(chan store.StoreResult, 1)
|
||||||
go func() {
|
go func() {
|
||||||
post, err := a.Srv().Store.Post().GetSingle(postId)
|
post, err := a.Srv().Store.Post().GetSingle(postID)
|
||||||
pchan <- store.StoreResult{Data: post, NErr: err}
|
pchan <- store.StoreResult{Data: post, NErr: err}
|
||||||
close(pchan)
|
close(pchan)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
infos, err := a.GetFileInfosForPost(postId, false)
|
infos, err := a.GetFileInfosForPost(postID, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -1267,8 +1267,8 @@ func (a *App) GetFileInfosForPostWithMigration(postId string) ([]*model.FileInfo
|
|||||||
post := result.Data.(*model.Post)
|
post := result.Data.(*model.Post)
|
||||||
|
|
||||||
if len(post.Filenames) > 0 {
|
if len(post.Filenames) > 0 {
|
||||||
a.Srv().Store.FileInfo().InvalidateFileInfosForPostCache(postId, false)
|
a.Srv().Store.FileInfo().InvalidateFileInfosForPostCache(postID, false)
|
||||||
a.Srv().Store.FileInfo().InvalidateFileInfosForPostCache(postId, true)
|
a.Srv().Store.FileInfo().InvalidateFileInfosForPostCache(postID, true)
|
||||||
// The post has Filenames that need to be replaced with FileInfos
|
// The post has Filenames that need to be replaced with FileInfos
|
||||||
infos = a.MigrateFilenamesToFileInfos(post)
|
infos = a.MigrateFilenamesToFileInfos(post)
|
||||||
}
|
}
|
||||||
@@ -1277,8 +1277,8 @@ func (a *App) GetFileInfosForPostWithMigration(postId string) ([]*model.FileInfo
|
|||||||
return infos, nil
|
return infos, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetFileInfosForPost(postId string, fromMaster bool) ([]*model.FileInfo, *model.AppError) {
|
func (a *App) GetFileInfosForPost(postID string, fromMaster bool) ([]*model.FileInfo, *model.AppError) {
|
||||||
fileInfos, err := a.Srv().Store.FileInfo().GetForPost(postId, fromMaster, false, true)
|
fileInfos, err := a.Srv().Store.FileInfo().GetForPost(postID, fromMaster, false, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, model.NewAppError("GetFileInfosForPost", "app.file_info.get_for_post.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return nil, model.NewAppError("GetFileInfosForPost", "app.file_info.get_for_post.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
@@ -1464,8 +1464,8 @@ func (a *App) countMentionsFromPost(user *model.User, post *model.Post) (int, *m
|
|||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, postId := range postList.Order {
|
for _, postID := range postList.Order {
|
||||||
if isPostMention(user, postList.Posts[postId], keywords, postList.Posts, mentionedByThread, checkForCommentMentions) {
|
if isPostMention(user, postList.Posts[postID], keywords, postList.Posts, mentionedByThread, checkForCommentMentions) {
|
||||||
count += 1
|
count += 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -625,12 +625,12 @@ func TestDeletePostWithFileAttachments(t *testing.T) {
|
|||||||
|
|
||||||
// Create a post with a file attachment.
|
// Create a post with a file attachment.
|
||||||
teamID := th.BasicTeam.Id
|
teamID := th.BasicTeam.Id
|
||||||
channelId := th.BasicChannel.Id
|
channelID := th.BasicChannel.Id
|
||||||
userID := th.BasicUser.Id
|
userID := th.BasicUser.Id
|
||||||
filename := "test"
|
filename := "test"
|
||||||
data := []byte("abcd")
|
data := []byte("abcd")
|
||||||
|
|
||||||
info1, err := th.App.DoUploadFile(time.Date(2007, 2, 4, 1, 2, 3, 4, time.Local), teamID, channelId, userID, filename, data)
|
info1, err := th.App.DoUploadFile(time.Date(2007, 2, 4, 1, 2, 3, 4, time.Local), teamID, channelID, userID, filename, data)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
defer func() {
|
defer func() {
|
||||||
th.App.Srv().Store.FileInfo().PermanentDelete(info1.Id)
|
th.App.Srv().Store.FileInfo().PermanentDelete(info1.Id)
|
||||||
@@ -639,7 +639,7 @@ func TestDeletePostWithFileAttachments(t *testing.T) {
|
|||||||
|
|
||||||
post := &model.Post{
|
post := &model.Post{
|
||||||
Message: "asd",
|
Message: "asd",
|
||||||
ChannelId: channelId,
|
ChannelId: channelID,
|
||||||
PendingPostId: model.NewId() + ":" + fmt.Sprint(model.GetMillis()),
|
PendingPostId: model.NewId() + ":" + fmt.Sprint(model.GetMillis()),
|
||||||
UserId: userID,
|
UserId: userID,
|
||||||
CreateAt: 0,
|
CreateAt: 0,
|
||||||
|
|||||||
@@ -69,18 +69,18 @@ func (a *App) SaveReactionForPost(reaction *model.Reaction) (*model.Reaction, *m
|
|||||||
return reaction, nil
|
return reaction, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetReactionsForPost(postId string) ([]*model.Reaction, *model.AppError) {
|
func (a *App) GetReactionsForPost(postID string) ([]*model.Reaction, *model.AppError) {
|
||||||
reactions, err := a.Srv().Store.Reaction().GetForPost(postId, true)
|
reactions, err := a.Srv().Store.Reaction().GetForPost(postID, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, model.NewAppError("GetReactionsForPost", "app.reaction.get_for_post.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return nil, model.NewAppError("GetReactionsForPost", "app.reaction.get_for_post.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
return reactions, nil
|
return reactions, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetBulkReactionsForPosts(postIds []string) (map[string][]*model.Reaction, *model.AppError) {
|
func (a *App) GetBulkReactionsForPosts(postIDs []string) (map[string][]*model.Reaction, *model.AppError) {
|
||||||
reactions := make(map[string][]*model.Reaction)
|
reactions := make(map[string][]*model.Reaction)
|
||||||
|
|
||||||
allReactions, err := a.Srv().Store.Reaction().BulkGetForPosts(postIds)
|
allReactions, err := a.Srv().Store.Reaction().BulkGetForPosts(postIDs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, model.NewAppError("GetBulkReactionsForPosts", "app.reaction.bulk_get_for_post_ids.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return nil, model.NewAppError("GetBulkReactionsForPosts", "app.reaction.bulk_get_for_post_ids.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
@@ -92,14 +92,14 @@ func (a *App) GetBulkReactionsForPosts(postIds []string) (map[string][]*model.Re
|
|||||||
reactions[reaction.PostId] = reactionsForPost
|
reactions[reaction.PostId] = reactionsForPost
|
||||||
}
|
}
|
||||||
|
|
||||||
reactions = populateEmptyReactions(postIds, reactions)
|
reactions = populateEmptyReactions(postIDs, reactions)
|
||||||
return reactions, nil
|
return reactions, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func populateEmptyReactions(postIds []string, reactions map[string][]*model.Reaction) map[string][]*model.Reaction {
|
func populateEmptyReactions(postIDs []string, reactions map[string][]*model.Reaction) map[string][]*model.Reaction {
|
||||||
for _, postId := range postIds {
|
for _, postID := range postIDs {
|
||||||
if _, present := reactions[postId]; !present {
|
if _, present := reactions[postID]; !present {
|
||||||
reactions[postId] = []*model.Reaction{}
|
reactions[postID] = []*model.Reaction{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return reactions
|
return reactions
|
||||||
|
|||||||
@@ -269,16 +269,16 @@ func (a *App) SessionCacheLength() int {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) RevokeSessionsForDeviceId(userID string, deviceId string, currentSessionId string) *model.AppError {
|
func (a *App) RevokeSessionsForDeviceId(userID string, deviceID string, currentSessionId string) *model.AppError {
|
||||||
sessions, err := a.Srv().Store.Session().GetSessions(userID)
|
sessions, err := a.Srv().Store.Session().GetSessions(userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return model.NewAppError("RevokeSessionsForDeviceId", "app.session.get_sessions.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return model.NewAppError("RevokeSessionsForDeviceId", "app.session.get_sessions.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
for _, session := range sessions {
|
for _, session := range sessions {
|
||||||
if session.DeviceId == deviceId && session.Id != currentSessionId {
|
if session.DeviceId == deviceID && session.Id != currentSessionId {
|
||||||
mlog.Debug("Revoking sessionId for userId. Re-login with the same device Id", mlog.String("session_id", session.Id), mlog.String("user_id", userID))
|
mlog.Debug("Revoking sessionId for userId. Re-login with the same device Id", mlog.String("session_id", session.Id), mlog.String("user_id", userID))
|
||||||
if err := a.RevokeSession(session); err != nil {
|
if err := a.RevokeSession(session); err != nil {
|
||||||
mlog.Warn("Could not revoke session for device", mlog.String("device_id", deviceId), mlog.Err(err))
|
mlog.Warn("Could not revoke session for device", mlog.String("device_id", deviceID), mlog.Err(err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -286,8 +286,8 @@ func (a *App) RevokeSessionsForDeviceId(userID string, deviceId string, currentS
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetSessionById(sessionId string) (*model.Session, *model.AppError) {
|
func (a *App) GetSessionById(sessionID string) (*model.Session, *model.AppError) {
|
||||||
session, err := a.Srv().Store.Session().Get(sessionId)
|
session, err := a.Srv().Store.Session().Get(sessionID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, model.NewAppError("GetSessionById", "app.session.get.app_error", nil, err.Error(), http.StatusBadRequest)
|
return nil, model.NewAppError("GetSessionById", "app.session.get.app_error", nil, err.Error(), http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
@@ -295,8 +295,8 @@ func (a *App) GetSessionById(sessionId string) (*model.Session, *model.AppError)
|
|||||||
return session, nil
|
return session, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) RevokeSessionById(sessionId string) *model.AppError {
|
func (a *App) RevokeSessionById(sessionID string) *model.AppError {
|
||||||
session, err := a.Srv().Store.Session().Get(sessionId)
|
session, err := a.Srv().Store.Session().Get(sessionID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return model.NewAppError("RevokeSessionById", "app.session.get.app_error", nil, err.Error(), http.StatusBadRequest)
|
return model.NewAppError("RevokeSessionById", "app.session.get.app_error", nil, err.Error(), http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
@@ -320,8 +320,8 @@ func (a *App) RevokeSession(session *model.Session) *model.AppError {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) AttachDeviceId(sessionId string, deviceId string, expiresAt int64) *model.AppError {
|
func (a *App) AttachDeviceId(sessionID string, deviceID string, expiresAt int64) *model.AppError {
|
||||||
_, err := a.Srv().Store.Session().UpdateDeviceId(sessionId, deviceId, expiresAt)
|
_, err := a.Srv().Store.Session().UpdateDeviceId(sessionID, deviceID, expiresAt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return model.NewAppError("AttachDeviceId", "app.session.update_device_id.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return model.NewAppError("AttachDeviceId", "app.session.update_device_id.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,10 +73,10 @@ func (cfg *AutoPostCreator) CreateRandomPost() (*model.Post, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (cfg *AutoPostCreator) CreateRandomPostNested(parentId, rootId string) (*model.Post, error) {
|
func (cfg *AutoPostCreator) CreateRandomPostNested(parentId, rootId string) (*model.Post, error) {
|
||||||
var fileIds []string
|
var fileIDs []string
|
||||||
if cfg.HasImage {
|
if cfg.HasImage {
|
||||||
var err error
|
var err error
|
||||||
fileIds, err = cfg.UploadTestFile()
|
fileIDs, err = cfg.UploadTestFile()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -95,7 +95,7 @@ func (cfg *AutoPostCreator) CreateRandomPostNested(parentId, rootId string) (*mo
|
|||||||
ParentId: parentId,
|
ParentId: parentId,
|
||||||
RootId: rootId,
|
RootId: rootId,
|
||||||
Message: postText,
|
Message: postText,
|
||||||
FileIds: fileIds,
|
FileIds: fileIDs,
|
||||||
}
|
}
|
||||||
rpost, err := cfg.a.CreatePostMissingChannel(post, true)
|
rpost, err := cfg.a.CreatePostMissingChannel(post, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
50
app/user.go
50
app/user.go
@@ -274,7 +274,7 @@ func (a *App) createUserOrGuest(user *model.User, guest bool) (*model.User, *mod
|
|||||||
if appErr != nil {
|
if appErr != nil {
|
||||||
return nil, appErr
|
return nil, appErr
|
||||||
}
|
}
|
||||||
// This message goes to everyone, so the teamID, channelId and userID are irrelevant
|
// This message goes to everyone, so the teamID, channelID and userID are irrelevant
|
||||||
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_NEW_USER, "", "", "", nil)
|
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_NEW_USER, "", "", "", nil)
|
||||||
message.Add("user_id", ruser.Id)
|
message.Add("user_id", ruser.Id)
|
||||||
a.Publish(message)
|
a.Publish(message)
|
||||||
@@ -609,8 +609,8 @@ func (a *App) GetUsersInChannelPageByStatus(options *model.UserGetOptions, asAdm
|
|||||||
return a.sanitizeProfiles(users, asAdmin), nil
|
return a.sanitizeProfiles(users, asAdmin), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetUsersNotInChannel(teamID string, channelId string, groupConstrained bool, offset int, limit int, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError) {
|
func (a *App) GetUsersNotInChannel(teamID string, channelID string, groupConstrained bool, offset int, limit int, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError) {
|
||||||
users, err := a.Srv().Store.User().GetProfilesNotInChannel(teamID, channelId, groupConstrained, offset, limit, viewRestrictions)
|
users, err := a.Srv().Store.User().GetProfilesNotInChannel(teamID, channelID, groupConstrained, offset, limit, viewRestrictions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, model.NewAppError("GetUsersNotInChannel", "app.user.get_profiles.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return nil, model.NewAppError("GetUsersNotInChannel", "app.user.get_profiles.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
@@ -618,8 +618,8 @@ func (a *App) GetUsersNotInChannel(teamID string, channelId string, groupConstra
|
|||||||
return users, nil
|
return users, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetUsersNotInChannelMap(teamID string, channelId string, groupConstrained bool, offset int, limit int, asAdmin bool, viewRestrictions *model.ViewUsersRestrictions) (map[string]*model.User, *model.AppError) {
|
func (a *App) GetUsersNotInChannelMap(teamID string, channelID string, groupConstrained bool, offset int, limit int, asAdmin bool, viewRestrictions *model.ViewUsersRestrictions) (map[string]*model.User, *model.AppError) {
|
||||||
users, err := a.GetUsersNotInChannel(teamID, channelId, groupConstrained, offset, limit, viewRestrictions)
|
users, err := a.GetUsersNotInChannel(teamID, channelID, groupConstrained, offset, limit, viewRestrictions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -634,8 +634,8 @@ func (a *App) GetUsersNotInChannelMap(teamID string, channelId string, groupCons
|
|||||||
return userMap, nil
|
return userMap, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetUsersNotInChannelPage(teamID string, channelId string, groupConstrained bool, page int, perPage int, asAdmin bool, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError) {
|
func (a *App) GetUsersNotInChannelPage(teamID string, channelID string, groupConstrained bool, page int, perPage int, asAdmin bool, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError) {
|
||||||
users, err := a.GetUsersNotInChannel(teamID, channelId, groupConstrained, page*perPage, perPage, viewRestrictions)
|
users, err := a.GetUsersNotInChannel(teamID, channelID, groupConstrained, page*perPage, perPage, viewRestrictions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -692,13 +692,13 @@ func (a *App) GetUsersByIds(userIDs []string, options *store.UserGetByIdsOpts) (
|
|||||||
return a.sanitizeProfiles(users, options.IsAdmin), nil
|
return a.sanitizeProfiles(users, options.IsAdmin), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetUsersByGroupChannelIds(channelIds []string, asAdmin bool) (map[string][]*model.User, *model.AppError) {
|
func (a *App) GetUsersByGroupChannelIds(channelIDs []string, asAdmin bool) (map[string][]*model.User, *model.AppError) {
|
||||||
usersByChannelId, err := a.Srv().Store.User().GetProfileByGroupChannelIdsForUser(a.Session().UserId, channelIds)
|
usersByChannelId, err := a.Srv().Store.User().GetProfileByGroupChannelIdsForUser(a.Session().UserId, channelIDs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, model.NewAppError("GetUsersByGroupChannelIds", "app.user.get_profile_by_group_channel_ids_for_user.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return nil, model.NewAppError("GetUsersByGroupChannelIds", "app.user.get_profile_by_group_channel_ids_for_user.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
for channelId, userList := range usersByChannelId {
|
for channelID, userList := range usersByChannelId {
|
||||||
usersByChannelId[channelId] = a.sanitizeProfiles(userList, asAdmin)
|
usersByChannelId[channelID] = a.sanitizeProfiles(userList, asAdmin)
|
||||||
}
|
}
|
||||||
|
|
||||||
return usersByChannelId, nil
|
return usersByChannelId, nil
|
||||||
@@ -1863,9 +1863,9 @@ func (a *App) SearchUsers(props *model.UserSearch, options *model.UserSearchOpti
|
|||||||
return a.SearchUsersInTeam(props.TeamId, props.Term, options)
|
return a.SearchUsersInTeam(props.TeamId, props.Term, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) SearchUsersInChannel(channelId string, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError) {
|
func (a *App) SearchUsersInChannel(channelID string, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError) {
|
||||||
term = strings.TrimSpace(term)
|
term = strings.TrimSpace(term)
|
||||||
users, err := a.Srv().Store.User().SearchInChannel(channelId, term, options)
|
users, err := a.Srv().Store.User().SearchInChannel(channelID, term, options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, model.NewAppError("SearchUsersInChannel", "app.user.search.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return nil, model.NewAppError("SearchUsersInChannel", "app.user.search.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
@@ -1876,9 +1876,9 @@ func (a *App) SearchUsersInChannel(channelId string, term string, options *model
|
|||||||
return users, nil
|
return users, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) SearchUsersNotInChannel(teamID string, channelId string, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError) {
|
func (a *App) SearchUsersNotInChannel(teamID string, channelID string, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError) {
|
||||||
term = strings.TrimSpace(term)
|
term = strings.TrimSpace(term)
|
||||||
users, err := a.Srv().Store.User().SearchNotInChannel(teamID, channelId, term, options)
|
users, err := a.Srv().Store.User().SearchNotInChannel(teamID, channelID, term, options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, model.NewAppError("SearchUsersNotInChannel", "app.user.search.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return nil, model.NewAppError("SearchUsersNotInChannel", "app.user.search.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
@@ -1947,10 +1947,10 @@ func (a *App) SearchUsersInGroup(groupID string, term string, options *model.Use
|
|||||||
return users, nil
|
return users, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) AutocompleteUsersInChannel(teamID string, channelId string, term string, options *model.UserSearchOptions) (*model.UserAutocompleteInChannel, *model.AppError) {
|
func (a *App) AutocompleteUsersInChannel(teamID string, channelID string, term string, options *model.UserSearchOptions) (*model.UserAutocompleteInChannel, *model.AppError) {
|
||||||
term = strings.TrimSpace(term)
|
term = strings.TrimSpace(term)
|
||||||
|
|
||||||
autocomplete, err := a.Srv().Store.User().AutocompleteUsersInChannel(teamID, channelId, term, options)
|
autocomplete, err := a.Srv().Store.User().AutocompleteUsersInChannel(teamID, channelID, term, options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, model.NewAppError("AutocompleteUsersInChannel", "app.user.search.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return nil, model.NewAppError("AutocompleteUsersInChannel", "app.user.search.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
@@ -2142,8 +2142,8 @@ func (a *App) UserCanSeeOtherUser(userID string, otherUserId string) (bool, *mod
|
|||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) userBelongsToChannels(userID string, channelIds []string) (bool, *model.AppError) {
|
func (a *App) userBelongsToChannels(userID string, channelIDs []string) (bool, *model.AppError) {
|
||||||
belongs, err := a.Srv().Store.Channel().UserBelongsToChannels(userID, channelIds)
|
belongs, err := a.Srv().Store.Channel().UserBelongsToChannels(userID, channelIDs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, model.NewAppError("userBelongsToChannels", "app.channel.user_belongs_to_channels.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return false, model.NewAppError("userBelongsToChannels", "app.channel.user_belongs_to_channels.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
@@ -2173,12 +2173,12 @@ func (a *App) GetViewUsersRestrictions(userID string) (*model.ViewUsersRestricti
|
|||||||
return nil, model.NewAppError("GetViewUsersRestrictions", "app.channel.get_channels.get.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return nil, model.NewAppError("GetViewUsersRestrictions", "app.channel.get_channels.get.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
channelIds := []string{}
|
channelIDs := []string{}
|
||||||
for channelId := range userChannelMembers {
|
for channelID := range userChannelMembers {
|
||||||
channelIds = append(channelIds, channelId)
|
channelIDs = append(channelIDs, channelID)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &model.ViewUsersRestrictions{Teams: teamIDsWithPermission, Channels: channelIds}, nil
|
return &model.ViewUsersRestrictions{Teams: teamIDsWithPermission, Channels: channelIDs}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// PromoteGuestToUser Convert user's roles and all his mermbership's roles from
|
// PromoteGuestToUser Convert user's roles and all his mermbership's roles from
|
||||||
@@ -2274,11 +2274,11 @@ func (a *App) DemoteUserToGuest(user *model.User) *model.AppError {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) PublishUserTyping(userID, channelId, parentId string) *model.AppError {
|
func (a *App) PublishUserTyping(userID, channelID, parentId string) *model.AppError {
|
||||||
omitUsers := make(map[string]bool, 1)
|
omitUsers := make(map[string]bool, 1)
|
||||||
omitUsers[userID] = true
|
omitUsers[userID] = true
|
||||||
|
|
||||||
event := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_TYPING, "", channelId, "", omitUsers)
|
event := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_TYPING, "", channelID, "", omitUsers)
|
||||||
event.Add("parent_id", parentId)
|
event.Add("parent_id", parentId)
|
||||||
event.Add("user_id", userID)
|
event.Add("user_id", userID)
|
||||||
a.Publish(event)
|
a.Publish(event)
|
||||||
|
|||||||
@@ -234,27 +234,27 @@ func (a *App) invalidateCacheForChannel(channel *model.Channel) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) invalidateCacheForChannelMembers(channelId string) {
|
func (a *App) invalidateCacheForChannelMembers(channelID string) {
|
||||||
a.Srv().Store.User().InvalidateProfilesInChannelCache(channelId)
|
a.Srv().Store.User().InvalidateProfilesInChannelCache(channelID)
|
||||||
a.Srv().Store.Channel().InvalidateMemberCount(channelId)
|
a.Srv().Store.Channel().InvalidateMemberCount(channelID)
|
||||||
a.Srv().Store.Channel().InvalidateGuestCount(channelId)
|
a.Srv().Store.Channel().InvalidateGuestCount(channelID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) invalidateCacheForChannelMembersNotifyProps(channelId string) {
|
func (a *App) invalidateCacheForChannelMembersNotifyProps(channelID string) {
|
||||||
a.invalidateCacheForChannelMembersNotifyPropsSkipClusterSend(channelId)
|
a.invalidateCacheForChannelMembersNotifyPropsSkipClusterSend(channelID)
|
||||||
|
|
||||||
if a.Cluster() != nil {
|
if a.Cluster() != nil {
|
||||||
msg := &model.ClusterMessage{
|
msg := &model.ClusterMessage{
|
||||||
Event: model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_MEMBERS_NOTIFY_PROPS,
|
Event: model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_MEMBERS_NOTIFY_PROPS,
|
||||||
SendType: model.CLUSTER_SEND_BEST_EFFORT,
|
SendType: model.CLUSTER_SEND_BEST_EFFORT,
|
||||||
Data: channelId,
|
Data: channelID,
|
||||||
}
|
}
|
||||||
a.Cluster().SendClusterMessage(msg)
|
a.Cluster().SendClusterMessage(msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) invalidateCacheForChannelMembersNotifyPropsSkipClusterSend(channelId string) {
|
func (a *App) invalidateCacheForChannelMembersNotifyPropsSkipClusterSend(channelID string) {
|
||||||
a.Srv().Store.Channel().InvalidateCacheForChannelMembersNotifyProps(channelId)
|
a.Srv().Store.Channel().InvalidateCacheForChannelMembersNotifyProps(channelID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) invalidateCacheForChannelByNameSkipClusterSend(teamID, name string) {
|
func (a *App) invalidateCacheForChannelByNameSkipClusterSend(teamID, name string) {
|
||||||
@@ -265,9 +265,9 @@ func (a *App) invalidateCacheForChannelByNameSkipClusterSend(teamID, name string
|
|||||||
a.Srv().Store.Channel().InvalidateChannelByName(teamID, name)
|
a.Srv().Store.Channel().InvalidateChannelByName(teamID, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) invalidateCacheForChannelPosts(channelId string) {
|
func (a *App) invalidateCacheForChannelPosts(channelID string) {
|
||||||
a.Srv().Store.Channel().InvalidatePinnedPostCount(channelId)
|
a.Srv().Store.Channel().InvalidatePinnedPostCount(channelID)
|
||||||
a.Srv().Store.Post().InvalidateLastPostTimeCache(channelId)
|
a.Srv().Store.Post().InvalidateLastPostTimeCache(channelID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) InvalidateCacheForUser(userID string) {
|
func (a *App) InvalidateCacheForUser(userID string) {
|
||||||
|
|||||||
@@ -585,12 +585,12 @@ func (a *App) GetOutgoingWebhooksPageByUser(userID string, page, perPage int) ([
|
|||||||
return webhooks, nil
|
return webhooks, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetOutgoingWebhooksForChannelPageByUser(channelId string, userID string, page, perPage int) ([]*model.OutgoingWebhook, *model.AppError) {
|
func (a *App) GetOutgoingWebhooksForChannelPageByUser(channelID string, userID string, page, perPage int) ([]*model.OutgoingWebhook, *model.AppError) {
|
||||||
if !*a.Config().ServiceSettings.EnableOutgoingWebhooks {
|
if !*a.Config().ServiceSettings.EnableOutgoingWebhooks {
|
||||||
return nil, model.NewAppError("GetOutgoingWebhooksForChannelPage", "api.outgoing_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
|
return nil, model.NewAppError("GetOutgoingWebhooksForChannelPage", "api.outgoing_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||||
}
|
}
|
||||||
|
|
||||||
webhooks, err := a.Srv().Store.Webhook().GetOutgoingByChannelByUser(channelId, userID, page*perPage, perPage)
|
webhooks, err := a.Srv().Store.Webhook().GetOutgoingByChannelByUser(channelID, userID, page*perPage, perPage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, model.NewAppError("GetOutgoingWebhooksForChannelPage", "app.webhooks.get_outgoing_by_channel.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return nil, model.NewAppError("GetOutgoingWebhooksForChannelPage", "app.webhooks.get_outgoing_by_channel.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user