Skip to content

Commit 8a0e649

Browse files
authoredSep 30, 2016
PLT-3105 Files table migration (mattermost#4068)
* Implemented initial changes for files table * Removed *_benchmark_test.go files * Re-implemented GetPublicFile and added support for old path * Localization for files table * Moved file system code into utils package * Finished server-side changes and added initial upgrade script * Added getPostFiles api * Re-add Extension and HasPreviewImage fields to FileInfo * Removed unused translation * Fixed merge conflicts left over after permissions changes * Forced FileInfo.extension to be lower case * Changed FileUploadResponse to contain the FileInfos instead of FileIds * Fixed permissions on getFile* calls * Fixed notifications for file uploads * Added initial version of client code for files changes * Permanently added FileIds field to Post object and removed Post.HasFiles * Updated PostStore.Update to be usable in more circumstances * Re-added Filenames field and switched file migration to be entirely lazy-loaded * Increased max listener count for FileStore * Removed unused fileInfoCache * Moved file system code back into api * Removed duplicate test case * Fixed unit test running on ports other than 8065 * Renamed HasPermissionToPostContext to HasPermissionToChannelByPostContext * Refactored handleImages to make it more easily understandable * Renamed getPostFiles to getFileInfosForPost * Re-added pre-FileIds posts to analytics * Changed files to be saved as their ids as opposed to id/filename.ext * Renamed FileInfo.UserId to FileInfo.CreatorId * Fixed detection of language in CodePreview * Fixed switching between threads in the RHS not loading new files * Add serverside protection against a rare bug where the client sends the same file twice for a single post * Refactored the important parts of uploadFile api call into a function that can be called without a web context
1 parent a2deeed commit 8a0e649

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+3316
-1924
lines changed
 

‎api/api.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ type Routes struct {
3333
Commands *mux.Router // 'api/v3/teams/{team_id:[A-Za-z0-9]+}/commands'
3434
Hooks *mux.Router // 'api/v3/teams/{team_id:[A-Za-z0-9]+}/hooks'
3535

36-
Files *mux.Router // 'api/v3/teams/{team_id:[A-Za-z0-9]+}/files'
36+
TeamFiles *mux.Router // 'api/v3/teams/{team_id:[A-Za-z0-9]+}/files'
37+
Files *mux.Router // 'api/v3/files'
38+
NeedFile *mux.Router // 'api/v3/files/{file_id:[A-Za-z0-9]+}'
3739

3840
OAuth *mux.Router // 'api/v3/oauth'
3941

@@ -70,7 +72,9 @@ func InitApi() {
7072
BaseRoutes.Posts = BaseRoutes.NeedChannel.PathPrefix("/posts").Subrouter()
7173
BaseRoutes.NeedPost = BaseRoutes.Posts.PathPrefix("/{post_id:[A-Za-z0-9]+}").Subrouter()
7274
BaseRoutes.Commands = BaseRoutes.NeedTeam.PathPrefix("/commands").Subrouter()
73-
BaseRoutes.Files = BaseRoutes.NeedTeam.PathPrefix("/files").Subrouter()
75+
BaseRoutes.TeamFiles = BaseRoutes.NeedTeam.PathPrefix("/files").Subrouter()
76+
BaseRoutes.Files = BaseRoutes.ApiRoot.PathPrefix("/files").Subrouter()
77+
BaseRoutes.NeedFile = BaseRoutes.Files.PathPrefix("/{file_id:[A-Za-z0-9]+}").Subrouter()
7478
BaseRoutes.Hooks = BaseRoutes.NeedTeam.PathPrefix("/hooks").Subrouter()
7579
BaseRoutes.OAuth = BaseRoutes.ApiRoot.PathPrefix("/oauth").Subrouter()
7680
BaseRoutes.Admin = BaseRoutes.ApiRoot.PathPrefix("/admin").Subrouter()

‎api/authorization.go

+36
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,42 @@ func HasPermissionToChannel(user *model.User, teamMember *model.TeamMember, chan
114114
return HasPermissionToTeam(user, teamMember, permission)
115115
}
116116

117+
func HasPermissionToChannelByPostContext(c *Context, postId string, permission *model.Permission) bool {
118+
cmc := Srv.Store.Channel().GetMemberForPost(postId, c.Session.UserId)
119+
120+
var channelRoles []string
121+
if cmcresult := <-cmc; cmcresult.Err == nil {
122+
channelMember := cmcresult.Data.(*model.ChannelMember)
123+
channelRoles = channelMember.GetRoles()
124+
125+
if CheckIfRolesGrantPermission(channelRoles, permission.Id) {
126+
return true
127+
}
128+
}
129+
130+
cc := Srv.Store.Channel().GetForPost(postId)
131+
if ccresult := <-cc; ccresult.Err == nil {
132+
channel := ccresult.Data.(*model.Channel)
133+
134+
if teamMember := c.Session.GetTeamByTeamId(channel.TeamId); teamMember != nil {
135+
roles := teamMember.GetRoles()
136+
137+
if CheckIfRolesGrantPermission(roles, permission.Id) {
138+
return true
139+
}
140+
}
141+
142+
}
143+
144+
if HasPermissionToContext(c, permission) {
145+
return true
146+
}
147+
148+
c.Err = model.NewLocAppError("HasPermissionToChannelByPostContext", "api.context.permissions.app_error", nil, "userId="+c.Session.UserId+", "+"permission="+permission.Id+" channelRoles="+model.RoleIdsToString(channelRoles))
149+
c.Err.StatusCode = http.StatusForbidden
150+
return false
151+
}
152+
117153
func HasPermissionToUser(c *Context, userId string) bool {
118154
// You are the user (users autmaticly have permissions to themselves)
119155
if c.Session.UserId == userId {

0 commit comments

Comments
 (0)
Please sign in to comment.