admin: Can delete a repository directory if needed
This commit is contained in:
parent
7692f92aa4
commit
c1924c0e92
@ -41,5 +41,27 @@ func declareRepositoriesRoutes(router *gin.RouterGroup) {
|
||||
}
|
||||
c.JSON(http.StatusOK, mod)
|
||||
})
|
||||
|
||||
router.DELETE("/repositories/*repopath", func(c *gin.Context) {
|
||||
di, ok := sync.GlobalImporter.(sync.DeletableImporter)
|
||||
if !ok {
|
||||
c.AbortWithStatusJSON(http.StatusNotImplemented, gin.H{"errmsg": "Not implemented"})
|
||||
return
|
||||
}
|
||||
|
||||
if strings.Contains(c.Param("repopath"), "..") {
|
||||
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": "Repopath contains invalid characters"})
|
||||
return
|
||||
}
|
||||
|
||||
repopath := strings.TrimPrefix(c.Param("repopath"), "/")
|
||||
|
||||
err := di.DeleteDir(repopath)
|
||||
if err != nil {
|
||||
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, true)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -755,6 +755,12 @@ angular.module("FICApp")
|
||||
$http.get("api/repositories").then(function (response) {
|
||||
$scope.repositories = response.data.repositories;
|
||||
});
|
||||
|
||||
$scope.deleteRepository = function(repo) {
|
||||
$http.delete("api/repositories/" + repo.path).then(function (response) {
|
||||
$scope.repositories[$scope.repositories.indexOf(repo)].hash = "- DELETED -";
|
||||
});
|
||||
};
|
||||
})
|
||||
.component('repositoryUptodate', {
|
||||
bindings: {
|
||||
|
@ -9,16 +9,20 @@
|
||||
<tr>
|
||||
<th>Chemin</th>
|
||||
<th>Branche</th>
|
||||
<th>Commit</th>
|
||||
<th>Plus récent</th>
|
||||
<th>Commit <span class="text-muted">Plus récent</span></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr ng-repeat="repository in repositories">
|
||||
<td>{{ repository.path }}</td>
|
||||
<td>{{ repository.branch }}</td>
|
||||
<td>{{ repository.hash }}</td>
|
||||
<td><repository-uptodate repository="repository" /></td>
|
||||
<td>
|
||||
{{ repository.hash }}<br>
|
||||
<repository-uptodate repository="repository" />
|
||||
</td>
|
||||
<td>
|
||||
<button type="button" ng-click="deleteRepository(repository)" class="btn btn-sm btn-danger"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
@ -57,6 +57,10 @@ func (i GitImporter) Kind() string {
|
||||
return "git originated from " + i.Remote + " on " + i.li.Kind()
|
||||
}
|
||||
|
||||
func (i GitImporter) DeleteDir(filename string) error {
|
||||
return i.li.DeleteDir(filename)
|
||||
}
|
||||
|
||||
func getForgeBaseLink(remote string) (u *url.URL, err error) {
|
||||
res := gitRemoteRe.FindStringSubmatch(remote)
|
||||
u, err = url.Parse(res[2])
|
||||
|
@ -113,3 +113,11 @@ func (i LocalImporter) ListDir(filename string) ([]string, error) {
|
||||
func (i LocalImporter) Stat(filename string) (os.FileInfo, error) {
|
||||
return os.Stat(path.Join(i.Base, filename))
|
||||
}
|
||||
|
||||
type DeletableImporter interface {
|
||||
DeleteDir(filename string) error
|
||||
}
|
||||
|
||||
func (i LocalImporter) DeleteDir(filename string) error {
|
||||
return os.RemoveAll(path.Join(i.Base, filename))
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user