| 
									
										
										
										
											2022-10-12 15:01:42 +02:00
										 |  |  | /* | 
					
						
							|  |  |  |    GoToSocial | 
					
						
							|  |  |  |    Copyright (C) 2021-2022 GoToSocial Authors admin@gotosocial.org | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    This program is free software: you can redistribute it and/or modify | 
					
						
							|  |  |  |    it under the terms of the GNU Affero General Public License as published by | 
					
						
							|  |  |  |    the Free Software Foundation, either version 3 of the License, or | 
					
						
							|  |  |  |    (at your option) any later version. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |    but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |    GNU Affero General Public License for more details. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    You should have received a copy of the GNU Affero General Public License | 
					
						
							|  |  |  |    along with this program.  If not, see <http://www.gnu.org/licenses/>. | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | package admin | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							| 
									
										
										
										
											2022-10-13 16:37:55 +02:00
										 |  |  | 	"errors" | 
					
						
							| 
									
										
										
										
											2022-10-12 15:01:42 +02:00
										 |  |  | 	"fmt" | 
					
						
							|  |  |  | 	"net/http" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	"github.com/gin-gonic/gin" | 
					
						
							|  |  |  | 	"github.com/superseriousbusiness/gotosocial/internal/api" | 
					
						
							|  |  |  | 	"github.com/superseriousbusiness/gotosocial/internal/gtserror" | 
					
						
							|  |  |  | 	"github.com/superseriousbusiness/gotosocial/internal/oauth" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-13 16:37:55 +02:00
										 |  |  | // EmojiGETHandler swagger:operation GET /api/v1/admin/custom_emojis/{id} emojiGet | 
					
						
							| 
									
										
										
										
											2022-10-12 15:01:42 +02:00
										 |  |  | // | 
					
						
							| 
									
										
										
										
											2022-10-13 16:37:55 +02:00
										 |  |  | // Get the admin view of a single emoji. | 
					
						
							| 
									
										
										
										
											2022-10-12 15:01:42 +02:00
										 |  |  | // | 
					
						
							|  |  |  | //	--- | 
					
						
							|  |  |  | //	tags: | 
					
						
							|  |  |  | //	- admin | 
					
						
							|  |  |  | // | 
					
						
							|  |  |  | //	produces: | 
					
						
							|  |  |  | //	- application/json | 
					
						
							|  |  |  | // | 
					
						
							|  |  |  | //	parameters: | 
					
						
							|  |  |  | //	- | 
					
						
							| 
									
										
										
										
											2022-10-13 16:37:55 +02:00
										 |  |  | //		name: id | 
					
						
							| 
									
										
										
										
											2022-10-12 15:01:42 +02:00
										 |  |  | //		type: string | 
					
						
							| 
									
										
										
										
											2022-10-13 16:37:55 +02:00
										 |  |  | //		description: The id of the emoji. | 
					
						
							|  |  |  | //		in: path | 
					
						
							|  |  |  | //		required: true | 
					
						
							| 
									
										
										
										
											2022-10-12 15:01:42 +02:00
										 |  |  | // | 
					
						
							|  |  |  | //	responses: | 
					
						
							|  |  |  | //		'200': | 
					
						
							| 
									
										
										
										
											2022-10-13 16:37:55 +02:00
										 |  |  | //			description: A single emoji. | 
					
						
							| 
									
										
										
										
											2022-10-12 15:01:42 +02:00
										 |  |  | //			schema: | 
					
						
							| 
									
										
										
										
											2022-10-13 16:37:55 +02:00
										 |  |  | //				"$ref": "#/definitions/adminEmoji" | 
					
						
							| 
									
										
										
										
											2022-10-12 15:01:42 +02:00
										 |  |  | //		'400': | 
					
						
							|  |  |  | //			description: bad request | 
					
						
							|  |  |  | //		'401': | 
					
						
							|  |  |  | //			description: unauthorized | 
					
						
							|  |  |  | //		'403': | 
					
						
							|  |  |  | //			description: forbidden | 
					
						
							|  |  |  | //		'404': | 
					
						
							|  |  |  | //			description: not found | 
					
						
							|  |  |  | //		'406': | 
					
						
							|  |  |  | //			description: not acceptable | 
					
						
							|  |  |  | //		'500': | 
					
						
							|  |  |  | //			description: internal server error | 
					
						
							| 
									
										
										
										
											2022-10-13 16:37:55 +02:00
										 |  |  | func (m *Module) EmojiGETHandler(c *gin.Context) { | 
					
						
							| 
									
										
										
										
											2022-10-12 15:01:42 +02:00
										 |  |  | 	authed, err := oauth.Authed(c, true, true, true, true) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		api.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet) | 
					
						
							|  |  |  | 		return | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if !*authed.User.Admin { | 
					
						
							|  |  |  | 		err := fmt.Errorf("user %s not an admin", authed.User.ID) | 
					
						
							|  |  |  | 		api.ErrorHandler(c, gtserror.NewErrorForbidden(err, err.Error()), m.processor.InstanceGet) | 
					
						
							|  |  |  | 		return | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if _, err := api.NegotiateAccept(c, api.JSONAcceptHeaders...); err != nil { | 
					
						
							|  |  |  | 		api.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) | 
					
						
							|  |  |  | 		return | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-13 16:37:55 +02:00
										 |  |  | 	emojiID := c.Param(IDKey) | 
					
						
							|  |  |  | 	if emojiID == "" { | 
					
						
							|  |  |  | 		err := errors.New("no emoji id specified") | 
					
						
							|  |  |  | 		api.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet) | 
					
						
							|  |  |  | 		return | 
					
						
							| 
									
										
										
										
											2022-10-12 15:01:42 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-13 16:37:55 +02:00
										 |  |  | 	emoji, errWithCode := m.processor.AdminEmojiGet(c.Request.Context(), authed, emojiID) | 
					
						
							| 
									
										
										
										
											2022-10-12 15:01:42 +02:00
										 |  |  | 	if errWithCode != nil { | 
					
						
							|  |  |  | 		api.ErrorHandler(c, errWithCode, m.processor.InstanceGet) | 
					
						
							|  |  |  | 		return | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-13 16:37:55 +02:00
										 |  |  | 	c.JSON(http.StatusOK, emoji) | 
					
						
							| 
									
										
										
										
											2022-10-12 15:01:42 +02:00
										 |  |  | } |